{% 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_shipping_price') }}">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="group_id">Groupe</label>
                            <select name="group_id" id="group_id" class="form-control">
                                <option value="">Tous</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="carrier">Transporteur</label>
                            <select name="carrier" id="carrier" class="form-control">
                                <option value="">Tous</option>
                                {% for carrier, label in filter_options.carriers %}
                                    <option value="{{ carrier }}" {% if filters.carrier == carrier %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="type_id">Type</label>
                            <select name="type_id" id="type_id" class="form-control">
                                <option value="">Tous</option>
                                {% for id, label in filter_options.types %}
                                    <option value="{{ id }}" {% if filters.type_id == id %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="zone_id">Zone</label>
                            <select name="zone_id" id="zone_id" class="form-control">
                                <option value="">Toutes</option>
                                {% for id, label in filter_options.zones %}
                                    <option value="{{ id }}" {% if filters.zone_id == id %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="delivery_method_id">Méthode de livraison</label>
                            <select name="delivery_method_id" id="delivery_method_id" class="form-control">
                                <option value="">Toutes</option>
                                <option value="__none__" {% if filters.delivery_method_id == '__none__' %}selected{% endif %}>Sans méthode spécifique</option>
                                {% for id, label in filter_options.delivery_methods %}
                                    <option value="{{ id }}" {% if filters.delivery_method_id == id %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <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_shipping_price') }}" class="btn btn-default btn-block">Reinitialiser</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            Zones pour frais de port ({{ items|length }})
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_shipping_price_new', filters.query_parameters) }}" type="button" class="btn btn-default btn-xs">
                        Ajouter
                    </a>
                </div>
            </div>
        </div>
        <table class="table table-bordered dataTable" width="100%" cellspacing="0">
            <thead>
            <tr>
                <th>#</th>
                <th>De</th>
                <th>A</th>
                <th>Type</th>
                <th>Transporteur</th>
                <th>Groupes</th>
                <th>Méthode de livraison</th>
                <th>Forfait</th>
                <th>Par bouteille</th>
                <th>Marge Globale</th>
                <th>Zone(s)</th>
                <th>Action</th>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <th>#</th>
                <th>De</th>
                <th>A</th>
                <th>Type</th>
                <th>Transporteur</th>
                <th>Groupes</th>
                <th>Méthode de livraison</th>
                <th>Forfait</th>
                <th>Par bouteille</th>
                <th>Marge Globale</th>
                <th>Zone(s)</th>
                <th>Action</th>
            </tr>
            </tfoot>
            <tbody>

            {% for item in items %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td>{{ item.qtyOf }}</td>
                    <td>{{ item.qtyAt }}</td>
                    <td>
                        {% for type in item.types %}
                            <span class="label label-default">{{ type.name }} {% if type.info %}({{ type.info}}){% endif %}</span>
                        {% endfor %}
                    </td>
                    <td>{{ item.nameCarrier }}</td>
                    <td>
                        {% for group in item.groups %}
                            <span class="label label-default">{{ group.name }}</span>
                        {% endfor %}
                    </td>
                    <td>
                        {% if item.deliveryMethod is not null %}
                            <span class="label label-default">{{ item.deliveryMethod.name }}</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if item.packagePrice is not null %}
                            {{ item.packagePrice / 100 }} €
                        {% endif %}
                    </td>
                    <td>
                        {% if item.bottlePrice is not null %}
                            {{ item.bottlePrice / 100 }} €
                        {% endif %}
                    </td>
                    <td>
                        {% if item.configGlobal %}
                            Oui
                        {% endif %}
                    </td>
                    <td>
                        {% for zone in item.zones %}
                            <span class="label label-default">{{ zone.name }}</span>
                        {% endfor %}
                    </td>
                    <td>
                        <a href="{{ path('admin_shipping_price_edit', {'id': item.id}|merge(filters.query_parameters)) }}" class="btn btn-info btn-xs"
                           data-toggle="tooltip" title="Editer le prix"><i class="fas fa-edit fa-2x"></i></a>
                        {% if is_granted('ROLE_ADMIN') %}
                        <a href="{{ path('admin_shipping_price_delete', {'id': item.id}|merge(filters.query_parameters)) }}"
                           class="confirm-deletable btn btn-danger btn-xs"
                           data-toggle="tooltip" title="Supprimer le prix"
                           data-title="Supprimer le prix">
                            <i class="fa fa-2x fa-trash"></i></a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
