{% extends '@ChillMain/Admin/layoutWithVerticalMenu.html.twig' %}

{% block title %}{{ 'Permission group "%name%"'|trans({ '%name%': entity.name }) }}{% endblock %}

{% block admin_content -%}
    <h1 class="mb-4">{{ 'Permission group "%name%"'|trans({ '%name%': entity.name }) }}</h1>

    <table class="table table-bordered border-dark align-middle">
        <tbody>
            <tr>
                <th>{{ 'Name'|trans }}</th>
                <td class="w-25">{{ entity.name }}</td>
            </tr>
        </tbody>
    </table>

    {% if role_scopes_sorted|length > 0 %}
    <h2 class="mb-5">{{ 'Grant those permissions'|trans }}&nbsp;:</h2>

    {% for title, role_scopes in role_scopes_sorted %}
    <h3>{{ title|default('Unclassified')|trans }}</h3>
    <table class="table table-bordered border-dark align-middle mb-5">
        <thead>
            <tr>
                <th class="w-25">{{ 'Circle'|trans }}</th>
                <th>{{ 'Role'|trans }}</th>
            </tr>
        </thead>
        <tbody>

            {% for role_scope in role_scopes %}
            <tr>
                <td style="width: 7em">{%- if role_scope.scope is not null -%}
                        {{ role_scope.scope.name|localize_translatable_string }}
                    {%- else -%}
                        <small><i>N/A</i></small>
                    {%- endif -%}
                </td>
                <td>
                    <span class="role_scope role">{{ role_scope.role|trans }}</span>
                    {% if expanded_roles[role_scope.role]|length > 1 %}
                        <div class="help-text">
                            <span style="text-decoration: underline dotted;">{{ 'Which implies'|trans }}&nbsp;:</span>
                            {% for role in expanded_roles[role_scope.role] %}
                                {% if role != role_scope.role  %}
                                    {{ role|trans }}
                                    {% if not loop.last %}, {% endif %}
                                {% endif %}
                            {% endfor %}
                        </div>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% endfor %}

    {% else %}
        <p>{{ 'This group does not provide any permission'|trans }}.
            <a href="{{ path('admin_permissionsgroup_edit', { 'id': entity.id }) }}">
                {{ 'add permissions'|trans|capitalize }}
            </a>
        </p>
    {% endif %}

    <ul class="record_actions sticky-form-buttons">
        <li class="cancel">
            <a href="{{ path('admin_permissionsgroup') }}" class="btn btn-cancel">
                {{ 'Back to the list'|trans }}
            </a>
        </li>
        <li>
            <a href="{{ path('admin_permissionsgroup_edit', { 'id': entity.id }) }}" class="btn btn-edit">
               {{ 'Edit'|trans }}
            </a>
        </li>
    </ul>
{% endblock %}
