{% extends 'admin/base_admin.html.twig' %}

{% block contentHeader %}
    <h1>
        Utilisateurs
        <small>Liste</small>
    </h1>
    <ol class="breadcrumb">
        <li>
            <a href="{{ path('admin_dashboard') }}">
                <i class="fa fa-dashboard"></i>
                Dashboard</a>
        </li>
        <li>Secret</li>
        <li class="active">Utilisateurs</li>
    </ol>
{% endblock %}

{% block content %}

    <div class="box box-primary">
        <div class="box-body">
            <table id="user_list_table" class="table table-hover table-bordered">
                <thead>
                    <tr>
                        <th class="col-md-2">Nom</th>
                        <th class="col-md-2">Prénom</th>
                        <th class="col-md-3">Email</th>
                        <th class="col-md-1">Rôle</th>
                        <th class="col-md-3">Etat</th>
                        <th class="col-md-1">Action</th>
                    </tr>
                </thead>

                <tbody>
                    {% for u in users %}
                        <tr>
                            <td>{{ u.lastname }}</td>
                            <td>{{ u.firstname }}</td>
                            <td>{{ u.email }}</td>
                            <td>
                                {% for r in u.roles %}
                                    {% if r != "ROLE_USER" and r == "ROLE_TALENT" %}
                                        <span class="badge bg-blue" style="font-weight: 400;">{{ r }}</span>
                                    {% elseif r != "ROLE_USER" and r == "ROLE_COMPANY" %}
                                        <span class="badge bg-orange" style="font-weight: 400;">{{ r }}</span>
                                    
                                    {% endif %}
                                {% endfor %}
                            </td>
                            <td>
                                {% if u.enabled %}
                                    Activé
                                {% else %}
                                    Désactivé
                                    <br/>
                                    <a href="{{ path('admin_user_resend',{'id':u.id}) }}">Renvoyer le mail de confirmation</a>
                                {% endif %}
                            </td>

                            <td>
                                <a class="delete-user" href="{{ path('admin_user_delete',{'id':u.id}) }}" data-toggle="tooltip" title="Supprimer">
                                    <i class="fa fa-trash"></i>
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

{% endblock %}

{% block javascripts %}
    <script>
        $(function () {
            $('#user_list_table').DataTable({
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": false,
                "language": {
                    "url": "https://cdn.datatables.net/plug-ins/1.10.11/i18n/French.json"
                },
                "columnDefs": [
                    {
                        "targets": 0,
                        "searchable": true,
                        "orderable": true
                    }, {
                        "targets": 1,
                        "searchable": true,
                        "orderable": true
                    }, {
                        "targets": 2,
                        "searchable": true,
                        "orderable": true
                    }, {
                        "targets": 3,
                        "searchable": true,
                        "orderable": true,
                        "className": "text-center"
                    }, {
                        "targets": 4,
                        "searchable": false,
                        "orderable": false,
                        "className": "text-center"
                    }, {
                        "targets": 5,
                        "searchable": false,
                        "orderable": false,
                        "className": "text-center"
                    }
                ]
            });
        });

        $(document).ready(function () {
            $('[data-toggle="popover"]').popover();

            $(".delete-user").confirm({
                title: "Êtes vous sûr de supprimer cet utilisateur ?",
                content: "Supprimer cet utilisateur supprimera, son compte, son entreprise, ses réponses, médias",
                type: 'red',
                boxWidth: '30%',
                useBootstrap: false,
                buttons: {
                    confirm: {
                        text: 'Confirmer',
                        action: function () {
                            console.log(this.$target);
                            location.href = this.$target.attr('href');
                            return true;
                        }
                    },
                    cancel: {
                        text: 'Annuler'
                    }
                }
            });
        });
    </script>

{% endblock %}