{% extends "templates/base_index.html" %}

{% block title %}{{ i18n('interface.permissions.title') }}{% endblock %}

{% block new_resource_label %}{{ i18n('interface.common.new_permission') }}{% endblock %}

{% block extra_buttons %}

  <div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle h-100" type="button" data-bs-toggle="dropdown" aria-expanded="false">
      {{ i18n('interface.permissions.role_filter') }}: {{ active_role if active_role is not none and active_role != 'all' else i18n('interface.common.all') }}
    </button>
    <ul class="dropdown-menu">
      <li>
        <a
          class="dropdown-item {{ 'active' if active_role is none or active_role == 'all' }}"
          href="{{ url_for('permissions', role='all', type=active_resource_type) }}"
        >{{ i18n('interface.common.all') }}</a>
      </li>
      <li><hr class="dropdown-divider"></li>
      {% for role in roles %}
        <li>
          <a
            class="dropdown-item  {{ 'active' if role.name == active_role }}"
            href="{{ url_for('permissions', role=role.name, type=active_resource_type) }}"
          >{{ role.name }}</a>
        </li>
      {% endfor %}
    </ul>
  </div>


  <div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle h-100" type="button" data-bs-toggle="dropdown" aria-expanded="false">
      {{ i18n('interface.permissions.type_filter') }}: {{ resource_types[active_resource_type] if active_resource_type is not none else i18n('interface.common.all') }}
    </button>
    <ul class="dropdown-menu">
      <li>
        <a
          class="dropdown-item {{ 'active' if active_resource_type is none or active_resource_type == 'all' }}"
          href="{{ url_for('permissions', role=active_role, type='all') }}"
        >{{ i18n('interface.common.all') }}</a>
      </li>
      <li><hr class="dropdown-divider"></li>
      {% for resource_type in resource_types %}
        <li>
          <a
            class="dropdown-item  {{ 'active' if resource_type == active_resource_type }}"
            href="{{ url_for('permissions', role=active_role, type=resource_type) }}"
          >{{ resource_types[resource_type] }}</a>
        </li>
      {% endfor %}
    </ul>
  </div>

{% endblock %}

{% block table_headers %}
  <th>{{ sortable_column(i18n('interface.common.id'), 'id') }}</th>
  <th>{{ sortable_column(i18n('interface.common.role'), 'role') }}</th>
  <th>{{ sortable_column(i18n('interface.permissions.resource_type'), 'type') }}</th>
  <th>{{ sortable_column(i18n('interface.common.resource'), 'resource') }}</th>
  <th>{{ sortable_column(i18n('interface.permissions.priority'), 'priority') }}</th>
  <th>{{ sortable_column(i18n('interface.permissions.write'), 'write') }}</th>
{% endblock %}

{% block resource_fields %}
  <td>{{ resource.id }}</td>
  <td>{{ resource.role.name }}</td>
  <td>{{ resource_types[resource.resource.type] }}</td>
  <td>{{ resource.resource.name }}
    {% if resource.resource.parent %}
      (<i>{{ parents_dict[resource.resource.parent.id] }}</i>)</td>
    {% endif %}
  <td>{{ resource.priority }}</td>
  <td>{{ resource.write }}</td>
{% endblock %}

{% block delete_resource_confirmation %}{{ i18n('interface.permissions.confirm_message_delete') }}{% endblock %}
