{% extends "community/_base.html" %}

{%- from "macros/user.html" import m_user_link, m_user_photo %}
{%- from "macros/box.html" import m_box_content, m_box_menu -%}
{%- from "forum/_macros.html" import m_postattachments -%}


{%- block content %}
  {#  TODO #}
  <p>
    <a href="{{ url_for('.index', community_id=g.community.slug) }}">
      <i class="fa fa-arrow-left"></i> {{ _("Back to conversation list") }}</a>
  </p>

  <div class="thread-header">
    <div class="author">
      {% call m_user_link(thread.creator, css="pull-left") %}
        {{ m_user_photo(thread.creator, size=55) }}
      {% endcall %}
      <div>{{ m_user_link(thread.creator) }}</div>
      <div>{{ thread.created_at | age(date_threshold='day') }}</div>
    </div>
    <h2>{{ thread.title }}</h2>
  </div>

  {%- if thread.posts|length > 1 %}
    <div class="comments">
      {%- for post in thread.posts %}
        {{ m_postattachments(post) }}
      {%- endfor %}
    </div>
  {%- endif %}

{%- endblock %}

{%- block sidebar %}
  {%- call m_box_menu() %}
    <ul class="nav nav-list">
      {%- set content_actions = actions.for_category('forum:thread') %}
      {%- set global_actions = actions.for_category('forum:global') %}

      {%- for action in content_actions %}
        <li>{{ action.render() }}</li>
      {%- endfor %}

      {%- if content_actions and global_actions %}
        <li class="divider"></li>
      {%- endif %}

      {%- for action in global_actions %}
        <li>{{ action.render() }}</li>
      {%- endfor %}
    </ul>
  {%- endcall %}
{%- endblock %}


{%- block modals %}
  <div class="modal fade" id="modal-delete" role="dialog"
       data-keyboard="true">

    <div class="modal-dialog">
      <div class="modal-content">
        <form
            action="{{ url_for('.thread_delete', thread_id=thread.id, community_id=g.community.slug) }}"
            method="POST" style="margin-bottom: 0;">

          {{ csrf.field() }}

          <div class="modal-header">
            <button class="close" data-dismiss="modal">&times;</button>
            <h3>{{ _("Delete Thread") }}</h3>
          </div>

          <div class="modal-body">
            {{ _('Are you sure you want to delete this thread?') }}
          </div>

          <div class="modal-footer">
            <button data-dismiss="modal" class="btn">{{ _("Cancel") }}</button>
            <button type="submit"
                    class="btn btn-danger">{{ _("Really Delete") }}</button>
          </div>
        </form>
      </div>
    </div>
  </div>
{%- endblock %}
