{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "forums/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor %}
{# L10n: {f} if the name of the forum. #}
{% set title = _('Create a new thread | {f} | Forums')|f(f=forum.name) %}
{% set crumbs = [(url('forums.forums'), _('Forums')),
                 (url('forums.threads', forum.slug), forum.name),
                 (None, _('Create a new thread'))] %}

{% block content %}
<article id="new-thread" class="main">
  <h1>{{ _('Create a new thread') }}</h1>

  <form action="{{ url('forums.new_thread', forum.slug) }}" method="post" class="new-thread">
    {{ csrf() }}
    {{ errorlist(form) }}

    {% for field in form %}
      <div class="form-widget{% if field.errors %} invalid{% endif %}">
        {{ field.label_tag()|safe }}
        {% if field.name == 'content' %}
          {{ content_editor(field) }}
        {% else %}
          {{ field|safe }}
        {% endif %}
      </div>
    {% endfor %}

    <div class="form-widget submit">
      <input type="submit" name="preview" value="{{ _('Preview') }}" />
      <input type="submit" value="{{ _('Post') }}" />
      <a href="{{ url('forums.threads', forum.slug) }}">{{ _('Cancel') }}</a>
    </div>

    {% if post_preview %}
      <div id="post-preview">
        <h3>{{ _('Post Preview:') }}</h3>
        <ol class="posts">
          <li>
            {% set post = post_preview %}
            {% include "forums/includes/post.html" %}
          </li>
        </ol>
      </div>
    {% endif %}
  </form>
</article>
{% endblock %}
