{% extends "base/base.html" %}
{% import "widgets/editor.html" as widget_editor %}

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

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

	{% if f.topics %}
		<h2>Sujets</h2>
		<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 f.topics %}
				<tr><td><a href='{{ url_for('forum_topic', f=t.forum, t=t) }}'>{{ 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>{{ t.thread.comments.count() }}</td>
					<td>{{ t.views }} </td></tr>
			{% endfor %}
		</table>
	{% 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 | length }}</td></tr>
			<tr><td>{{ sf.descr }}</td><td></td></tr>
		{% endfor %}

		</table>
	{% endif %}

	{% if (not f.sub_forums) == 0 or (current_user.is_authenticated and current_user.priv('access-admin-board')) %}
	<div class=form>
		<h2>Créer un nouveau sujet</h2>
		<form action="" method="post" enctype="multipart/form-data">
			{{ form.hidden_tag() }}

			<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.submit(class_='bg-green') }}</div>
		</form>
	</div>
	{% endif %}
</section>
{% endblock %}
