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

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

            {{ c.text|md }}

            {{ widget_attachments.attachments(c) }}

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