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

{% load django_bootstrap_breadcrumbs %}

{% block breadcrumbs %}
    {{ block.super }}
    {% breadcrumb topic "forum:topic_posts" topic.slug %}

{% endblock breadcrumbs %}

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


{% block content %}
    {% render_breadcrumbs %}
    <div class="container">
        <div class="row">
            Created by <a
                    href="{% url 'user_profile' topic.creator %}">{{ topic.creator }}</a><br>
                <i class="fa fa-clock-o"></i> {{ topic.created|timesince }} ago



            {% if user.is_authenticated %}
                {% if topic.creator == user %}
                    <div class="dropdown pull-right">
                        <button class="btn-sm btn btn-default endbtn" type="button" id="topicEditMenu" data-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="true">
                            Edit
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="topicEditMenu">
                            <li><a href="{% url 'forum:topic_update' topic.slug %}">Edit</a></li>
                            <li><a href="{% url 'forum:topic_delete' topic.slug %}">Delete</a></li>
                        </ul>
                    </div>
                {% endif %}
                <a href="{% url 'forum:new_post' topic.slug %}">
                    <button class="btn-sm btn btn-success pull-right endbtn">New Post in {{ topic }}</button>
                </a>
            {% else %}
                <a href="{% url 'account_login' %}">Login</a> or <a href="{% url 'account_signup' %}">Register</a> to
                    join the discussion!</p>
            {% endif %}
{#            <div class="clearfix"></div>#}
{#        </div>#}


        <table class="table forum table-striped">
            <thead>
            <tr>
                <th class="cell-stat"></th>
                <th>
                    <h3>Post</h3>
                </th>
                <th class="cell-stat text-center hidden-xs hidden-sm">Replies</th>
                <th class="cell-stat-2x hidden-xs hidden-sm">Last Reply</th>
            </tr>
            </thead>
            <tbody>
            {% for post in posts %}
                <tr>
                    <td class="text-center"><i class=" fa fa-2x fa-sticky-note-o text-primary "
                            {# todo: add this to post type #}></i></td>
                    <td>
                        <h4><a href="{% url 'forum:post' topic.slug post.slug %}">{{ post }}</a><br>
                            <small>{{ post.description }}</small>
                        </h4>
                    </td>
                    <td class="text-center hidden-xs hidden-sm"><a href="#">{{ post.reply_set.count }}</a></td>

                    <td class="hidden-xs hidden-sm">
                        {% if post.last_reply %}
                            {% if user.is_authenticated %}
                                {% if topic.last_post.creator == request.user %}
                                    by You
                                {% else %}
                                    by {{ topic.last_post.creator }}
                                {% endif %}
                            {% else %}
                                {{ topic.last_post.creator }}
                            {% endif %}
                            <small><i class="fa fa-clock-o"></i> {{ post.last_reply.created|timesince }} ago</small>
                        {% else %}
                            No replies yet!
                        {% endif %}
                    </td>

                </tr>
            {% endfor %}

            </tbody>
        </table>
        {% if posts.count == 0 %}
            {% if user.is_authenticated %}
                <p class="center-block">Nothing here yet, why not <a href="{% url 'forum:new_post' topic.slug %}">post
                    something!</a></p>
            {% else %}
                <p class="center-block"><a href="{% url 'account_login' %}">Login</a> or <a
                        href="{% url 'account_signup' %}">Register</a> post in {{ topic }}!</p>
            {% endif %}
        {% endif %}
    </div>
    </div>

{% endblock content %}





