{% import "widgets/user.html" as widget_user %}
{% import "widgets/attachments.html" as widget_attachments %}

{% macro thread(comments, top_comment) %}
<table class="thread {{ 'topcomment' if top_comment == None else ''}} ">
{% for c in comments %}
    <tr id="{{ c.id }}">
    {% if c != top_comment %}
        <td class="author">{{ widget_user.profile(c.author) }}</td>
        <td>
            <div class="info">
                <div>Posté le {{ c.date_created|date }}</div>
                {% if c.date_created != c.date_modified %}
                    <div>Modifié le {{ c.date_modified|date }}</div>
                {% endif %}
                <div><a href="{{ request.path }}#{{ c.id }}">Permalink</a></div>
                <div><a href="{{ url_for('edit_post', postid=c.id, r=request.path) }}">Modifier</a></div>
                <div><a href="{{ url_for('delete_post', postid=c.id, csrf_token=csrf_token()) }}" onclick="return confirm('Le message sera supprimé')">Supprimer</a></div>
            </div>

            {{ c.text|md }}

            {{ widget_attachments.attachments(c) }}

            {% if c.author.signature %}
              <hr class="signature">
              {{ c.author.signature|md }}
            {% endif %}
        </td>
    {% elif loop.index0 != 0 %}
        <div>Ce message est le top comment</div>
    {% endif %}
    </tr>
{% endfor %}
</table>
{% endmacro %}
