{% extends "lbforum/base_site.html" %}

{% load i18n %}
{% load lbforum_filters %}
{% load lbforum_tags %}
{% load el_pagination_tags %}
{% load staticfiles %}
{% load lbutils %}

{% block title %}
  {{ topic.subject }} - {% get_setting "LBFORUM_TITLE" %}
{% endblock %}

{% block content_right_bar %}
  {% include 'lbforum/widgets/cur_user_profile.html' %}
{% endblock %}

{% block extra_header %}
  {{ block.super }}
  <link rel="stylesheet" type="text/css" media="screen" href="{% static 'lbforum/styles/pygments.css' %}"/>
{% endblock %}

{% block content_content %}
  {% paginate posts %}
  {% get_pages %}
  <div class="box">
    {% with post=topic.post %}
    <div class="cell" style="min-height: 73px;">
      <div class="fr snow" style="padding-left: 10px; padding-bottom: 10px;">
        <a href="{% url 'lbforum_profile' user_id=post.posted_by.pk %}">{# avatar post.posted_by #}</a>
      </div>
      <span class="bigger">
        <a href="{% url 'lbforum_index' %}">{% trans "Home" %}</a>
        <span class="chevron">&raquo;</span>
        <a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum.name }}</a>
      </span>
      <h1>{{topic}}</h1>
      <small class="fade">
        By
        <a href="{% url 'lbforum_profile' user_id=post.posted_by.pk %}">{{post.posted_by.username}}</a>
        at {{ topic.last_post.created_on|lbtimesince }},
        {{topic.num_views}} hits
        {% if can_admin %}
          <span>|</span>
          <span>
            <a href="{% url 'lbforum_toggle_topic_attr' topic_id=topic.id attr='distillate' %}">
              {% if topic.level >= 60 %} {% trans "undistillate" %} {% else %} {% trans "distillate" %} {% endif %}
            </a>
          </span>
          <span>
            <a href="{% url 'lbforum_toggle_topic_attr' topic_id=topic.id attr='sticky' %}">
              {% if topic.sticky %} {% trans "unsticky" %} {% else %} {% trans "sticky" %} {% endif %}
            </a>
          </span>
          <span>
            <a href="{% url 'lbforum_toggle_topic_attr' topic_id=topic.id attr='close' %}">
              {% if topic.closed %} {% trans "unclose" %} {% else %} {% trans "close" %} {% endif %}
            </a>
          </span>
          <span>
            <a href="{% url 'lbforum_toggle_topic_attr' topic_id=topic.id attr='hide' %}">
              {% if topic.hidden %} {% trans "unhide" %} {% else %} {% trans "hide" %} {% endif %}
            </a>
          </span>
          <span>
            <a href="{% url 'lbforum_delete_topic' topic_id=topic.id %}" onclick="return confirm('{% trans "Do you want to delete it?" %}')">{% trans "delete" %}</a>
          </span>
        {% endif %}
      </small>
    </div>
    <div class="inner">
      <div class="content topic_content">
        {% include 'lbforum/inc_post_content.html' %}
      </div>
    </div>
    <div class="inner" id="topic-post-footer">
      <div class="fr">
        {% if user == post.posted_by or can_admin %}
          <span>
            <a href="{% url 'lbforum_post_edit' post_id=post.pk %}">{% trans "edit" %}</a>
          </span>
          |
        {% endif %}
        <span>
          <a href="{% url 'lbforum_new_replay' topic_id=topic.pk %}?qid={{post.pk}}">{% trans "quote" %}</a>
        </span>
        {% if topic|topic_can_post:user %}
          <span>
            <a class="newpost" href="{% url 'lbforum_new_replay' topic_id=topic.pk %}">
              {% trans "Post reply" %}
            </a>
          </span>
        {% endif %}
      </div>
      &nbsp;
    </div>
    {% endwith %}
  </div>

  <div class="sep20"></div>

  {% if not posts %}
    <div align="center" class="glass"><div class="inner"><span class="white">{% trans "No Reply" %}</span></div></div>
  {% else %}
    <div class="box">
      <div class="cell">
        <div class="fr">
        </div>
        <span class="fade">
          {% trans "Posts" %} [ {% page_range_info pages %} ]
          <span class="snow">|</span>
          {% trans "Last post" %} {{ topic.last_post.created_on|lbtimesince }}
        </span>
      </div>
      <div id="replies">
        {% for post in posts %}
          {% include 'lbforum/inc_post_detail.html' %}
        {% endfor %}
      </div>
      <div class="inner">
        {% show_pages %}
      </div>
    </div>
  {% endif %}

  {% if  topic|topic_can_post:user %}
    <div class="sep20"></div>
    <div class="box" id="quick-reply-box">
      <form action="{% url 'lbforum_new_replay' topic_id=topic.pk %}" accept-charset="utf-8" method="post" class="frm-form">
        <div class="cell"><div class="fr fade"><a class="dark" href="#Top">Top&uarr;</a></div>
          <span class="fade">
            {% trans "Quick reply to this topic" %}
          </span>
        </div>
        <div class="cell">
          <textarea id="reply_content" name="message" class="mll"></textarea>
          <div class="sep10"></div>
          <div id="e" class="fr fade"></div>
          {% csrf_token %}
          <input type="submit" value="{% trans "Submit" %}" name="submit" class="super normal button">
          <input type="submit" value="{% trans "Preview" %}" name="preview" class="super normal button">
        </div>
      </form>

      <div class="inner">
        <span class="fade" style="font-size: 120%">
          <small>{% trans "You may use" %}: </small>
          <a class="node" target="_blank" title="Help with: BBCode" href="http://fluxbb.org/forums/help/bbcode/" class="exthelp">BBCode</a>
        </span>
      </div>
    </div>
  {% endif %}
{% endblock %}

{% block footer_js %}
  <script type="text/javascript" src="{% static 'jquery/dist/jquery.min.js' %}"></script>
  <script type="text/javascript" src="{% static 'mediaelement/build/mediaelement-and-player.min.js' %}"></script>
  <link rel="stylesheet" href="{% static 'mediaelement/build/mediaelementplayer.css' %}" />
  <script type="text/javascript">
    $('.entry-attachments-img-s a').click(function() {
      var p = $(this).parent();
      p.hide();
      p.next().show()
      return false;
    })
    $('.content a').attr({ target: "_blank" });
  </script>
{% endblock %}
