{% load i18n %}
{% load mptt_tags %}
{% load forum_tags %}
{% load forum_conversation_tags %}
{% load forum_member_tags %}
{% load forum_tracking_tags %}

<div class="row">
  <div class="col-12">
    {% if forum_contents.nodes %}
    {% recurseforumcontents forum_contents %}
    {% if node.level == root_level %}
    {% if node.obj.is_category %}
    <div class="mt-3 card forumlist">
      <div class="p-0 card-header">
        <div class="row m-0 px-3 py-2">
          <div class="pl-0 col-md-8 col-sm-9 col-12 forum-name-col">
            <h3 class="m-0 card-title h5"><a href="{% url 'forum:forum' node.obj.slug node.obj.id %}" class="text-dark">{{ node.obj.name }}</a></h3>
          </div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Topics" %}</div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Posts" %}</div>
          <div class="pr-0 col-md-2 col-sm-3 d-none d-sm-block text-nowrap forum-last-post-col">{% trans "Last post" %}</div>
        </div>
      </div>
      <div class="p-0 card-body">
        {{ children }}
      </div>
    </div>
    {% else %}
    {% with node.previous_sibling.obj as previous_sibling %}
    {% if previous_sibling and previous_sibling.is_category or not previous_sibling in forum_contents.visible_forums or not previous_sibling %}
    <div class="mt-3 card forumlist">
      <div class="p-0 card-header">
        <div class="row m-0 px-3 py-2">
          <div class="pl-0 col-md-8 col-sm-9 col-12 forum-name-col">
            <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
          </div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Topics" %}</div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Posts" %}</div>
          <div class="pr-0 col-md-2 col-sm-3 d-none d-sm-block text-nowrap forum-last-post-col">{% trans "Last post" %}</div>
        </div>
      </div>
      <div class="p-0 card-body">
    {% endif %}
    {% endwith %}
    <div class="row m-0 px-3 py-2 border-bottom">
      {% if not node.obj.is_link %}
      <div class="pl-0 col-md-7 col-sm-9 col-11 forum-name">
        <table class="forum-data-table">
          <tr>
            <td class="pt-1 pr-3 align-top forum-icon {% if node.obj in unread_forums %}unread{% endif %}">
              <i class="far fa-circle fa-2x"></i>
            </td>
            <td>
            {% if node.obj.image %}
            <td>
              <div class="d-none d-md-block forum-image pr-2">
                <img src="{{ node.obj.image.url }}" alt="{{ node.obj.name }}" />
              </div>
            </td>
            {% endif %}
            <td class="align-top">
              <a href="{% url 'forum:forum' node.obj.slug node.obj.id %}" class="forum-name-link">{{ node.obj.name }}</a>
              <div class="forum-description">{{ node.obj.description.rendered }}</div>
              <div class="sub-forums"><small>{{ children }}</small></div>
            </td>
          </tr>
        </table>
      </div>
      <div class="py-2 col-md-1 d-none d-md-block forum-syndication"></div>
      <div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.topics_count }}</div>
      <div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
      <div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
        {% if node.last_post %}
        {% if node.last_post.poster %}
        {% url 'forum_member:profile' node.last_post.poster_id as poster_url %}
        {% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %}
        By: <a href="{{ poster_url }}">{{ username }}</a>
        {% endblocktrans %}
        {% include "partials/user_icon.html" with topic=node.last_post.topic user=node.last_post.poster %}
        {% else %}
        {% blocktrans trimmed with poster_username=node.last_post.username %}
        By: {{ poster_username }}
        {% endblocktrans %}
        {% endif %}
        &nbsp;<a href="{% url 'forum_conversation:topic' node.obj.slug node.obj.pk node.last_post.topic.slug node.last_post.topic.pk %}?post={{ node.last_post.pk }}#{{ node.last_post.pk }}"><i class="fas fa-arrow-circle-right "></i></a>
        <br />
        <small>{{ node.last_post.created }}</small>
        {% else %}
        {% trans "No posts" %}
        {% endif %}
      </div>
      {% else %}
      <div class="pl-0 col-md-8 col-sm-9 col-11 forum-name" colspan="2">
        <table class="forum-data-table">
          <tr>
            <td class="pt-1 pr-3 align-top forum-icon link"><i class="fas fa-link fa-2x"></i></td>
            <td class="align-top">
              <a href="{% url 'forum:forum' node.obj.slug node.obj.id %}" class="forum-name-link">{{ node.obj.name }}</a>
              <div class="forum-description">{{ node.obj.description.rendered }}</div>
            </td>
          </tr>
        </table>
      </div>
      <div class="col-md-1 d-none d-md-block forum-count"></div>
      <div class="col-md-1 d-none d-md-block forum-count"></div>
      <div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-link-redirects">
        {% if node.obj.link_redirects %}
        {% trans "Total redirects:" %}&nbsp;{{ node.obj.link_redirects_count|default:"0" }}
        {% endif %}
      </div>
    {% endif %}
    </div>
    {% with node.next_sibling.obj as next_sibling %}
    {% if next_sibling and next_sibling.is_category or not next_sibling in forum_contents.visible_forums or not next_sibling %}
      </div>
    </div>
    {% endif %}
    {% endwith %}
    {% endif %}
    {% elif node.level == root_level_middle %}
    {% if node.parent.obj.is_category %}
    <div class="row m-0 px-3 py-2 border-bottom">
      {% if not node.obj.is_link %}
      <div class="pl-0 col-md-7 col-sm-9 col-11 forum-name">
        <table class="forum-data-table">
          <tr>
            <td class="pt-1 pr-3 align-top forum-icon {% if node.obj in unread_forums %}unread{% endif %}"><i class="far fa-circle fa-2x"></i></td>
            {% if node.obj.image %}
            <td>
              <div class="d-none d-md-block forum-image pr-2">
                <img src="{{ node.obj.image.url }}" alt="{{ node.obj.name }}" />
              </div>
            </td>
            {% endif %}
            <td class="align-top">
              <a href="{% url 'forum:forum' node.obj.slug node.obj.id %}" class="forum-name-link">{{ node.obj.name }}</a>
              <div class="forum-description">{{ node.obj.description.rendered }}</div>
              <div class="sub-forums"><small>{{ children }}</small></div>
            </td>
          </tr>
        </table>
      </div>
      <div class="py-2 col-md-1 d-none d-md-block forum-syndication"></div>
      <div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.topics_count }}</div>
      <div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
      <div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
        {% if node.last_post %}
        {% if node.last_post.poster_id %}
        {% url 'forum_member:profile' node.last_post.poster_id as poster_url %}
        {% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %}
        By: <a href="{{ poster_url }}">{{ username }}</a>
        {% endblocktrans %}
        {% include "partials/user_icon.html" with topic=node.last_post.topic user=node.last_post.poster %}
        {% else %}
        {% blocktrans trimmed with poster_username=node.last_post.username %}
        By: {{ poster_username }}
        {% endblocktrans %}
        {% endif %}
        &nbsp;<a href="{% url 'forum_conversation:topic' node.obj.slug node.obj.pk node.last_post.topic.slug node.last_post.topic.pk %}?post={{ node.last_post.pk }}#{{ node.last_post.pk }}"><i class="fas fa-arrow-circle-right "></i></a>
        <br />
        <small>{{ node.last_post.created }}</small>
        {% else %}
        {% trans "No posts" %}
        {% endif %}
      </div>
      {% else %}
      <div class="pl-0 col-md-8 col-sm-9 col-11 forum-name" colspan="2">
        <table class="forum-data-table">
          <tr>
            <td class="pt-1 pr-3 align-top forum-icon link"><i class="fas fa-link fa-2x"></i></td>
            <td class="align-top">
              <a href="{% url 'forum:forum' node.obj.slug node.obj.id %}" class="forum-name-link">{{ node.obj.name }}</a>
              <div class="forum-description">{{ node.obj.description.rendered }}</div>
            </td>
          </tr>
        </table>
      </div>
      <div class="col-md-1 d-none d-md-block forum-count"></div>
      <div class="col-md-1 d-none d-md-block forum-count"></div>
      <div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post forum-link-redirects">
        {% if node.obj.link_redirects %}
        {% trans "Total redirects:" %}&nbsp;{{ node.obj.link_redirects_count|default:"0" }}
        {% endif %}
      </div>
      {% endif %}
    </div>
    {% else %}
    {% if not node.previous_sibling %}
    <b>{% trans "Subforums:" %}</b>&nbsp;
    {% endif %}
    <i class="fas fa-file"></i>&nbsp;<a href="{% url 'forum:forum' node.obj.slug node.obj.id %}">{{ node.obj.name }}</a>&nbsp;&nbsp;
    {% endif %}
    {% elif node.level == root_level_sub %}
    {% if not node.previous_sibling %}
    <b>{% trans "Subforums:" %}</b>&nbsp;
    {% endif %}
    <i class="fas fa-file"></i>&nbsp;<a href="{% url 'forum:forum' node.obj.slug node.obj.id %}">{{ node.obj.name }}</a>&nbsp;&nbsp;
    {% endif %}
    {% endrecurseforumcontents %}
    {% else %}
    <div class="mt-3 card forumlist">
      <div class="p-0 card-header">
        <div class="row m-0 px-3 py-2">
          <div class="pl-0 col-md-8 col-sm-9 col-9 forum-name-col">
            <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
          </div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Topics" %}</div>
          <div class="col-md-1 d-none d-md-block text-center text-nowrap forum-count-col">{% trans "Posts" %}</div>
          <div class="pr-0 col-md-2 col-sm-3 d-none d-sm-block text-nowrap forum-last-post-col">{% trans "Last post" %}</div>
        </div>
      </div>
      <div class="p-0 card-body">
        <div class="m-0 px-3 py-2 row">
          <div class="p-0 col-md-12">{% trans "No forums." %}</div>
        </div>
      </div>
    </div>
    {% endif %}
  </div>
</div>
