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

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

{% block main %}

    {% if not entete is null and not entete.texte==''%}
        <div class="col-xs-12 p-0">
            <div class="bloc-base p-16">
                {{ entete.texte|raw }}
            </div>
        </div>
    {% endif %}

{% if user.isAdmin==1 %}

<div class="bloc-title mb-16">
    <h2 class="align-middle">Liste des utilisateurs</h2>
</div>
<div class="row m-0">
    <div class="col-xs-12 p-16 background-white">
        <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">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 u in users %}
                        <tr>
                            <td class="plr-8 ptb-24">{{ u.nom }}</td>
                            <td class="plr-8 ptb-24">{{ u.prenom }}</td>
                            <td class="plr-8 ptb-24">{{ u.email }}</td>
                            <td class="plr-8 ptb-24">{{ u.telephone }}</td>

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

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

                                {% if is_granted('ROLE_PREVIOUS_ADMIN') %}
                            <td class="plr-8 ptb-24 dtb-action">
                                {% if u.id != app.user.id %}
                                    {% if u.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 %}
                                    <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation"><i class="fas fa-search" style="color: white" ></i></a>

                                {% 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 u.id != app.user.id %}
                                        {% if u.isActif == 1 %}
                                            <a  href="{{ path('user_deactivate', { userId: u.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: u.id}) }}" class="button-rond-xs align-middle bg-success" title="Activer"><i class="fas fa-toggle-on"></i></a>
                                        {% endif %}
                                        <a href="{{ path('switch_user', {'u': u.username}) }}" class="button-rond-xs align-middle" title="Consulter">
                                            <i class="fas fa-search"></i>
                                        </a>
                                    {% endif %}
                                    <a  href="{{ path('user_admin_update', { 'user': u.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>

{% else %}

    <div align="left">
        <form  id="inter" name="interlocuteurSiret" action="" method="post">
            Filtrer les utilisateurs en fonction de l'interlocuteur
            <input type="text" id="siret" name="siret" placeholder="siret de l'interlocuteur">
            <button type="submit" value="inter" class="button-square">Valider</button>
            {#<a class="button-square bg-orange" href="{{ path('users_list') }}">Tous les utilisateurs</a>#}
        </form>
    </div>

<div class="bloc-title mb-16">
    <h2 class="align-middle">Liste des utilisateurs</h2>
</div>
<div class="row m-0">
    <div class="col-xs-12 p-16 background-white">
        <div class="table-responsive">
            <table id="myTable" class="display">
                <thead class="background-orange">
                <tr>
                    <th class="plr-8 ptb-16">Interlocuteurs et communes</th>
                    <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">Consultation</th>
                </tr>
                </thead>
                <tbody>
                {% for u in users %}
                <tr>
                    <td class="plr-8 ptb-24">
                    {% for i in u.interlocuteurSiret %}
                       n°siret: {{ i.siret }}, commune : {{ i.commune }}<br/>
                    {% endfor %}
                    </td>
                    <td class="plr-8 ptb-24">{{ u.nom }}</td>
                    <td class="plr-8 ptb-24">{{ u.prenom }}</td>
                    <td class="plr-8 ptb-24">{{ u.email }}</td>

                    {% if is_granted('ROLE_PREVIOUS_ADMIN') %}
                        <td class="plr-8 ptb-24 dtb-action">
                            {% if u.id != app.user.id %}
                                <a class="button-rond-xs align-middle" style="background-color: gray" title="Non accessible en consultation">
                                    <i class="fas fa-search" style="color: white" ></i>
                                </a>
                            {% endif %}
                        </td>
                    {% else %}
                        <td class="plr-8 ptb-24 dtb-action">
                            {% if u.id != app.user.id and not u.isAdmin%}
                                <a href="{{ path('switch_user', {'u': u.username}) }}" class="button-rond-xs align-middle" title="Consulter">
                                    <i class="fas fa-search"></i>
                                </a>
                            {% elseif u.id == app.user.id %}
                                <a  class="button-rond-xs align-middle" title="Vous ne pouvez pas vous consulter vous-même" style="background-color: gray">
                                    <i class="fas fa-search" style="color: white"></i>
                                </a>

                            {% else %}
                                <a  class="button-rond-xs align-middle" title="Vous ne pouvez pas consulter un admin en étant agent" style="background-color: gray">
                                    <i class="fas fa-search" style="color: white"></i>
                                </a>
                            {% endif %}

                                </td>
                    {% endif %}

                    {% endfor %}
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

{% endif %}

{% endblock %}
