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

{% block admin_content -%}
    {% embed '@ChillMain/CRUD/_edit_content.html.twig' %}

        {% block crud_content_after_form %}
            {% if access_permissions_group_list %}
                <h2 class="mt-5">{{ 'Permissions granted'|trans }}</h2>

                {% if entity.groupcenters|length > 0 %}
                    <table class="table table-bordered border-dark align-middle mb-5">
                        <thead>
                        <tr>
                            <th>{{ 'Permission group'|trans }}</th>
                            <th>{{ 'Center'|trans }}</th>
                            <th>&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for groupcenter in entity.groupcenters %}
                            <tr>
                                <td>
                                    <span class="user_group permissionsgroup">
                                        {{ groupcenter.permissionsgroup.name }}
                                    </span>
                                </td>
                                <td>
                                    <span class="user_group center">
                                        {{ groupcenter.center.name }}
                                    </span>
                                </td>
                                <td class="w-25 text-end">
                                    {{ form_start(delete_groupcenter_form[groupcenter.id]) }}
                                    {{ form_widget(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'btn btn-remove' } } ) }}
                                    {{ form_rest(delete_groupcenter_form[groupcenter.id]) }}
                                    {{ form_end(delete_groupcenter_form[groupcenter.id]) }}
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                {% else %}
                    <p>{{ 'Any permissions granted to this user'|trans }}.</p>
                {% endif %}

                <h3>{{ 'Grant new permissions'|trans }}</h3>

                {{ form_start(add_groupcenter_form) }}
                {{ form_row(add_groupcenter_form.composed_groupcenter.center) }}
                {{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }}
                {{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'btn btn-create' } } ) }}

                {{ form_end(add_groupcenter_form) }}
            {% endif %}
        {% endblock %}

        {% block content_form_actions_save_and_show %}{% endblock %}

        {% block content_form_actions_view %}
        <li>
            <a href="{{ path('admin_user_job_scope_history', {id: entity.id}) }}" class="btn btn-show">
                {{ 'admin.users.job_scope_histories.Show history'|trans }}
            </a>
        </li>
        {% endblock %}

    {% endembed %}
{% endblock %}
