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

{% trans_default_domain 'form' %}

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

{% block body %}
    {{ knp_menu_render('actions_demandes_itdlc') }}

    {# Formulaire de recherche #}
    <form action="{{ path('admin_demande_itdlc', {'user_type':user_type}) }}" class="search-admin" method="get">
        <fieldset>
            <legend>{{ ('form.' ~ user_type ~ '.label')|transchoice(1) }}</legend>
            <div class="search-fields">
                <p>
                    <label for="user_name">Nom et prénom</label>
                    <input id="user_name" type="text" name="user_name" value="{{ user_name }}" />
                </p>
                {% if userTypeTeacher == user_type %}
                    <p>
                        <label for="user_academy">{{'form.academy.label'|trans }}</label>
                        <select id="user_academy" name="user_academy">
                            <option value="">- Toutes -</option>
                            {% for academy in user_academies %}
                                <option value="{{ academy }}"{% if academy == user_academy %} selected="selected"{% endif %}>{{ academy }}</option>
                            {% endfor %}
                        </select>
                    </p>
                {% endif %}
            </div>
        </fieldset>
        {% if userTypeTeacher == user_type %}
            <fieldset>
                <legend>{{ 'form.itdlc.demande.label'|transchoice(1, {}, 'form') }}</legend>
                <div class="search-fields">
                    <p>
                        <label for="demande_state">{{ 'form.state.label'|trans({}, 'form') }}</label>
                        <select id="demande_state" name="demande_state">
                            <option value="">- Tous -</option>
                            {% for key, state in demande_states %}
                                <option value="{{ key }}"{% if key == demande_state %} selected="selected"{% endif %}>{{ state }}</option>
                            {% endfor %}
                        </select>
                    </p>
                    <p>
                        <label for="demande_whoisincharge">{{ 'form.whoisincharge.label'|trans({}, 'form') }}</label>
                        <select id="demande_whoisincharge" name="demande_whoisincharge">
                            <option value="">- Tout le monde -</option>
                            {% for key, employee in demande_employees %}
                                <option value="{{ key }}"{% if key == demande_employee %} selected="selected"{% endif %}>{{ employee }}</option>
                            {% endfor %}
                        </select>
                    </p>
                </div>
            </fieldset>
        {% endif %}
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}" />
        </p>
    </form>

    <table class="tableBo">
        <thead>
            <tr>
                <td colspan="{{ userTypeTeacher == user_type ? 3 : 2 }}">{{ ('form.' ~ user_type ~ '.label')|transchoice(1) }}</td>
                <td colspan="{{ userTypeTeacher == user_type ? 6 : 4 }}">{{ 'form.itdlc.demande.label'|transchoice(1, {}, 'form') }}</td>
            </tr>
            <tr>
                <td>Nom et prénom</td>
                <td>Ville</td>
                {% if userTypeTeacher == user_type %}
                    <td>{{'form.academy.label'|trans }}</td>
                {% endif %}
                <td>Date</td>
                {% if userTypeTeacher == user_type %}
                    <td>{{'form.state.label'|trans }}</td>
                    <td>{{'form.whoisincharge.label'|trans }}</td>
                    <td colspan="4">{{ 'word.actions'|trans({}, 'word') }}</td>
                {% else %}
                    <td>Nbr de contributions acceptées</td>
                    <td colspan="3">{{ 'word.actions'|trans({}, 'word') }}</td>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for operation in ope %}
                <tr class="delete-element-container">
                    {% if userTypeTeacher == user_type %}
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {{ operation.prof.lastname ?? '' }} {{ operation.prof.firstname ?? '' }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {{ operation.prof.establishmentCity ?? '' }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {{ operation.prof.academy ?? '' }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {{ operation.created|date('d/m/Y') }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {{ operation.state|transconst('AppBundle\\Enum\\OperationITDLCState') }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                {#{ operation.whoIsInCharge|transconst('AppBundle\\Enum\\EmployeesInCharge') }#}
                                {{ operation.whoIsInCharge }}
                            </a>
                        </td>
                        <td class="action">
                            {% if operation.prof.latitude is defined and operation.prof.longitude is defined %}
                                {% if operation.prof.latitude is not null or operation.prof.longitude is not null %}
                                        <a class="search" href="{{ path('admin_demande_itdlc_professeur_search', {id:operation.id }) }}">
                                            <span>{{ 'action.search'|trans({}, 'action') }}</span>
                                        </a>
                                {% endif %}
                            {% else %}
                                <small>Geoloc</small>
                            {% endif %}
                        </td>
                        <td class="action">
                            <a class="delete-element" href="{{ path('admin_operation_itdlc_delete', {id:operation.id}) }}">
                                <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                            </a>
                        </td>
                        <td class="action">
                            <a class="edit" href="{{ path('admin_demande_itdlc_professeur_edit', {id:operation.id}) }}">
                                <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                            </a>
                        </td>
                    {% else %} {# Engineer #}
                        <td>
                            <a href="{{ path('admin_demande_itdlc_inge_edit', {id:operation.id}) }}">
                                {{ operation.lastname }} {{ operation.firstname }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_inge_edit', {id:operation.id}) }}">
                                {{ operation.personalCity }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_inge_edit', {id:operation.id}) }}">
                                {{ operation.created|date('d/m/Y') }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ path('admin_demande_itdlc_inge_edit', {id:operation.id}) }}">
                                {% if operation.nbContribution %}
                                    {{ operation.nbContribution }}
                                {% else %}
                                    0
                                {% endif %}
                                contributions acceptées
                            </a>
                        </td>
                        <td class="action">
                            {% if operation.latitude is not null or operation.longitude is not null %}
                                <a class="search" href="{{ path('admin_demande_itdlc_ingenieur_search', {'user':operation.id}) }}">
                                    <span>{{ 'action.search'|trans({}, 'action') }}</span>
                                </a>
                            {% endif %}
                        </td>
                        <td class="action">
                            <a class="edit" href="{{ path('admin_demande_itdlc_inge_edit', {id:operation.id}) }}">
                                <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                            </a>
                        </td>
                    {% endif %}
                </tr>
            {% else %}
                <tr>
                    <td colspan="{% if userTypeTeacher == user_type %}9{% else %}6{% endif %}">
                        Aucune demande ne correspond à votre recherche.
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>

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