{% extends 'forum/base.html' %}

{% block title %}
{% endblock title %}


{% block content %}

    <div class="container">
        <div class="page-header page-heading">
            <h1 class="pull-left">Forums</h1>

            <ol class="pull-right where-am-i">
                {% if user.is_authenticated %}
                    <a href="{% url 'forum:new_topic' %}">
                        <button class="btn btn-success">New Topic</button>
                    </a>
                {% else %}
                    <p><a href="{% url 'account_login' %}">Login</a> or <a
                            href="{% url 'account_signup' %}">Register</a> to join the discussion!</p>
                {% endif %}

            </ol>


            <div class="clearfix"></div>
        </div>
        <p class="lead">Welcome to Kihoutei Beta Forums, please see the <a href="#">rules</a> before posting.</p>
        <table class="table forum table-striped">
            <thead>
            <tr>
                <th class="cell-stat"></th>
                <th>
                    <h3>Topics</h3>
                </th>
                <th class="cell-stat text-center hidden-xs hidden-sm">Creator</th>
                <th class="cell-stat text-center hidden-xs hidden-sm">Posts</th>
                <th class="cell-stat text-center hidden-xs hidden-sm">Replies</th>
                <th class="cell-stat-2x hidden-xs hidden-sm">Last Post</th>
            </tr>
            </thead>
            <tbody>
            {% for topic in topics %}
                <tr>
                    <td class="text-center"><i class="fa fa-2x fa-folder-open-o text-primary"></i></td>
                    <td>
                        <h4><a href="{% url 'forum:topic_posts' topic.slug %}">{{ topic.title }}</a><br>
                            <small>{{ topic.description }}</small>
                        </h4>
                    </td>

                    <td class="text-center hidden-xs hidden-sm">
                        {% if topic.post_set.count != 0 %}
                            {% if user.is_authenticated %} {# todo: abstract #}
                                {% if topic.last_post.creator == request.user %}
                                    You
                                {% else %}
                                    {{ topic.last_post.creator }}
                                {% endif %}
                            {% else %}
                                {{ topic.last_post.creator }}s
                            {% endif %}
                        {% else %}
                            No posts yet!
                        {% endif %}
                    </td>

                    <td class="text-center hidden-xs hidden-sm">{{ topic.post_set.count }}</td>
                    <td class="text-center hidden-xs hidden-sm">{{ topic.reply_set.count }}</td>

                    <td class="hidden-xs hidden-sm">
                        {% if topic.last_post %}
                            <a href="{% url 'forum:post' topic.slug topic.last_post.slug %}">
                                {{ topic.post_set.last.title }}</a> by
                            {% if user.is_authenticated %}
                                {% if topic.last_post.creator == request.user %}
                                    You
                                {% else %}
                                    <a href="{% url 'user_profile' topic.last_post.creator %}">{{ topic.last_post.creator }}</a>
                                {% endif %}
                            {% else %}
                                {{ topic.last_post.creator }}
                            {% endif %}
                            <small><i class="fa fa-clock-o"></i> {{ topic.last_post.created|timesince }} ago</small>
                        {% else %}
                            No posts yet!
                        {% endif %}
                    </td>

                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    </div>

{% endblock content %}

