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

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            Collections
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_product_collection_new') }}" type="button" class="btn btn-default btn-xs">
                        Ajouter
                    </a>
                </div>
            </div>
        </div>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>#</th>
                <th>Nom</th>
                <th>Code</th>
                <th>Mode</th>
                <th>Conditions</th>
                <th>Produits</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            {% for item in items %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td>{{ item.name }}</td>
                    <td><code>{{ item.code }}</code></td>
                    <td>
                        {% if item.automatic %}
                            <span class="label label-info">Automatique</span>
                        {% else %}
                            <span class="label label-default">Manuel</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if item.automatic %}
                            {% if item.automaticCategory %}
                                <span class="label label-default">{{ item.automaticCategory.name }}</span>
                            {% endif %}
                            {% if item.automaticOnlyCuvee %}
                                <span class="label label-default">Cuvées</span>
                            {% endif %}
                            {% if item.automaticOnlyNew %}
                                <span class="label label-default">Nouveautés</span>
                            {% endif %}
                            {% if item.automaticExcludeSoldOut %}
                                <span class="label label-default">Sans rupture</span>
                            {% endif %}
                            {% if item.automaticLimit %}
                                <span class="label label-default">Limite {{ item.automaticLimit }}</span>
                            {% endif %}
                        {% else %}
                            -
                        {% endif %}
                    </td>
                    <td>
                        {% if item.manual %}
                            {% for collectionItem in item.items %}
                                {% if collectionItem.product %}
                                    <span class="label label-default">{{ collectionItem.product.fullName }}</span>
                                {% endif %}
                            {% else %}
                                -
                            {% endfor %}
                        {% else %}
                            Généré automatiquement
                        {% endif %}
                    </td>
                    <td>
                        <a href="{{ path('admin_product_collection_edit', {id: item.id}) }}" class="btn btn-info btn-xs"
                           data-toggle="tooltip" title="Editer la collection"><i class="fas fa-edit fa-2x"></i></a>

                        <a href="{{ path('admin_product_collection_delete', {id: item.id}) }}"
                           class="confirm-deletable btn btn-danger btn-xs"
                           data-toggle="tooltip" title="Supprimer la collection {{ item.name }}" data-title="Supprimer la collection {{ item.name }}">
                            <i class="fa fa-2x fa-trash"></i></a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
