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

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            Filtres
        </div>
        <div class="panel-body">
            <form method="get" action="{{ path('admin_depot') }}">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="search">Recherche</label>
                            <input
                                type="text"
                                name="search"
                                id="search"
                                class="form-control"
                                value="{{ filters.search_input }}"
                                placeholder="Nom, adresse, code postal, ville…"
                            >
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="category">Catégorie</label>
                            <select name="category" id="category" class="form-control">
                                <option value="">Toutes</option>
                                <option value="__none__" {% if filters.category_id == '__none__' %}selected{% endif %}>Sans catégorie</option>
                                {% for id, label in filter_options.categories %}
                                    <option value="{{ id }}" {% if filters.category_id == id %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label for="country">Pays</label>
                            <select name="country" id="country" class="form-control">
                                <option value="">Tous</option>
                                {% for code, label in filter_options.countries %}
                                    <option value="{{ code }}" {% if filters.country == code %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="status">Statut</label>
                            <select name="status" id="status" class="form-control">
                                <option value="all" {% if filters.status == 'all' %}selected{% endif %}>Tous</option>
                                <option value="published" {% if filters.status == 'published' %}selected{% endif %}>Publiés</option>
                                <option value="unpublished" {% if filters.status == 'unpublished' %}selected{% endif %}>Dépubliés</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-2">
                        <button type="submit" class="btn btn-primary btn-block">Filtrer</button>
                    </div>
                    <div class="col-md-2">
                        <a href="{{ path('admin_depot') }}" class="btn btn-default btn-block">Réinitialiser</a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            Dépôts ({{ items|length }})
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_depot_new', filters.query_parameters) }}" type="button" class="btn btn-default btn-xs">
                        Ajouter
                    </a>
                </div>
            </div>
        </div>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>#</th>
                <th>Catégorie</th>
                <th>Nom</th>
                <th>Description</th>
                <th>Adresse</th>
                <th>Code Postal</th>
                <th>Ville</th>
                <th>Pays</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            {% for item in items %}
                {% set movePermission = move_permissions[item.id ~ ''] %}
                <tr>
                    <td>{{ item.position is null ? '–' : item.position + 1 }}</td>
                    <td>{% if item.category is not null %}{{ item.category.name }}{% endif %}</td>
                    <td>{{ item.name }}</td>
                    <td>{{ item.description | slice(0,50) }}</td>
                    <td>{{ item.address }}</td>
                    <td>{{ item.postal }}</td>
                    <td>{{ item.city }}</td>
                    <td>{{ item.country }}</td>
                    <td>
                        <a href="{{ path('admin_depot_edit', { id: item.id}|merge(filters.query_parameters)) }}" class="btn btn-info btn-xs"
                           data-title="Editer le dépôt"><i
                                    class="fas fa-edit fa-2x" aria-hidden="true"></i></a>

                        <a href="{{ path('admin_depot_delete', { id: item.id }|merge(filters.query_parameters)) }}"
                           class="confirm-deletable btn btn-danger btn-xs"
                           data-title="Supprimer le dépôt {{ item.name }}"><i class="fa fa-2x fa-trash"
                                                                              aria-hidden="true"></i></a>
                        {% if item.disabled == 0 %}
                            <a href="{{ path('admin_depot_disable', { id: item.id }|merge(filters.query_parameters)) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip"
                               title="Dépublier le dépôt {{ item.name }}"><i
                                        class="fas fa-circle fa-2x color_green"></i></a>
                        {% else %}
                            <a href="{{ path('admin_depot_enable', { id: item.id }|merge(filters.query_parameters)) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip"
                               title="Publier le dépôt {{ item.name }}"><i class="fas fa-circle fa-2x color_red"></i></a>
                        {% endif %}

                        {% if movePermission.up %}
                            <a href="{{ path('admin_depot_move_up', {id : item.id}|merge(filters.query_parameters)) }}"
                               class="btn btn-default btn-xs" data-toggle="tooltip" title="Remonter le dépôt"><i
                                        class="fa fa-2x fa-arrow-up" aria-hidden="true"></i></a>
                        {% endif %}
                        {% if movePermission.down %}
                            <a href="{{ path('admin_depot_move_down', {id : item.id}|merge(filters.query_parameters)) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip" title="Descendre le dépôt"><i
                                        class="fa fa-2x fa-arrow-down" aria-hidden="true"></i></a>
                        {% endif %}

                    </td>
                </tr>
            {% endfor %}

            {% if items is empty %}
                <tr>
                    <td colspan="9" class="text-center">Aucun dépôt ne correspond aux filtres.</td>
                </tr>
            {% endif %}

            </tbody>
        </table>
    </div>
{% endblock %}
