{% extends "baseadmin.html.twig" %}

{% block body %}
    <table class="table table-stripped">
        <thead>
            <tr>
                <th>
                    Nom
                    <a href="{{ path('admin.formations.sort', {champ:'title', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
                    <a href="{{ path('admin.formations.sort', {champ:'title', ordre:'DESC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
                    <form class="form-inline mt-1" method="POST" action="{{ path('admin.formations.findallcontain', {champ:'title'}) }}">
                        <div class="form-group mr-1 mb-2">
                            <input type="text" class="sm" name="recherche" 
                                   value="{% if valeur|default and not table|default %}{{ valeur }}{% endif %}">
                            <input type="hidden" name="_token" value="{{ csrf_token('filtre_title') }}">
                            <button type="submit" class="btn btn-info mb-2 btn-sm">filtrer</button>
                        </div>
                    </form>  
                </th>
                <th>
                    Playlist
                    <a href="{{ path('admin.formations.sort', {table:'playlist', champ:'name', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
                    <a href="{{ path('admin.formations.sort', {table:'playlist', champ:'name', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
                    <form class="form-inline mt-1" method="POST" action="{{ path('admin.formations.findallcontain', {champ:'name', table:'playlist'}) }}">
                        <div class="form-group mr-1 mb-2">
                            <input type="text" class="sm" name="recherche" 
                                   value="{% if valeur|default and table|default and table=='playlist' %}{{ valeur }}{% endif %}">
                            <input type="hidden" name="_token" value="{{ csrf_token('filtre_name') }}">
                            <button type="submit" class="btn btn-info mb-2 btn-sm">filtrer</button>
                        </div>
                    </form>
                </th>
                <th>
                    Catégories
                    <form class="form-inline mt-1" method="POST" action="{{ path('admin.formations.findallcontain', {champ:'id', table:'categories'}) }}">
                        <select class="form-select form-select-sm" name="recherche" id="recherche" onchange="this.form.submit()">
                            <option value=""></option>
                            {% for categorie in categories %}
                                <option 
                                    {% if valeur|default and valeur==categorie.id %} 
                                        selected
                                    {% endif %} 
                                    value="{{ categorie.id }}">{{ categorie.name }}
                                </option>
                            {% endfor %}
                        </select>                    
                    </form>
                </th>
                <th>
                    Date
                    <a href="{{ path('admin.formations.sort', {champ:'publishedAt', ordre:'ASC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true"><</a>
                    <a href="{{ path('admin.formations.sort', {champ:'publishedAt', ordre:'DESC'}) }}" class="btn btn-info btn-sm active" role="button" aria-pressed="true">></a>
                </th>
                <th>
                    Actions
                </th>
            </tr>
        </thead>
        <tbody>
            {% for formation in formations %}
                <tr>
                    <td>
                        {{ formation.title }}
                    </td>
                    <td>
                        {{ formation.playlist.name }}
                    </td>
                    <td>
                        {% for categorie in formation.categories %}
                            {{ categorie.name }}<br />
                        {% endfor %}
                    </td>
                    <td>
                        {{ formation.publishedatstring }}
                    </td>
                    <td>
                        <a href="{{ path('admin.formations.remove', {'id': formation.id}) }}" class="btn btn-danger" onclick="return confirm('Êtes vous sûr de vouloir supprimer {{ formation.title }} ?')">Supprimer</a>
                        <a href="{{ path('admin.formations.modifier', {'id': formation.id}) }}" class="btn btn-danger">Modifier</a>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    <a href="{{ path('admin.creerFormation')}}" class="btn btn-primary">Ajouter une formation</a>
{% endblock %}