{% extends 'base.html' %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <menu>
        <li><strong><a href="{% url 'core:topic-list' %}">Topics</a></strong></li>
    </menu>
</div>
{% endblock breadcrumbs %}

{% block content %}
<article>
    <header>
        <h1>{{ topic.name }}</h1>
        <h4>{{ topic.description }}</h4>
        <p>Created: <time>{{ topic.created_at }}</time></p>
        <p>
            <a href="{% url 'core:post-create' topic.pk %}" class="action-button">+ New post</a>
        </p>
    </header>
<section>
    <table>
        <thead>
            <tr>
                <th>Post</th>
                <th>Comments</th>
                <th>Last comment</th>
            </tr>
        </thead>
        {% for post in topic.post_set.all %}
            <tr class="has-link" onclick="document.location='{% url 'core:post-detail' topic.pk post.pk %}'">
                <td>
                    <h4>{{ post.title }}</h4>
                    by <a href="{% url 'account-detail' post.author.pk %}">{{ post.author }}</a> » <time>{{ post.created_at }}</time>
                </td>                
                <td>{{ post.comments__count }}</td>
                {% if post.comments.last is not None %}
                    {% with comment=post.comments.last %}
                    <td>
                        by <a href="{% url 'account-detail' comment.author.pk %}">{{ comment.author }}</a> » <time>{{ comment.created_at }}</time>
                    </td>
                    {% endwith %}
                {% else %}
                    <td>No comments</td>
                {% endif %}
            </tr>
        {% empty %}
            <p>No posts</p>
        {% endfor %}
        <tbody>
            
        </tbody>
    </table>
</section>
</article>
{% endblock %}
