{% extends 'base.html' %}

{% block content %}
<article>
    <header>
    <h1>Topics</h1>
    <p>
        <a href="{% url 'core:topic-create' %}" class="action-button">+ New topic</a>
    </p>
    </header>
    <section>
        <table>
            <thead>
                <tr>
                    <th>Topics</th>
                    <th>Posts</th>
                    <th>Last post</th>
                </tr>
            </thead>
            <tbody>
            {% for topic in topic_list %}
            <tr class="has-link" onclick="document.location='{% url 'core:topic-detail' topic.pk %}'">
                <td>
                    <h4>{{ topic.name }}</a></h4>
                    {{ topic.description }} » {{ topic.created_at }}
                </td>
                <td>{{ topic.post__count }}</td>
                {% with post=topic.post_set.last %} 
                <td>
                    {{ post.title  }}<br>
                    by <a href="{% url 'account-detail' post.author.pk %}">{{ post.author }}</a> » <time>{{ post.created_at }}</time>
                </td>
                {% endwith %}
            </tr>
            {% empty %}
            <tr>
                <li colspan="3">No topics yet</li>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </section>
</article>
{% endblock %}
