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

{% 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>Édition de sujet</h1>
{% endblock %}

{% block content %}
<section>
    <h1>Édition du sujet: {{ t.title }}</h1>

    <h3>Sujet actuel</h3>

    <p><i>Pour modifier substantiellement ou réécrire le commentaire d'en-tête, il vaut mieux poster un nouveau commentaire et le désigner comme en-tête ; ça permet à la conversation de rester dans son contexte.</i></p>

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

	<div class="form">
		<h3>Nouveau sujet</h3>
		<form action="" method="post" enctype="multipart/form-data">
			{{ form.hidden_tag() }}

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

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

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

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

			{% if form.attachment_list %}
				<div>Supprimer des pièces jointes<br>
					{% for id, a in form.attachment_list.items() %}
						{{ form[id]() }} <code>{{ a.name }}</code> ({{ a.size }} octets)<br>
					{% endfor %}
				</div>
			{% endif %}

			<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>
</section>
{% endblock %}
