{% extends "misago/admin/generic/list.html" %}
{% load i18n %}


{% block page-actions %}
<div class="col-auto page-action">
  <a href="{% url 'misago:admin:ranks:new' %}" class="btn btn-primary btn-sm">
    <span class="fa fa-plus-circle"></span>
    {% trans "New rank" context "admin ranks" %}
  </a>
</div>
{% endblock %}


{% block table-header %}
<th style="width: 1px;">&nbsp;</th>
<th>{% trans "Rank" context "admin ranks list" %}</th>
<th style="width: 1px;">&nbsp;</th>
<th>{% trans "Title" context "admin ranks list" %}</th>
<th>{% trans "CSS class" context "admin ranks list" %}</th>
{% for action in extra_actions %}
  <th style="width: 1px;">&nbsp;</th>
{% endfor %}
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
{% endblock table-header %}


{% block table-row %}
<td class="pr-0">
  {% if item.is_tab %}
    <a href="{{ item.get_absolute_url }}" class="btn btn-light btn-sm">
      <span class="fas fa-external-link-alt"></span>
    </a>
  {% endif %}
</td>
<td class="pr-0">
  <a href="{% url 'misago:admin:ranks:edit' pk=item.pk %}" class="item-name small">
    {{ item }}
  </a>
</td>
<td class="badges-list">
  {% if item.is_tab %}
    <span class="badge badge-success" data-tooltip="top" title="{% trans 'Has dedicated page on users list' context 'admin ranks' %}">
      {% trans "Tab" context "admin rank has tab status" %}
    </span>
  {% endif %}
  {% if item.is_default %}
    <span class="badge badge-primary" data-tooltip="top" title="{% trans 'This is default rank assigned to new members' context 'admin ranks' %}">
      {% trans "Default" context "admin rank is default status" %}
    </span>
  {% endif %}
</td>
<td class="small">
  {% if item.title %}
    {{ item.title }}
  {% else %}
    <i class="text-muted">{% trans "Not set" context "admin rank user title" %}</i>
  {% endif %}
</td>
<td class="small">
  {% if item.css_class %}
    <pre class="m-0">{{ item.css_class }}</pre>
  {% else %}
    <i class="text-muted">{% trans "Not set" context "admin rank css class" %}</i>
  {% endif %}
</td>
{% include "misago/admin/generic/list_extra_actions.html" %}
<td>
  {% if not forloop.last %}
    <form action="{% url 'misago:admin:ranks:down' pk=item.pk %}" method="post">
      {% csrf_token %}
      <button class="btn btn-light btn-sm" data-tooltip="top" title="{% trans 'Move down' context 'admin ranks' %}">
        <span class="fa fa-chevron-down"></span>
      </button>
    </form>
  {% else %}
    <button class="btn btn-light btn-sm" disabled>
      <span class="fa fa-chevron-down"></span>
    </button>
  {% endif %}
</td>
<td>
  {% if not forloop.first %}
    <form action="{% url 'misago:admin:ranks:up' pk=item.pk %}" method="post">
      {% csrf_token %}
      <button class="btn btn-light btn-sm" data-tooltip="top" title="{% trans 'Move up' context 'admin ranks' %}">
        <span class="fa fa-chevron-up"></span>
      </button>
    </form>
  {% else %}
    <button class="btn btn-light btn-sm" disabled>
      <span class="fa fa-chevron-up"></span>
    </button>
  {% endif %}
</td>
<td>
  <div class="dropdown">
    <button class="btn btn-light btn-sm dropdown-toggle" type="button" id="item-optioms-{{ item.pk }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <i class="fas fa-ellipsis-h"></i>
    </button>
    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="item-optioms-{{ item.pk }}">
      <a class="dropdown-item" href="{% url 'misago:admin:ranks:users' pk=item.pk %}">
        {% trans "List users" context "admin ranks" %}
      </a>
      {% if not item.is_default %}
        <form action="{% url 'misago:admin:ranks:default' pk=item.pk %}" method="post">
          {% csrf_token %}
          <button class="dropdown-item">
            {% trans "Set as default" context "admin ranks" %}
          </button>
        </form>
      {% endif %}
      <a class="dropdown-item" href="{% url 'misago:admin:ranks:edit' pk=item.pk %}">
        {% trans "Edit rank" context "admin ranks" %}
      </a>
      <form action="{% url 'misago:admin:ranks:delete' pk=item.pk %}" method="post" data-delete-confirmation="true">
        {% csrf_token %}
        <button class="dropdown-item">
          {% trans "Delete rank" context "admin ranks" %}
        </button>
      </form>
    </div>
  </div>
</td>
{% endblock %}


{% block blankslate %}
<td colspan="{{ 8|add:extra_actions_len }}">
  {% trans "No user ranks are set." context "admin ranks" %}
</td>
{% endblock blankslate %}


{% block javascripts %}
<script type="text/javascript">
  window.misago.initConfirmation(
    "[data-delete-confirmation]",
    "{% trans 'Are you sure you want to delete this rank?' context 'admin ranks' %}"
  )
</script>
{% endblock %}
