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

{% block title 'title.bans_in_forum'|trans({'%forum%': '/f/'~forum.name}) %}

{% block head %}
  {{ parent() }}
  {{ include('_includes/meta_pagination.html.twig', {pager: bans}, with_context=false) }}
{% endblock head %}

{% block body %}
  <h1 class="page-heading">{{ block('title') }}</h1>

  {% embed '_layouts/table.html.twig' with { items: bans } %}
    {% block header %}
      <th class="table__shrink">{{ 'label.username'|trans }}</th>
      <th>{{ 'label.reason'|trans }}</th>
      <th class="table__shrink">{{ 'label.banned'|trans }}</th>
      <th class="table__shrink">{{ 'label.expires'|trans }}</th>
      {% if is_granted('moderator', forum) %}
        <th class="table__shrink"></th>
      {% endif %}
    {% endblock header %}

    {% block row %}
      {% from '_macros/time.html.twig' import relative_time %}
      {% from 'user/_macros.html.twig' import user_link %}

      <td class="table__shrink">{{ user_link(item.user) }}</td>
      <td>{{ item.reason }}</td>
      <td class="table__shrink">
        {{ relative_time(item.timestamp, { date_format: 'short', time_format: 'none' }) }}
      </td>
      <td class="table__shrink">
        {% if item.expires %}
          {{ relative_time(item.expires, { date_format: 'short' }) }}
        {% else %}
          <small class="fg-muted text-sm">{{ 'label.never'|trans }}</small>
        {% endif %}
      </td>
      {% if is_granted('moderator', forum) %}
        <td class="table__shrink">
          <a href="{{ path('forum_ban_history', {forum_name: forum.name, username: item.user.username}) }}"
             class="button button--small inline">
            {{- 'nav.ban_history'|trans -}}
          </a>
          <a href="{{ path('forum_unban', {forum_name: forum.name, username: item.user.username}) }}"
             class="button button--small inline">
            {{- 'action.unban'|trans -}}
          </a>
        </td>
      {% endif %}
    {% endblock row %}
  {% endembed %}
{% endblock body %}

