{% 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_product') }}">
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="product-filter-category">Catégorie</label>
                            <select id="product-filter-category" name="category" class="form-control">
                                <option value="">Toutes</option>
                                {% for category in categories %}
                                    <option value="{{ category.id }}" {% if filters.category == (category.id ~ '') %}selected{% endif %}>
                                        {{ category.name }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="product-filter-variant">Variant</label>
                            <select id="product-filter-variant" name="variant" class="form-control">
                                <option value="">Tous</option>
                                {% for variant in variants %}
                                    <option value="{{ variant.id }}" {% if filters.variant == (variant.id ~ '') %}selected{% endif %}>
                                        {{ variant.name }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="product-filter-group">Groupe</label>
                            <select id="product-filter-group" name="group" class="form-control">
                                <option value="">Tous</option>
                                {% for group in groups %}
                                    <option value="{{ group.id }}" {% if filters.group == (group.id ~ '') %}selected{% endif %}>
                                        {{ group.name }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="product-filter-cuvee">Cuvées</label>
                            <select id="product-filter-cuvee" name="cuvee" class="form-control">
                                <option value="">Tous</option>
                                <option value="1" {% if filters.cuvee is same as(true) %}selected{% endif %}>Présent</option>
                                <option value="0" {% if filters.cuvee is same as(false) %}selected{% endif %}>Absent</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="product-filter-shop">Shop</label>
                            <select id="product-filter-shop" name="shop" class="form-control">
                                <option value="">Tous</option>
                                <option value="1" {% if filters.shop is same as(true) %}selected{% endif %}>Présent</option>
                                <option value="0" {% if filters.shop is same as(false) %}selected{% endif %}>Absent</option>
                            </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_product') }}" class="btn btn-default btn-block">Reinitialiser</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            Produits ({{ items|length }})
            {% if is_granted('ROLE_ADMIN') %}
                <div class="pull-right">
                    <div class="btn-group">
                        <a href="{{ path('admin_product_init_position_shop', filterQuery) }}" type="button" class="btn btn-default btn-xs btn-warning">
                            Réinitialiser position Shop
                        </a>
                        <a href="{{ path('admin_product_init_position', filterQuery) }}" type="button" class="btn btn-default btn-xs btn-warning">
                            Réinitialiser position Cuvées
                        </a>
                        <a href="{{ path('admin_product_new', filterQuery) }}" type="button" class="btn btn-default btn-xs">
                            Ajouter
                        </a>
                    </div>
                </div>
            {% endif %}
        </div>
        <table class="table table-bordered dataTable" width="100%" cellspacing="0">
            <thead>
            <tr>
                <th>#</th>
                <th></th>
                <th>Nom</th>
                <th>Qualité</th>
                <th>Catégorie</th>
                <th>Cuvées</th>
                <th>Shop</th>
                <th>Groupes</th>
                <th>Variant</th>
                <th>Position Cuvées</th>
                <th>Position Shop</th>
                <th>Action</th>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <th>#</th>
                <th></th>
                <th>Nom</th>
                <th>Qualité</th>
                <th>Catégorie</th>
                <th>Cuvées</th>
                <th>Shop</th>
                <th>Groupes</th>
                <th>Variant</th>
                <th>Position Cuvées</th>
                <th>Position Shop</th>
                <th>Action</th>
            </tr>
            </tfoot>
            <tbody>

            {% for item in items %}
                <tr {% if item.disabled == 1 %} class="danger" {% endif %}>
                    <td>{{ loop.index }}</td>
                    <td> {% if item.image is not null %}
                            <img src="{{ asset(item.image.path) | imagine_filter('relative_widen_20_filter') }}"/>
                        {% endif %}
                    </td>
                    <td>{{ item.name ? item.name|upper : '-' }}</td>
                    <td> {% if item.quality %}{{ item.quality }}{% endif %}</td>
                    <td>
                        {% if item.category %}
                            {{ item.category.name }}
                        {% endif %}
                    </td>
                    <td>
                        {% if item.cuvee %}
                            <i class="fas fa-circle fa-2x color_green"></i>
                        {% else %}
                            <i class="fas fa-circle fa-2x color_red"></i>
                        {% endif %}
                    </td>
                    <td>
                        {% if item.shop %}
                            <i class="fas fa-circle fa-2x color_green"></i>
                        {% else %}
                            <i class="fas fa-circle fa-2x color_red"></i>
                        {% endif %}
                    </td>
                    <td>
                        {% for group in item.groups %}
                            <span class="label label-default">{{ group.name }}</span>
                        {% endfor %}
                    </td>
                    <td>
                        <ul class="list-unstyled">
                            {% for variant in item.variants %}
                                {% if variant.unPublished %}
                                    <li><s>{{ variant.type.name }}</s></li>
                                {% else %}
                                    <li>{{ variant.type.name }} {% if variant.type.info %}({{ variant.type.info }}){% endif %}</li>
                                {% endif %}
                            {% endfor %}
                        </ul>
                    </td>
                    <td>
                        {{ item.position}}
                        {% if item.position is not null and item.position > 0 %}
                            <a href="{{ path('admin_product_move_up', ({id : item.id}|merge(filterQuery))) }}"
                               class="btn btn-default btn-xs" data-toggle="tooltip" title="Remonter le produit"><i
                                        class="fa fa-2x fa-arrow-up" aria-hidden="true"></i></a>
                        {% endif %}
                        {% if item.position is not null and (maxPosition is null or item.position < maxPosition) %}
                            <a href="{{ path('admin_product_move_down', ({id : item.id}|merge(filterQuery))) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip" title="Descendre le produit"><i
                                        class="fa fa-2x fa-arrow-down" aria-hidden="true"></i></a>
                        {% endif %}
                    </td>
                    <td>
                       {{ item.positionShop}}
                            {% if item.positionShop is not null and item.positionShop > 0 %}
                                <a href="{{ path('admin_product_move_up_shop', ({id : item.id}|merge(filterQuery))) }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip" title="Remonter le produit"><i
                                            class="fa fa-2x fa-arrow-up" aria-hidden="true"></i></a>
                            {% endif %}

                            {% if item.positionShop is not null and (maxPositionShop is null or item.positionShop < maxPositionShop) %}
                                <a href="{{ path('admin_product_move_down_shop', ({id : item.id}|merge(filterQuery))) }}"
                                   class=" btn btn-default btn-xs" data-toggle="tooltip" title="Descendre le produit"><i
                                            class="fa fa-2x fa-arrow-down" aria-hidden="true"></i></a>
                            {% endif %}

                    </td>
                    <td>
                        <a href="{{ path('admin_product_edit', ({ id: item.id }|merge(filterQuery))) }}" class="btn btn-info btn-xs"
                           data-toggle="tooltip" title="Editer le produit"><i class="fas fa-edit fa-2x"></i></a>
                        {% if is_granted('ROLE_ADMIN') %}
                            <a href="{{ path('admin_product_delete', ({ id: item.id }|merge(filterQuery))) }}"
                               class="confirm-deletable btn btn-danger btn-xs"
                               data-toggle="tooltip" title="Supprimer le produit {{ item.name ? item.name|upper : '-' }}"
                               data-title="Supprimer le produit {{ item.name ? item.name|upper : '-' }}">
                                <i class="fa fa-2x fa-trash"></i></a>
                        {% endif %}
                        {% if item.disabled == 0 %}
                            <a href="{{ path('admin_product_disable', ({ id: item.id }|merge(filterQuery))) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip"
                               title="Dépublier le produit {{ item.name ? item.name|upper : '-' }}"><i
                                        class="fas fa-circle fa-2x color_green"></i></a>
                        {% else %}
                            <a href="{{ path('admin_product_enable', ({ id: item.id }|merge(filterQuery))) }}"
                               class=" btn btn-default btn-xs" data-toggle="tooltip"
                               title="Publier le produit {{ item.name ? item.name|upper : '-' }}"><i class="fas fa-circle fa-2x color_red"></i></a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
