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

{% block title %}
<a href='/forum'>Forum de Planète Casio</a> » <h1>{{ f.name }}</h1>
{% endblock %}

{% block content %}
<section>
	<p>{{ f.descr }}</p>

	{% if topics.items %}
		<h2>Sujets</h2>

		{{ widget_pagination.paginate(topics, 'forum_page', None, {'f': f}) }}

		<table class=topiclist>
			<tr><th>Sujet</th><th>Auteur</th><th>Date de création</th>
				<th>Commentaires</th><th>Vues</th></tr>

			{% for t in topics.items %}
				<tr><td><a href='{{ url_for('forum_topic', f=t.forum, page=(t,1)) }}'>{{ t.title }}</a></td>
					<td><a href='{{ url_for('user', username=t.author.name) }}'>{{ t.author.name }}</a></td>
					<td>{{ t.date_created | date }}</td>
					<td>{{ comment_counts[t.thread.id] }}</td>
					<td>{{ t.views }} </td></tr>
			{% endfor %}
		</table>

		{{ widget_pagination.paginate(topics, 'forum_page', None, {'f': f}) }}

	{% elif not f.sub_forums %}
		<p>Il n'y a aucun topic sur ce forum ! Animons-le vite !</p>
	{% endif %}

	{% if f.sub_forums %}
		<h2>Forums</h2>
		<table class=forumlist>
		<tr><th>{{ f.name }}</th><th>Nombre de sujets</th></tr>

		{% for sf in f.sub_forums %}
			<tr><td><a href='/forum{{ sf.url }}'>{{ sf.name }}</td>
					<td>{{ sf.topics.count() }}</td></tr>
			<tr><td>{{ sf.descr }}</td><td></td></tr>
		{% endfor %}

		</table>
	{% endif %}

	{% if (V5Config.ENABLE_GUEST_POST and f.is_default_postable())
		or (current_user.is_authenticated and current_user.can_post_in_forum(f)) %}
	<div class=form>
		<h2>Créer un nouveau sujet</h2>
		<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 %}
			</div>
			{{ form.ab }}
			{% endif %}

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

			{{ widget_editor.text_editor(form.message) }}

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