{% extends "base/base.html" %}
{% import "widgets/editor.html" as widget_editor %}
{% import "widgets/member.html" as widget_member %}
{% import "widgets/pagination.html" as widget_pagination with context %}

{% block title %}
<a href='/forum'>Forum de Planète Casio</a> » <a href="{{ url_for('forum_page', f=t.forum) }}">{{ t.forum.name }}</a> » <h1>{{ t.title }}</h1>
{% endblock %}

{% block content %}
<section>
    <h1>{{ t.title }}</h1>
    <table class="thread"><tr>
		<td class="member">{{ widget_member.profile(t.author ) }}</td>
		<td>{{ t.thread.top_comment.text }}</td>
	</tr></table>

    {{ widget_pagination.paginate(comments, 'forum_topic', {'f': t.forum, 't':t}) }}

	<table class="thread">
    {% for c in comments.items %}
    	<tr>
        {% if c != t.thread.top_comment %}
        	<td class="member">{{ widget_member.profile(c.author ) }}</td>
            <td>
                {% if c.date_created != c.date_modified %}
                    Le {{ c.date_created|date }} (Modifié le {{ c.date_modified|date }})
                {% elif c.date_created == c.date_modified %}
                    Le {{ c.date_created|date }}
                {% endif %}
                <hr>
                <p>{{ c.text }}</p>
        {% elif loop.index0 != 0 %}
            <div>Ce message est le top comment</div>
        {% endif %}
        </td>
        </tr>
    {% endfor %}
	</table>

    {{ widget_pagination.paginate(comments, 'forum_topic', {'f': t.forum, 't':t}) }}
    
    <div class=form>
		<h3>Commenter le sujet</h3>
		<form action="" method="post" enctype="multipart/form-data">
			{{ form.hidden_tag() }}

			{{ widget_editor.text_editor(form.message, label=False) }}

			<div>{{ form.submit(class_='bg-green') }}</div>
		</form>
	</div>
</section>
{% endblock %}
