{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "kbforums/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor %}
{# L10n: {t} is the title of the thread. {d} is the name of the document. #}
{% set title = _('{t} | {d} Discussion | Knowledge Base')|f(t=thread.title, d=document.title) %}
{% set crumbs = [(url('wiki.category', document.category), document.get_category_display()),
                 (document.get_absolute_url(), document.title),
                 (url('wiki.discuss.threads', document.slug), _('Discuss')),
                 (None, thread.title)] %}

{% block content %}
<article id="posts" class="main">
  <h1>{{ thread.title }}</h1>
  <div class="badges">
    {% if thread.is_sticky %}<span class="sticky">{{ _('Sticky') }}</span>{% endif %}
    {% if thread.is_locked %}<span class="locked">{{ _('Locked') }}</span>{% endif %}
    {% if is_watching_thread %}<span class="watching">{{ _('Watching') }}</span>{% endif %}
  </div>
  <div class="thread-actions">
    {% if user.is_authenticated() %}
      <form action="{{ url('wiki.discuss.watch_thread', document.slug, thread.id) }}" method="post">
        {{ csrf() }}
        {% if is_watching_thread %}
          {% set watch = _('Stop watching') %}
          <input type="hidden" name="watch" value="no" />
        {% else %}
          {% set watch = _('Watch this thread') %}
          <input type="hidden" name="watch" value="yes" />
        {% endif %}
        <input type="image" alt="{{ watch }}" title="{{ watch }}" src="{{ MEDIA_URL }}img/forums/watch.png"/>
      </form>
    {% endif %}
    {% if perms.kbforums.edit_thread or (thread.creator == request.user and not thread.is_locked) %}
      <a href="{{ url('wiki.discuss.edit_thread', document.slug, thread.id) }}"><img src="{{ MEDIA_URL }}img/forums/edit.png" alt="{{ _('Edit') }}" title="{{ _('Edit') }}"/></a>
    {% endif %}
    {% if perms.kbforums.delete_thread %}
      <a href="{{ url('wiki.discuss.delete_thread', document.slug, thread.id) }}">
        <img src="{{ MEDIA_URL }}img/forums/delete.png" alt="{{ _('Delete') }}" title="{{ _('Delete') }}">
      </a>
    {% endif %}
    {% if perms.kbforums.lock_thread %}
      <form action="{{ url('wiki.discuss.lock_thread', document.slug, thread.id) }}" method="post">
        {{ csrf() }}
        <input type="image" src="{{ MEDIA_URL }}img/forums/type/locked.png" alt="{{ _('Change locked status') }}" title="{{ _('Change locked status') }}"/>
      </form>
    {% endif %}
    {% if perms.kbforums.sticky_thread %}
      <form action="{{ url('wiki.discuss.sticky_thread', document.slug, thread.id) }}" method="post">
        {{ csrf() }}
        <input type="image" src="{{ MEDIA_URL }}img/forums/type/sticky.png" alt="{{ _('Change sticky status') }}" title="{{ _('Change sticky status') }}" />
      </form>
    {% endif %}
  </div>

  <div class="thread-watch">
    {% if user.is_authenticated() %}
    {% endif %}
  </div>

  <ol class="posts-columns">
    <li class="author">{{ _('Author') }}</li>
    <li class="message">{{ _('Message') }}</li>
  </ol>

  {% if posts %}
    <ol class="posts">
      {% for post in posts.object_list %}
        <li id="post-{{ post.id }}">
          {% include "kbforums/includes/post.html" %}
        </li>
      {% endfor %}
    </ol>

    {{ posts|paginator }}

  {% else %}
    <p>{{ _('Oh, no! Looks like there are no posts!') }}</p>
  {% endif %}

  {% if user.is_authenticated() and not thread.is_locked %}
    <div id="thread-reply">
      <h3>{{ _('Post a reply') }}</h3>

      <form action="{{ url('wiki.discuss.reply', document.slug, thread.id)|urlparams(hash='thread-reply') }}" method="post">
        {{ csrf() }}
        {{ errorlist(form) }}

        {{ content_editor(form.content) }}

        <div class="editor-actions">
          <input type="submit" name="preview" value="{{ _('Preview') }}" />
          <input type="submit" value="{{ _('Reply') }}" />
        </div>
      </form>
    </div>
  {% elif user.is_authenticated() and thread.is_locked %}
    <div id="thread-reply">
      <h3>{{ _('Post a reply') }}</h3>

      <p id="thread-locked">{{ _('This thread has been locked. It is no longer possible to post new replies.') }}</p>
    </div>
  {% endif %}
  {% if reply_preview %}
    <div id="post-preview">
      <h3>{{ _('Reply Preview:') }}</h3>
      <ol class="posts">
        <li>
          {% set post = reply_preview %}
          {% include "kbforums/includes/post.html" %}
        </li>
      </ol>
    </div>
  {% endif %}
</article>
{% endblock %}
