{% set page_title = forum[0].title %}
{% set active_forum_nav=True %}

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

<ol class="breadcrumb">
    <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
    <li><a href="{{ forum[0].category.url }}">{{ forum[0].category.title }}</a></li>
    <li class="active">{{ forum[0].title }}</li>
</ol>

<div class="pull-left" style="padding-bottom: 10px">
    {{ render_pagination(topics, forum[0].url) }}
</div> <!-- end span pagination -->

{% if current_user|post_topic(forum[0]) %}
<div class="pull-right" style="padding-bottom: 10px">
    <div class="btn-group">
        <a href="{{ url_for('forum.markread', forum_id=forum[0].id, slug=forum[0].slug) }}" class="btn btn-default">
            <span class="fa fa-check"></span> Mark as Read
        </a>

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

    </div>
</div>
{% endif %}

<table class="table table-bordered">
    <thead>
        <tr>
            <th colspan="5">
                {{ forum[0].title }}
            </th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <td colspan="2">Topic</td>

            <td>Posts</td>

            <td>Views</td>

            <td>Last Post</td>
        </tr>

        {% for topic, topicread in topics.items %}
        <tr>
            <td width="4%">
            {% if topic.locked %}
                <span class="fa fa-locked" style="font-size: 2em"></span>
            {% else %}
                {% if topic|topic_is_unread(topicread, current_user, forum[1]) %}
                    <span class="fa fa-comment" style="font-size: 2em"></span>
                {% else %}
                    <span class="fa fa-comment-o" style="font-size: 2em"></span>
                {% endif %}
            {% endif %}

            </td>
            <td>
                <div>
                    <a href="{{ topic.url }}">{{ topic.title }}</a>
                    <!-- Topic Pagination -->
                    {{ topic_pages(topic, config["POSTS_PER_PAGE"]) }}
                    <br />
                    {% if topic.user_id %}
                    <small>by <a href="{{ topic.user.url }}">{{ topic.user.username }}</a></small>
                    {% else %}
                    <small>by {{ topic.username }}</small>
                    {% endif %}
                </div>
            </td>
            <td>
                {{ topic.post_count }}
            </td>
            <td>
                {{ topic.views }}
            </td>
            <td>
                <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />

                {% if topic.last_post.user_id %}
                <small>by <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a></small>
                {% else %}
                <small>{{ topic.last_post.username }}</small>
                {% endif %}
            </td>
        </tr>
        {% else %}
        <tr>
            <td colspan="5">
                No Topics so far.
            </td>
        </tr>
        {% endfor %}

    </tbody>
</table>

{% endblock %}
