{% extends "base/base.html" %}
{% import "widgets/editor.html" as widget_editor %}
{% import "widgets/thread.html" as widget_thread with context %}
{% import "widgets/user.html" as widget_user %}
{% import "widgets/pagination.html" as widget_pagination with context %}
{% import "widgets/attachments.html" as widget_attachments %}

{% 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>

    {% if t.thread.top_comment %}
        {% call widget_thread.thread_leader(t.thread.top_comment) %}
            <div class="info">
                <div>Posté le {{ t.date_created | dyndate }}</div>
                {{ widget_thread.post_actions(t) }}
            </div>
            {{ t.thread.top_comment.text | md }}
            {{ widget_attachments.attachments(t.thread.top_comment) }}
        {% endcall %}
    {% endif %}

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

    {{ widget_thread.thread(comments.items, t.thread.top_comment) }}

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

    {% if outdated %}
    <div class="bg-warn">
        Ce topic est sans activité depuis {{ outdated }} jours, êtes-vous sûr de vouloir y poster ?
    </div>
    {% endif %}

    {% if V5Config.ENABLE_GUEST_POST
        or (current_user.is_authenticated and current_user.can_post_in_forum(t.forum)) %}
    <div class=form>
        <h3>Commenter le sujet</h3>
        <form action="" method="post" enctype="multipart/form-data">
            {{ form.hidden_tag() }}

            {% if form.pseudo %}
            <div>
                {{ form.pseudo.label }}
                {{ form.pseudo }}
                {% for error in form.pseudo.errors %}
                <span class="msgerror">{{ error }}</span>
                {% endfor %}
            {{ form.ab }}
            </div>
            {% endif %}

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

            <div>
                {{ form.attachments.label }}
                <div>
                    {{ form.attachments }}
                    {% for error in form.attachments.errors %}
                    <span class="msgerror">{{ error }}</span>
                    {% endfor %}
                </div>
            </div>

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