{% extends "forum/_base.html" %}
{%- from "macros/user.html" import m_user_link, m_user_photo %}
{% from "macros/box.html" import m_box_menu, m_box_content %}
{% from "forum/_macros.html" import forum_menu %}


{% block forumcontent %}
  {% call m_box_content(_("Recent conversations")) %}

    <div class="forum-menu-container">
      <div class="forum-menu" role="group">
        {%- set global_actions = actions.for_category('forum:global') %}
        {%- for action in global_actions %}
          {{ forum_menu(action) }}
        {%- endfor %}
      </div>
    </div>

    {% if threads %}
      <table class="thread-table" border="0">
        <tr>
          <th>
            {{ _("Topic") }}
          </th>
          <th>
            {{ _("Participants") }}
          </th>
          <th>
            {{ _("Replies") }}
          </th>
          <th>
            {{ _("Viewers") }}
          </th>
          <th>
            {{ _("Views") }}
          </th>
          <th>
            {{ _("Activity") }}
          </th>
        </tr>
        {% for thread in threads %}
          {{ m_thread(thread) }}
        {% endfor %}
      </table>
      <br>
      <br> {% else %}
      <p>{{ _("No message has been posted to this community yet.") }}</p>
    {% endif %}
    {% if has_more or True %}
      <br>
      <p class="thread-all"><i class="fa fa-th-list" aria-hidden="true" style="color:gray;"></i> <a
          href="{{ url_for('.archives', community_id=g.community.slug) }}">{{ _("All conversations") }}</a></p>
    {% endif %}
  {% endcall %}
{% endblock %}



{% macro m_thread(thread) %}
  {%- set thread_href = url_for(thread) %}
  {%- set thread_length = thread.posts|length %}
  <tr>
    <td>
      <div class="entry">
        <h4 class="thread-list-title"><a href="{{ thread_href }}"
                                         title="{{ thread.created_at | age(date_threshold='day') }}"
                                         class="thread-title"> {{ thread.title }} </a></h4>
        {%- if thread.closed %}
          <i class="fa fa-lock fa-big"></i>
        {%- endif %}
      </div>
    </td>
    <td class="thread-frequent-posters">
      {% call m_user_link(thread.creator) %}
        {{ m_user_photo(thread.creator, size=40) }}
      {%- endcall %}

      {% for p in thread.get_frequent_posters(5) %}
        {% call m_user_link(p) %}
          <span class="thread-participants-logo">
          {{ m_user_photo(p, size=30) }}
        </span>
        {%- endcall %}
      {% endfor %}
    </td>
    <td>
      <center>
        <div class="comments" style="position: relative;">
          <a class="thread-replies" href="{{ thread_href }}">{{ thread_length-1 }}</a>
          {% if nb_viewed_posts[thread] %}
            <span style="color:gray;"></span>
            <span class="thread-hilightview"
                  title="not viewed"><span
                class="badge thread-unread-posts">+{{ nb_viewed_posts[thread] }}</span></span>
          {% endif %}
        </div>
      </center>
    </td>
    <td style="width:10%;">
      <center>
        <span class="thread-viewers">
          <i class="fa fa-user" aria-hidden="true"></i>
          {{ nb_viewers[thread] }}
        </span>
      </center>
    </td>
    <td style="width:0%;">
      <center>
        <span class="thread-viewed-times"> {% if nb_viewed_times[thread] %}{{ nb_viewed_times[thread] }}{% else %}
          0{% endif %}</span>
      </center>
    </td>
    <td>
      <center>
          <span class="hidden-xs">
          <span class="divider"
              {% set activity_time = activity_time_format(thread.last_post_at) %}
                style="color:silver;">{{ activity_time }}</span>
        </span>
      </center>
    </td>
  </tr>
{% endmacro %}
