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

{% block content %}
    {% set zones = [
        {
            key: constant('CpCreation\\VitiCore\\Shop\\Model\\InformationBlock::ZONE_TOP'),
            label: 'Haut de boutique'
        },
        {
            key: constant('CpCreation\\VitiCore\\Shop\\Model\\InformationBlock::ZONE_BOTTOM'),
            label: 'Bas de boutique'
        }
    ] %}

    {% for zone in zones %}
        {% set zoneItems = items|filter(item => item.displayZone == zone.key) %}
        <div class="panel panel-default">
            <div class="panel-heading">
                Blocs d’information boutique : {{ zone.label }}
                {% if loop.first %}
                    <div class="pull-right">
                        <div class="btn-group">
                            <a href="{{ path('admin_shop_information_block_new') }}" type="button" class="btn btn-default btn-xs">
                                Ajouter
                            </a>
                        </div>
                    </div>
                {% endif %}
            </div>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Icône</th>
                    <th>Titre</th>
                    <th>Groupes</th>
                    <th>Type de bouton</th>
                    <th>Publication</th>
                    <th>Ordre</th>
                    <th>Statut</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                {% for item in zoneItems %}
                    <tr>
                        <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.title }}</td>
                        <td>
                            {% if item.groups|length > 0 %}
                                {% for group in item.groups %}
                                    <span class="label label-default">{{ group.name }}</span>
                                {% endfor %}
                            {% else %}
                                <span class="text-muted">Tous</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if item.actionType == constant('CpCreation\\VitiCore\\Shop\\Model\\InformationBlock::ACTION_MODAL') %}
                                Modale
                                {% if item.modalTemplate == constant('CpCreation\\VitiCore\\Shop\\Model\\InformationBlock::MODAL_TEMPLATE_SHIPPING_FEES') %}
                                    <br><small>Frais de port disponibles</small>
                                {% endif %}
                            {% elseif item.actionType == constant('CpCreation\\VitiCore\\Shop\\Model\\InformationBlock::ACTION_LINK') %}
                                Lien
                            {% else %}
                                Aucun
                            {% endif %}
                        </td>
                        <td>
                            <small>
                                Pub.: {{ item.publishedAt ? item.publishedAt|date('d/m/Y H:i') : 'Immédiate' }}<br>
                                Dépub.: {{ item.unPublishedAt ? item.unPublishedAt|date('d/m/Y H:i') : 'Aucune' }}
                            </small>
                        </td>
                        <td>
                            {% if loop.first == false %}
                                <a href="{{ path('admin_shop_information_block_move_up', {id : item.id}) }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip" title="Remonter le bloc"><i
                                            class="fa fa-2x fa-arrow-up" aria-hidden="true"></i></a>
                            {% endif %}
                            {% if loop.last == false %}
                                <a href="{{ path('admin_shop_information_block_move_down', {id : item.id}) }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip" title="Descendre le bloc"><i
                                            class="fa fa-2x fa-arrow-down" aria-hidden="true"></i></a>
                            {% endif %}
                        </td>
                        <td>
                            {% if item.disabled %}
                                <i class="fas fa-circle fa-2x color_red" data-toggle="tooltip" title="Dépublié manuellement"></i>
                            {% elseif item.publishedAt and item.publishedAt > date() %}
                                <i class="fas fa-circle fa-2x color_orange" data-toggle="tooltip" title="Programmée"></i>
                            {% elseif item.unPublishedAt and item.unPublishedAt < date() %}
                                <i class="fas fa-circle fa-2x color_red" data-toggle="tooltip" title="Dépubliée automatiquement"></i>
                            {% else %}
                                <i class="fas fa-circle fa-2x color_green" data-toggle="tooltip" title="Publié"></i>
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ path('admin_shop_information_block_edit', { id: item.id}) }}" class="btn btn-info btn-xs"
                               data-toggle="tooltip" title="Éditer le bloc {{ item.title }}"><i
                                        class="fas fa-edit fa-2x"></i></a>

                            <a href="{{ path('admin_shop_information_block_delete', { id: item.id }) }}"
                               class="confirm-deletable btn btn-danger btn-xs"
                               data-toggle="tooltip" title="Supprimer le bloc {{ item.title }}"
                               data-title="Supprimer le bloc {{ item.title }}">
                                <i class="fa fa-2x fa-trash"></i></a>

                            {% if item.disabled == false %}
                                <a href="{{ path('admin_shop_information_block_disable', { id: item.id }) }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip"
                                   title="Dépublier le bloc {{ item.title }}"><i
                                            class="fas fa-circle fa-2x color_green"></i></a>
                            {% else %}
                                <a href="{{ path('admin_shop_information_block_enable', { id: item.id }) }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip"
                                   title="Publier le bloc {{ item.title }}"><i class="fas fa-circle fa-2x color_red"></i></a>
                            {% endif %}
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="9">Aucun bloc configuré pour cette zone.</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endfor %}
{% endblock %}
