{% extends "/admin/menu_left_admin.html.twig" %}

{% block title %}Liste des agents{% endblock %}


{% block main %}

<div class="bloc-title mb-16">
    <h2 class="align-middle">Liste des agents</h2>
</div>
<div class="row m-0">
    <div class="col-xs-12 p-16 background-white">
        {% if is_granted('ROLE_PREVIOUS_ADMIN') %}
            <a  class="button-rond-md align-middle position-absolute z-3 top-back16 right-16" style="background-color: gray" title="Non accessible en consultation"><i class="fas fa-plus" style="color: white"></i></a>
        {% else %}
            <a  href="{{ path('new_agent') }}" class="button-rond-md align-middle position-absolute z-3 top-back16 right-16" ><i class="fas fa-plus"></i></a>
        {% endif %}
        <div class="table-responsive">
            <table id="myTable" class="display">
                <thead class="background-orange">
                    <tr>
                        <th class="plr-8 ptb-16">Nom</th>
                        <th class="plr-8 ptb-16">Prénom</th>
                        <th class="plr-8 ptb-16">Adresse email</th>
                        <th class="plr-8 ptb-16">Téléphone</th>
                        <th class="plr-8 ptb-16">Agence</th>
                        <th class="plr-8 ptb-16">Date de création</th>
                        <th class="plr-8 ptb-16">Date de mise à jour</th>
                        <th class="plr-8 ptb-16">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for agent in agents %}
                    <tr>
                        <td class="plr-8 ptb-24">{{ agent.nom }}</td>
                        <td class="plr-8 ptb-24">{{ agent.prenom }}</td>
                        <td class="plr-8 ptb-24">{{ agent.email }}</td>
                        <td class="plr-8 ptb-24">{{ agent.telephone }}</td>
                        <td class="plr-8 ptb-24">
                            {% for agence in agent.agences %}
                                {{ agence.libelle }}, Code : {{ agence.codeAgence }}<br/>
                            {% endfor %}</td>

                        {% if '30/11/-0001' not in agent.dateCreation|date('d/m/Y') and agent.dateCreation is not null %}
                            <td class="plr-8 ptb-24">{{agent.dateCreation ? agent.dateCreation|date('d/m/Y') }}</td>
                        {% else %}
                            <td class="plr-8 ptb-24"></td>
                        {% endif %}

                        {% if '30/11/-0001' not in agent.dateModification|date('d/m/Y') and agent.dateModification is not null %}
                            <td class="plr-8 ptb-24">{{agent.dateModification ? agent.dateModification|date('d/m/Y') }}</td>
                        {% else %}
                            <td class="plr-8 ptb-24"></td>
                        {% endif %}

                        {% if is_granted('ROLE_PREVIOUS_ADMIN') %}
                            <td class="plr-8 ptb-24 dtb-action">
                                {% if agent.id != user.id %}
                                    {% if agent.isActif == 1 %}
                                        <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"> <i class="fas fa-toggle-off" style="color: white" ></i></a>
                                    {% else %}
                                        <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"> <i class="fas fa-toggle-on" style="color: white" ></i></a>
                                    {% endif %}

                                    {% if agent.isAdmin == 0 %}
                                        <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"> <i class="fas fa-arrow-up" style="color: white" ></i></a>
                                    {% else %}
                                        <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"> <i class="fas fa-arrow-down" style="color: white" ></i></a>
                                    {% endif %}
                                {% endif %}

                                <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"> <i class="fas fa-edit" style="color: white" ></i></a>
                            </td>

                        {% else %}
                        <td class="plr-8 ptb-24 dtb-action">
                            {% if agent.id != user.id %}
                                {% if agent.isActif == 1 %}
                                    <a href="{{ path('user_deactivate', { userId: agent.id}) }}" class="button-rond-xs align-middle bg-error" title="Désactiver"><i class="fas fa-toggle-off"></i></a>
                                {% else %}
                                    <a href="{{ path('user_activate', { userId: agent.id}) }}" class="button-rond-xs align-middle bg-success" title="Activer"><i class="fas fa-toggle-on"></i></a>
                                {% endif %}

                                {% if agent.isAdmin == 0 %}
                                    <a  href="{{ path('user_promoteAdmin', { userId: agent.id}) }}" class="button-rond-xs align-middle" title="Donner droits admin"><i class="fas fa-arrow-up"></i></a>
                                {% else %}
                                    <a  href="{{ path('user_demoteAdmin', { userId: agent.id}) }}" class="button-rond-xs align-middle" title="Retirer droits admin"><i class="fas fa-arrow-down"></i></a>
                                {% endif %}
                            {% endif %}

                            <a  href="{{ path('update_agent', {agentID: agent.id}) }}" class="button-rond-xs align-middle" title="Modifier"><i class="fas fa-edit"></i></a>
                        </td>
                            {% endif %}
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% endblock %}