{% set page_title = forum.title %}
{% set active_forum_nav=True %}

{% extends theme("layout.html") %}
{% block content %}
{% from theme('macros.html') import render_pagination, topic_pages %}

<div class="forum-view">
    <ol class="breadcrumb flaskbb-breadcrumb">
        <li><a href="{{ url_for('forum.index') }}">{% trans %}Forum{% endtrans %}</a></li>
        <li><a href="{{ forum.category.url }}">{{ forum.category.title }}</a></li>
        <li class="active">{{ forum.title }}</li>
    </ol>

    <div class="row controls-row">
        <div class="pull-left">
            {{ render_pagination(topics, forum.url) }}
        </div> <!-- end span pagination -->

        {% if current_user|post_topic(forum) %}
        <div class="pull-right">
            <form class="inline-form" method="post" action="{{ url_for('forum.markread', forum_id=forum.id, slug=forum.slug) }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                <button class="btn btn-default">
                    <span class="fa fa-check fa-fw"></span> {% trans %}Mark as Read{% endtrans %}
                </button>
            </form>

            {% if forum.locked %}
            <span class="btn btn-primary">
                <span class="fa fa-lock fa-fw"></span> {% trans %}Locked{% endtrans %}
            </span>
            {% else %}
            <a href="{{ url_for('forum.new_topic', forum_id=forum.id, slug=forum.slug) }}" class="btn btn-primary">
                <span class="fa fa-pencil fa-fw"></span> {% trans %}New Topic{% endtrans %}
            </a>
            {% endif %}
        </div>
        {% endif %}
    </div>

    <div class="panel forum-panel">
        <div class="panel-heading forum-head">
            <a href="{{ forum.url }}">{{ forum.title }}</a>
        </div>

        <div class="panel-body forum-body">
            <div class="forum-meta">
                <div class="col-md-5 col-sm-5 col-xs-8 topic-name">{% trans %}Topic{% endtrans %}</div>
                <div class="col-md-2 col-sm-2 hidden-xs topic-stats">{% trans %}Posts{% endtrans %}</div>
                <div class="col-md-2 col-sm-2 hidden-xs topic-stats">{% trans %}Views{% endtrans %}</div>
                <div class="col-md-3 col-sm-3 col-xs-4 topic-last-post">{% trans %}Last Post{% endtrans %}</div>
            </div>

            {% for topic, topicread in topics.items %}
            <div class="row forum-row hover clearfix">

                <div class="col-md-5 col-sm-5 col-xs-8 topic-info">
                    <div class="row">
                        <div class="col-md-1 col-sm-2 col-xs-2 topic-status">
                        {% if topic.locked %}
                            <span class="fa fa-lock fa-fw topic-locked"></span>
                        {% elif topic.hidden %}
                            <span class="fa fa-user-secret"></span>
                        {% elif topic.important %}
                            {% if topic|topic_is_unread(topicread, current_user, forumsread) %}
                                <span class="fa fa-star fa-fw topic-starred-unread"></span>
                            {% else %}
                                <span class="fa fa-star-o fa-fw topic-starred-read"></span>
                            {% endif %}
                        {% else %}
                            {% if topic|topic_is_unread(topicread, current_user, forumsread) %}
                                <span class="fa fa-comment fa-fw topic-unread"></span>
                            {% else %}
                                <span class="fa fa-comment-o fa-fw topic-read"></span>
                            {% endif %}
                        {% endif %}
                        </div>
                        <div class="col-md-11 col-sm-10 col-xs-10">
                            <div class="topic-name">
                                <a href="{{ topic.first_unread(topicread, current_user, forumsread) }}">{{ topic.title }}</a>
                                <!-- Topic Pagination -->
                                <span class="topic-pages">{{ topic_pages(topic, flaskbb_config["POSTS_PER_PAGE"]) }}</span>
                            </div>

                            <div class="topic-author">
                                {% trans %}by{% endtrans %}
                                {% if topic.user_id %}
                                 <a href="{{ topic.user.url }}">{{ topic.user.username }}</a>
                                {% else %}
                                {{ topic.username }}
                                {% endif %}
                            </div>

                            {% if topic.hidden %}
                            <div class="topic-author">
                                {{ gettext("Hidden on %(when)s  by %(who)s", who=topic.hidden_by.username, when=format_date(topic.hidden_at, '%b %d %Y'))}}
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
                <div class="col-md-2 col-sm-2 hidden-xs topic-stats">
                    {{ topic.post_count }}
                </div>

                <div class="col-md-2 col-sm-2 hidden-xs topic-stats">
                    {{ topic.views }}
                </div>

                <div class="col-md-3 col-sm-3 col-xs-4 topic-last-post">
                    <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />

                    <div class="topic-author">
                        {% trans %}by{% endtrans %}
                        {% if topic.last_post.user_id %}
                        <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a>
                        {% else %}
                        {{ topic.last_post.username }}
                        {% endif %}
                    </div>
                </div>

            </div>  <!-- end forum-row -->
            {% else %}
            <div class="row forum-row clearfix">
                <div class="col-md-12 col-sm-12 co-xs-12">
                    {% trans %}No Topics.{% endtrans %}
                </div>
            </div> <!-- end forum-row -->
            {% endfor %}
        </div>
    </div>

    {% if current_user|can_moderate(forum) %}
    <div class="row controls-row">
        <a class="btn btn-default" href="{{ url_for('forum.manage_forum', forum_id=forum.id, slug=forum.slug) }}">
            <span class="fa fa-tasks fa-fw"></span> {% trans %}Moderation Mode{% endtrans %}
        </a>
    </div>
    {% endif %}
</div>
{% endblock %}
