{% extends 'Admin/layout.html.twig' %}

{% trans_default_domain 'form' %}

{% set constUserTypeProf = constant('AppBundle\\Enum\\UserType::TEACHER') %}

{% block body %}
    {# Formulaire de recherche #}
    <form action="{{ path('admin_demande_pee_liste') }}" class="search-admin" method="get">
        <fieldset>
            <legend>{{ ('word.type.user.' ~ constUserTypeProf ~ '.label')|trans({}, 'word') }}</legend>
            <div class="search-fields">
                <p>
                    <label for="form-search-lastname">Prénom et nom</label>
                    <input id="form-search-lastname" name="lastname" type="text" value="{{ app.request.get('lastname') }}" />
                </p>
                <p>
                    <label for="form-search-email">{{ 'form.email.label'|trans }}</label>
                    <input id="form-search-email" name="email" type="text" value="{{ app.request.get('email') }}" />
                </p>
                <p>
                    <label for="form-search-academy">{{ 'form.academy.label'|trans }}</label>
                    <select id="form-search-academy" name="academy">
                        <option value="">- Toutes -</option>
                        {% for academy in academies %}
                            <option value="{{ academy }}"{% if app.request.get('academy') == academy %} selected="selected"{% endif %}>{{ academy }}</option>
                        {% endfor %}
                    </select>
                </p>
            </div>
        </fieldset>
        <fieldset>
            <legend>Opération</legend>
            <div class="search-fields">
                <p>
                    <label for="form-search-oState">{{ 'form.state.label'|trans }}</label>
                    <select id="form-search-oState" name="oState">
                        <option value=""{% if app.request.get('oState') is empty %} selected="selected"{% endif %}>- Tous -</option>
                        {% for name, label in oStates %}
                            <option value="{{ name }}"{% if name == app.request.get('oState') %} selected="selected"{% endif %}>{{ label }}</option>
                        {% endfor %}
                    </select>
                </p>
            </div>
        </fieldset>
        <fieldset>
            <legend>Demande</legend>
            <div class="search-fields">
                <p>
                    <label for="form-search-dState">{{ 'form.state.label'|trans }}</label>
                    <select id="form-search-dState" name="dState">
                        <option value=""{% if app.request.get('dState') is empty %} selected="selected"{% endif %}>- Tous -</option>
                        {% for name, label in dStates %}
                            <option value="{{ name }}"{% if name == app.request.get('dState') %} selected="selected"{% endif %}>{{ label }}</option>
                        {% endfor %}
                    </select>
                </p>
                <p>
                    <label for="form-search-date">{{ 'form.date.label'|trans }}</label>
                    <input class="date" id="form-search-date" name="date" type="text" value="{{ app.request.get('date') }}" />
                </p>
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}" />
        </p>
    </form>

    <table class="tableBo">
        <thead>
            <tr>
                <td colspan="2">{{ ('word.type.user.' ~ constUserTypeProf ~ '.label')|trans({}, 'word') }}</td>
                <td colspan="2">Opération</td>
                <td colspan="5">Demande</td>
            </tr>
            <tr>
                <td>Prénom et nom</td>
                <td>Établissement</td>
                <td>Entreprise et site</td>
                <td>{{ 'form.state.label'|trans({}, 'form') }}</td>
                <td>{{ 'form.date.label'|trans({}, 'form') }}</td>
                <td>{{ 'form.state.label'|trans }}</td>
                <td>{{ 'form.externalRegistration.label'|trans({}, 'form') }}</td>
                <td colspan="2">{{ 'word.actions'|trans({}, 'word') }}</td>
            </tr>
        </thead>
        {% for demande in demandes %}
            <tr class="delete-element-container">
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">{{ demande.cuser.firstname }} {{ demande.cuser.lastname }}</a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">
                        {{ demande.cuser.establishmentname }}, {{ demande.cuser.establishmentaddress }} {{ demande.cuser.establishmentzipcode }} {{ demande.cuser.establishmentcity }}
                    </a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">{{ demande.operationpee.company }} {{ demande.operationpee.site }}</a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">
                        {{ demande.operationpee.state|transconst('AppBundle\\Enum\\OperationPEEState') }}
                    </a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">{{ demande.created|date('d/m/Y') }}</a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">
                        {{ demande.state|transconst('AppBundle\\Enum\\DemandePEEState') }}
                    </a>
                </td>
                <td>
                    <a href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">
                        {{ demande.type|transconst('AppBundle\\Enum\\DemandePEEType')|raw }}
                    </a>
                </td>
                <td class="action">
                    <a class="edit" href="{{ path('admin_demande_pee_edit', {id:demande.id}) }}">
                        <span>Modifier</span>
                    </a>
                </td>
                <td class="action">
                    <a class="delete-element" href="{{ path('admin_demande_pee_delete', {id:demande.id}) }}">
                        <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                    </a>
                </td>
            </tr>
        {% endfor %}
    </table>

    {{ include('Admin/Paginator/pagination.html.twig', {pages:nbPages}) }}
{% endblock %}
