{% 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_popup') }}">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="type">Type</label>
                            <select name="type" id="type" class="form-control">
                                <option value="all" {% if filters.type == 'all' %}selected{% endif %}>Tous</option>
                                <option value="popup" {% if filters.type == 'popup' %}selected{% endif %}>Popup</option>
                                <option value="banner" {% if filters.type == 'banner' %}selected{% endif %}>Bandeau</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="status">Statut</label>
                            <select name="status" id="status" class="form-control">
                                <option value="all" {% if filters.status == 'all' %}selected{% endif %}>Tous</option>
                                <option value="published" {% if filters.status == 'published' %}selected{% endif %}>Publiées</option>
                                <option value="unpublished" {% if filters.status == 'unpublished' %}selected{% endif %}>Dépubliées</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_popup') }}" class="btn btn-default btn-block">Reinitialiser</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            Annonces ({{ items|length }})
            <div class="pull-right">
                <div class="btn-group">
                    <a href="{{ path('admin_popup_new') }}" type="button" class="btn btn-default btn-xs">
                        Ajouter
                    </a>
                </div>
            </div>
        </div>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>#</th>
                <th>Image</th>
                <th>Titre</th>
                <th>Texte</th>
                <th>Affichage</th>
                <th>Statut</th>
                <th>Date de début</th>
                <th>Date de fin</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            {% for item in items %}
                <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>{{ item.text|striptags|slice(0, 100) }}</td>
                    <td>{{ item.popup ? 'Popup' : 'Bandeau' }}</td>
                    <td>
                        {% set status = status_by_id[item.id.toString] %}
                        <i class="fa fa-circle" style="color: {{ status.color }};" data-toggle="tooltip" title="{{ status.label }}"></i>
                    </td>
                    <td>{{ item.publishedAt | date('d-m-Y') }}</td>
                    <td>{{ item.unPublishedAt | date('d-m-Y') }}</td>
                    <td>
                        <a href="{{ path('admin_popup_edit', { id: item.id}) }}" class="btn btn-info btn-xs"
                           data-toggle="tooltip" title="Editer l’annonce {{ item.title }}"><i
                                    class="fas fa-edit fa-2x"></i></a>

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