{% extends '@CpCreationVitiCore/admin/base.html.twig' %}

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            Filtres
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_client_new') }}" type="button" class="btn btn-default btn-xs">
                        Ajouter un client
                    </a>
                </div>
            </div>
        </div>
        <div class="panel-body">
            <form method="get" action="{{ path('admin_client') }}">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="group_id">Groupe partenaire</label>
                            <select name="group_id" id="group_id" class="form-control">
                                <option value="">Selectionner</option>
                                {% for id, label in filter_options.groups %}
                                    <option value="{{ id }}" {% if filters.group_id == id %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="marketing_opt_in">Option marketing</label>
                            <select name="marketing_opt_in" id="marketing_opt_in" class="form-control">
                                <option value="">Selectionner</option>
                                {% for value, label in filter_options.marketing_choices %}
                                    <option value="{{ value }}" {% if filters.marketing_opt_in_input == value %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="has_orders">Commande deja realisee</label>
                            <select name="has_orders" id="has_orders" class="form-control">
                                <option value="">Selectionner</option>
                                {% for value, label in filter_options.order_choices %}
                                    <option value="{{ value }}" {% if filters.has_orders_input == value %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="is_verified">Compte vérifié</label>
                            <select name="is_verified" id="is_verified" class="form-control">
                                <option value="">Selectionner</option>
                                {% for value, label in filter_options.verification_choices %}
                                    <option value="{{ value }}" {% if filters.is_verified_input == value %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2">
                        <label>&nbsp;</label>
                        <div>
                            <button type="submit" class="btn btn-primary btn-block">Filtrer</button>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <label>&nbsp;</label>
                        <div>
                            <a href="{{ path('admin_client') }}" class="btn btn-default btn-block">Reinitialiser</a>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <label>&nbsp;</label>
                        <div>
                            <a href="{{ path('admin_client_export_excel', filters.query_parameters) }}" class="btn btn-default btn-block">Export Excel</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            Clients ({{ items|length }})
        </div>
        <div class="table-responsive">
            <table class="table table-bordered dataTable" width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Identifiant</th>
                    <th>Email</th>
                    <th>Compte vérifié</th>
                    <th>Groupe partenaire</th>
                    <th>Marketing</th>
                    <th>A deja commande</th>
                    <th>Actions</th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th>#</th>
                    <th>Identifiant</th>
                    <th>Email</th>
                    <th>Compte vérifié</th>
                    <th>Groupe partenaire</th>
                    <th>Marketing</th>
                    <th>A deja commande</th>
                    <th>Actions</th>
                </tr>
                </tfoot>
                <tbody>
                {% for item in items %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ item.username }}</td>
                        <td>{{ item.email }}</td>
                        <td>
                            {% if item.verified %}
                                <span class="label label-success">Oui</span>
                            {% else %}
                                <span class="label label-default">Non</span>
                            {% endif %}
                        </td>
                        <td>{{ item.group ? item.group.name : '-' }}</td>
                        <td>
                            {% if item.marketingOptIn %}
                                <span class="label label-success">Oui</span>
                            {% else %}
                                <span class="label label-default">Non</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if users_with_orders[item.id.toString]|default(false) %}
                                <span class="label label-success">Oui</span>
                            {% else %}
                                <span class="label label-default">Non</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if not item.verified %}
                                <form method="post" action="{{ path('admin_client_verify', { id: item.id }) }}" style="display: inline-block; margin-right: 6px;">
                                    <input type="hidden" name="_token" value="{{ csrf_token('verify-client-' ~ item.id) }}">
                                    <button type="submit" class="btn btn-success btn-sm">
                                        <i class="fas fa-check"></i> Vérifier
                                    </button>
                                </form>
                            {% endif %}
                            <a href="{{ path('admin_client_show', { id: item.id }) }}" class="btn btn-info btn-sm">
                                <i class="fas fa-search"></i> Détails
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
