{% requireEdition CraftPro %}
{% requireAdmin %}

{% extends "settings/users/_layout" %}
{% set selectedNavItem = 'groups' %}


{% set groups = craft.app.userGroups.getAllGroups() %}


{% block content %}
    <p id="nogroups"{% if groups|length %} class="hidden"{% endif %}>
        {{ "No groups exist yet."|t('app') }}
    </p>

    {% if groups|length %}
        <table id="groups" class="data fullwidth collapsible">
            <thead>
                <th scope="col">{{ "Name"|t('app') }}</th>
                <th scope="col">{{ "Handle"|t('app') }}</th>
                <td class="thin"></td>
            </thead>
            <tbody>
                {% for group in groups %}
                    <tr data-id="{{ group.id }}" data-name="{{ group.name|t('site') }}">
                        <th scope="row" data-title="{{ 'Name'|t('app') }}"><a href="{{ url('settings/users/groups/' ~ group.id) }}">{{ group.name|t('site') }}</a></th>
                        <td data-title="{{ 'Handle'|t('app') }}"><code>{{ group.handle }}</code></td>
                        <td class="thin"><a class="delete icon" title="{{ 'Delete'|t('app') }}" role="button"></a></td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}

    <div class="buttons">
        <a href="{{ url('settings/users/groups/new') }}" class="btn submit add icon">{{ "New user group"|t('app') }}</a>
    </div>
{% endblock %}


{% js %}
    new Craft.AdminTable({
        tableSelector: '#groups',
        noItemsSelector: '#nogroups',
        deleteAction: 'user-settings/delete-group'
    });
{% endjs %}
