{% extends 'board_base.html' %}
{% load i18n static %}
{% load forum_conversation_tags %}
{% load forum_member_tags %}
{% load forum_permission_tags %}

{% block sub_title %}{{ topic.subject }}{% endblock sub_title %}

{% block content %}
<div class="mb-8 w-full"><h1 class="text-3xl">{{ topic.subject }}</h1></div>
<div class="w-full">
  <div class="inline-flex items-center mb-6 space-x-3">
  {% include "forum_conversation/partials/topic_detail_actions.html" %}
  </div>
  <div class="pagination-block">
  {% with "pagination-sm justify-content-end" as pagination_size %}
  {% include "partials/pagination.html" %}
  {% endwith %}
  </div>
</div>
<div class="w-full">
  <div class="w-full">
  {% for post in posts %}
    {% if forloop.first and post.is_topic_head and poll %}
    {% include "forum_conversation/forum_polls/poll_detail.html" %}
    {% endif %}
    <div id="{{ post.id }}" class="my-3 card post">
      <div class="card-body">
        <div class="flex p-6 space-x-8 rounded border bg-charcoal border-1 border-slate">
          <div class="w-5/6 post-content-wrapper">
            <div class="float-right post-controls">
              {% get_permission 'can_edit_post' post request.user as user_can_edit_post %}
              {% if user_can_edit_post %}
              <a href="{% if post.is_topic_head %}{% url 'forum_conversation:topic_update' forum.slug forum.pk topic.slug topic.pk %}{% else %}{% url 'forum_conversation:post_update' forum.slug forum.pk topic.slug topic.pk post.pk %}{% endif %}"
                 class="py-2 px-4 text-sm uppercase rounded rounded-lg border border-1 border-orange text-orange"
                 title="{% trans "Edit" %}"
              >
                <img src="{% static 'img/icons/icon_button-edit.svg' %}" class="inline-block mr-4" />
                {% trans "Edit" %}
              </a>
              {% endif %}
              {% get_permission 'can_delete_post' post request.user as user_can_delete_post %}
              {% if user_can_delete_post %}
              <a href="{% url 'forum_conversation:post_delete' forum.slug forum.pk topic.slug topic.pk post.pk %}"
                 class="py-2 px-4 ml-3 text-sm uppercase rounded rounded-lg border border-1 border-orange text-orange"
                 title="{% trans "Delete" %}">
                <i class="fas fa-times text-orange"></i>
              </a>
              {% endif %}
            </div>
              {% spaceless %}
              <h4 class="items-center m-0 mb-3 text-2xl subject">
                {{ post.subject }}
                &nbsp;<a href="{% url 'forum_conversation:topic' forum.slug forum.pk topic.slug topic.pk %}?post={{ post.pk }}#{{ post.pk }}"><i class="text-sm fas fa-link text-white/60"></i></a>
              </h4>
              {% endspaceless %}
              <p class="p-0">
                <small class="text-muted">
                {% spaceless %}
                <img src="{% static 'img/icons/icon_clock.svg' %}" class="inline-block mr-4" />
                {% if post.poster %}
                {% url 'forum_member:profile' post.poster_id as poster_url %}
                {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
                  <span class="text-sm">By: <a href="{{ poster_url }}" class="text-orange">{{ username }}</a> on {{ creation_date }}</span>
                {% endblocktrans %}
                {% else %}
                {% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
                  <span class="text-sm">By: {{ poster_username }} on {{ creation_date }}</span>
                {% endblocktrans %}
                {% endif %}
                {% endspaceless %}
                </small>
              </p>
              <div class="post-content">
                {{ post.content.rendered }}
              </div>
              {% include "forum_conversation/forum_attachments/attachments_detail.html" %}
              {% if post.enable_signature and post.poster.forum_profile.signature %}
              <div class="post-signature">
                {{ post.poster.forum_profile.signature.rendered }}
              </div>
              {% endif %}
              {% if post.updates_count %}
              <div class="mt-4 edit-info">
                <small class="text-muted">
                  <i class="fas fa-edit"></i>&nbsp;{% if post.updated_by %}{% trans "Last edited by:" %}&nbsp;<a href="{% url 'forum_member:profile' post.updated_by_id %}">{{ post.updated_by|forum_member_display_name }}</a>&nbsp;{% else %}{% trans "Updated" %}&nbsp;{% endif %}{% trans "on" %}&nbsp;{{ post.updated }}, {% blocktrans count counter=post.updates_count %}edited {{counter }} time in total.{% plural %}edited {{counter }} times in total.{% endblocktrans %}
                </small>
                {% if post.update_reason %}
                <br />
                <small class="text-muted">
                  <b>{% trans "Reason:" %}</b>&nbsp;{{ post.update_reason }}
                </small>
                {% endif %}
              </div>
              {% endif %}
          </div>
          <div class="w-1/6 text-sm d-none d-md-block post-sidebar">
            {% if post.poster %}
            <div class="avatar">
              <a href="{% url 'forum_member:profile' post.poster_id %}">
                {% include "partials/avatar.html" with profile=post.poster.forum_profile show_placeholder=True %}
              </a>
            </div>
            <div class="username"><a class="text-orange" href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
            <div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
            {% else %}
            <div class="username"><b>{{ post.username }}</b></div>
            <div class="username text-muted">{% trans "Anonymous user" %}</div>
            {% endif %}
          </div>
        </div>
      </div>
    </div>
  {% endfor %}
  </div>
</div>
<div class="mt-11 w-full">
  <div class="inline-flex items-center space-x-3 w-1/2">
    {% include "forum_conversation/partials/topic_detail_actions.html" %}
  </div>
  <div class="w-full">
    {% with "pagination-sm justify-content-end" as pagination_size %}
    {% include "partials/pagination.html" %}
    {% endwith %}
  </div>
</div>
{% endblock content %}
