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

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

        {% block index_header %}
            <h1>{{"Users"|trans}}</h1>
        {% endblock %}

        {% block filter_order %}{{ filter_order|chill_render_filter_order_helper }}{% endblock %}

        {% block table_entities_thead_tr %}
            <th>{{ 'Active'|trans }}</th>
            <th>{{ 'absence.Is absent'|trans }}</th>
            <th>{{ 'Username'|trans }}</th>
            <th>{{ 'Datas'|trans }}</th>
            <th>{{ 'Actions'|trans }}</th>
        {% endblock %}

        {% block table_entities_tbody %}
            {% for entity in entities %}
                <tr>
                    <td>
                        {% if entity.isEnabled %}
                            <i class="fa fa-check-square-o"></i>
                        {% else %}
                            <i class="fa fa-square-o"></i>
                        {% endif %}
                    </td>
                    <td>
                        {% if entity.isAbsent %}
                            <i class="fa fa-check-square-o"></i>
                        {% else %}
                            <i class="fa fa-square-o"></i>
                        {% endif %}
                    </td>
                    <td>
                        {#
                        {% if entity.civility is not null %}
                            {% if entity.civility.name|length > 0 %}
                                {{ entity.civility.name|first }}
                            {% endif %}
                        {% endif %}
                        #}
                        {{ entity.label }}
                    </td>
                    <td>
                        <ul class="unbullet">
                            <li>
                                <span class="dt">login:</span>
                                {{ entity.username|e('html_attr') }}
                            </li>
                            <li>
                                <span class="dt">email:</span>
                                {{ entity.email }}
                            </li>
                            <li>
                                <span class="dt">métier:</span>
                                {% if entity.userJob %}
                                    {{ entity.userJob.label|localize_translatable_string }}
                                {% endif %}
                            </li>
                            <li>
                                <span class="dt">{{ 'Scope'|trans }}/{{ 'center'|trans }}:</span>
                                {% if entity.mainScope %}
                                    {{ entity.mainScope.name|localize_translatable_string }}
                                {% endif %}
                                {% if entity.mainCenter %}, {{ entity.mainCenter.name }}{% endif %}
                            </li>
                        </ul>
                    </td>
                    <td>
                        <ul class="record_actions">

                            {% if is_granted('ROLE_ALLOWED_TO_SWITCH') %}
                                <li>
                                    <a class="btn btn-chill-blue" href="{{ path('chill_main_homepage', {'_switch_user': entity.username }) }}" title="{{ "Impersonate"|trans|e('html_attr') }}"><i class="fa fa-user-secret"></i></a>
                                </li>
                            {% endif %}

                            <li>
                                <a class="btn btn-edit" title="{{ 'Edit'|trans }}" href="{{ path('chill_crud_admin_user_edit', { 'id': entity.id }) }}"></a>
                            </li>

                            {% if allow_change_password is same as(true) %}
                                <li>
                                    <a class="btn btn-reset" href="{{ path('admin_user_edit_password',  { 'id' : entity.id }) }}" title="{{ 'Edit password'|trans|e('html_attr') }}"><i class="fa fa-key-modern"></i></a>
                                </li>
                            {% endif %}
                        </ul>
                    </td>
                </tr>
            {% endfor %}
        {% endblock %}

        {% block pagination %}{{ chill_pagination(paginator) }}{% endblock %}

        {% block list_actions %}
            <ul class="record_actions sticky-form-buttons">
                <li class='cancel'>
                    <a href="{{ path('chill_main_admin_central') }}" class="btn btn-cancel">{{'Back to the admin'|trans}}</a>
                </li>

                <li>
                    <div class="dropdown">
                        <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-download"></i>
                        </button>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="{{ path('chill_main_users_export_list') }}">{{ 'admin.users.export_list_csv'|trans }}</a></li>
                            <li><a class="dropdown-item" href="{{ path('chill_main_users_export_permissions') }}">{{ 'admin.users.export_permissions_csv'|trans }}</a></li>
                        </ul>
                    </div>
                </li>
                <li>
                    <a href="{{ path('chill_crud_admin_user_new') }}" class="btn btn-create">{{ 'Create'|trans }}</a>
                </li>
            </ul>
        {% endblock list_actions %}

    {% endembed %}
{% endblock %}
