{% load i18n %}
{% load tags %}
{% load common_tags %}
{% load pybb_tags %}
{% load el_pagination_tags %}

{% forum_latest_topics user=request.user as topic_list %}

{% lazy_paginate 10 topic_list using "latest_from_forums_page" %}
{% for topic in topic_list|pybb_topic_unread:request.user %}
    <tr class="topic-row{% if topic.on_moderation %} on-moderation{% endif %}">
        <td class="topic-state{% if topic.unread %} topic-unread{% endif %}">
            <div class="state-indicator"></div>
        </td>

        <td class="topic-name{% if topic.unread %} topic-unread{% endif %}">
            <a href="{{ topic.get_absolute_url }}">
                {{ topic.name|truncatechars:120 }}
            </a>
            {% if topic.closed %} &nbsp;[{% trans "Closed" %}] {% endif %}

            <span class="posted-in">
                {% blocktrans trimmed with forum_name=topic.forum.name forum_url=topic.forum.get_absolute_url %}
                    Posted in <a href="{{ forum_url }}">{{ forum_name }}</a>
                {% endblocktrans %}
            </span>

            <br />

            {% if not topic.user.userprofile.deleted %}
                {% url 'user_page' topic.user as topic_user_url %}
                {% blocktrans trimmed with username=topic.user.userprofile.get_display_name|truncatechars:30 %}
                    Started by <a href="{{ topic_user_url }}">{{ username }}</a>
                {% endblocktrans %}
            {% else %}
                {% trans "Started by user that was since deleted" %}
            {% endif %}
            &middot;
            {% timestamp topic.created %}

            {% with topic|pybb_topic_inline_pagination as pages %}
                {% if pages|length > 1 %}
                    <span class="mini-pagination">
                        {% for page in pages %}
                            <span class="page">
                                {% if page == "..." %}
                                    ...
                                {% else %}
                                    <a href="{{ topic.get_absolute_url }}?page={{ page }}">
                                        {{ page }}
                                    </a>
                                {% endif %}
                            </span>
                        {% endfor %}
                    </span>
                {% endif %}
            {% endwith %}

            {% if topic.updated and not topic.last_post.user.userprofile.deleted %}
                <br />

                {% with topic.last_post as last_post %}
                    {% url 'user_page' last_post.user as last_post_user_url %}
                    {% blocktrans trimmed with username=last_post.user.userprofile.get_display_name|truncatechars:30 %}
                        Last post by <a href="{{ last_post_user_url }}">{{ username }}</a>
                    {% endblocktrans %}
                    &middot;
                    {% timestamp topic.updated %}
                {% endwith %}
            {% endif %}
        </td>

        <td class="topic-post-count hidden-phone">
            <span class="post-count">
                <i class="icon-comment"></i>
                {{ topic.post_count|add:"-1" }}
            </span>
            <span class="view-count">
                <i class="icon-eye-open"></i>
                {{ topic|pybbm_calc_topic_views }}
            </span>
            <span class="image-count">
                <i class="icon-camera"></i>
                {{ topic.images }}
            </span>
        </td>

        <td class="topic-last-post hidden-phone hidden-tablet">
            {% include "pybb/topic_last_message_info.html" %}
        </td>

        <td class="first-unread">
            <a href="{{ topic.get_absolute_url }}?first-unread=1" class="first-unread-post-link">
                <i class="icon-chevron-right"></i>
            </a>
        </td>
    </tr>
{% endfor %}

<tr>
    <td colspan="5">
        <div class="pagination pagination-centered">
            <button class="btn btn-primary btn-block-mobile {% button_loading_class %}">
                {% trans "More" %}
                {% button_loading_indicator %}
            </button>
        </div>
    </td>
</tr>
