{% extends "organization/edit_base.html" %}

{% block subtitle %}{{ _('Members') }} {{ g.template_title_delimiter }} {{ super() }}{% endblock %}

{% block page_primary_action %}
  {% if h.check_access('organization_update', {'id': organization.id}) %}

    {% link_for _('Add Member'), named_route=group_type+'.member_new', id=group_dict.id, class_='btn btn-primary', icon='plus-square' %}
    {% link_for _('CSV'), named_route=group_type+'.member_dump', id=group_dict.id, class_='btn btn-primary', icon='download' %}
  {% endif %}
{% endblock %}

{% block primary_content_inner %}
  {% set count = members|length %}
  {% set members_count = ungettext('{count} member', '{count} members', count).format(count=count) %}
  {% set can_create_members = h.check_access('organization_member_create', {'id': organization.id}) %}
  {% set can_delete_members = h.check_access('organization_member_delete', {'id': organization.id}) %}
  <h3 class="page-heading">{{ members_count }}</h3>
  <table class="table table-header table-hover table-bordered">
    <thead>
      <tr>
          <th>{{ _('User') }}</th>
          <th>{{ _('Role') }}</th>
          {% if can_create_members or can_delete_members %}
            <th></th>
          {% endif %}
      </tr>
    </thead>
    <tbody>
      {% for user_id, user, role in members %}
        <tr>
          <td class="media">
            {{ h.linked_user(user_id, maxlength=20) }}
          </td>
          <td>{{ role }}</td>
          {% if can_create_members or can_delete_members %}
            <td>
              <div class="btn-group pull-right">
                {% if can_create_members %}
                  <a class="btn btn-secondary btn-sm" href="{{ h.url_for(group_type + '.member_new', id=group_dict.id, user=user_id) }}" aria-label="{{ _('Edit role') }}" aria-description="{{ _('Edit the role of the user within the organization') }}" data-bs-title="{{ _('Edit role') }}" data-bs-toggle="tooltip">
                    <i class="fa fa-wrench"></i>
                  </a>
                {% endif %}

                {% if can_delete_members %}
                  <a class="btn btn-danger btn-sm" href="{{ h.url_for(group_type + '.member_delete', id=group_dict.id, user=user_id) }}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this member?') }}" aria-label="{{ _('Delete member') }}" aria-description="{{ _('Delete this member from the organization') }}" data-bs-title="{{ _('Delete member') }}"  data-bs-toggle="tooltip">{% block delete_button_text %}<i class="fa fa-times"></i>{% endblock %}</a>
                {% endif %}
              </div>
            </td>
          {% endif %}
        </tr>
      {% endfor %}
    </tbody>
  </table>
{% endblock %}
