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

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            Pages CMS
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_page_new') }}" type="button" class="btn btn-default btn-xs">
                        Ajouter
                    </a>
                </div>
            </div>
        </div>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>Nom</th>
                <th>Code</th>
                <th>Routes</th>
                <th>Type</th>
                <th>Template</th>
                <th>Publication</th>
                <th>Statut</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            {% for item in items %}
                <tr>
                    <td>{{ item.name }}</td>
                    <td><code>{{ item.code }}</code></td>
                    <td>
                        {% if item.routeMode == constant('CpCreation\\VitiCore\\PageBuilder\\Model\\Page::ROUTE_MODE_SYSTEM') %}
                            <span class="label label-info">{{ item.routeName ?: 'Route non définie' }}</span>
                        {% else %}
                            {% for translation in item.translations %}
                                {% set localePrefix = translation.locale == 'en' ? '/en' : '' %}
                                <div>
                                    <span class="label label-default">{{ translation.locale }}</span>
                                    {% if translation.path is empty %}
                                        <span>{{ localePrefix ?: '/' }}</span>
                                    {% else %}
                                        <span>{{ localePrefix }}/{{ translation.path }}</span>
                                    {% endif %}
                                </div>
                            {% else %}
                                <span class="text-muted">Aucun chemin configuré</span>
                            {% endfor %}
                        {% endif %}
                    </td>
                    <td>{{ item.routeMode == 'system' ? 'Système' : 'CMS' }}</td>
                    <td>{{ item.template }}</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 item.disabled %}
                            <i class="fas fa-circle fa-2x color_red" data-toggle="tooltip" title="Dépubliée 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ée"></i>
                        {% endif %}
                    </td>
                    <td>
                        <a href="{{ path('admin_page_edit', { id: item.id }) }}" class="btn btn-info btn-xs"
                           data-toggle="tooltip" title="Éditer la page {{ item.name }}">
                            <i class="fas fa-edit fa-2x"></i>
                        </a>

                        {% if item.routeMode == constant('CpCreation\\VitiCore\\PageBuilder\\Model\\Page::ROUTE_MODE_CMS') %}
                            <a href="{{ path('admin_page_builder_start', { id: item.id, locale: app.request.locale|default('fr') }) }}" class="btn btn-warning btn-xs"
                               data-toggle="tooltip" title="Ouvrir le builder visuel de la page {{ item.name }}">
                                <i class="fas fa-object-group fa-2x"></i>
                            </a>

                            <a href="{{ path('admin_page_front_edit', { id: item.id, locale: app.request.locale|default('fr') }) }}" class="btn btn-primary btn-xs"
                               data-toggle="tooltip" title="Éditer la page {{ item.name }} directement sur le site">
                                <i class="fas fa-external-link-alt fa-2x"></i>
                            </a>
                        {% endif %}

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

                        {% if item.disabled == false %}
                            <a href="{{ path('admin_page_disable', { id: item.id }) }}"
                               class="btn btn-default btn-xs" data-toggle="tooltip"
                               title="Dépublier la page {{ item.name }}">
                                <i class="fas fa-circle fa-2x color_green"></i>
                            </a>
                        {% else %}
                            <a href="{{ path('admin_page_enable', { id: item.id }) }}"
                               class="btn btn-default btn-xs" data-toggle="tooltip"
                               title="Publier la page {{ item.name }}">
                                <i class="fas fa-circle fa-2x color_red"></i>
                            </a>
                        {% endif %}
                    </td>
                </tr>
            {% else %}
                <tr>
                    <td colspan="8">Aucune page configurée.</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
