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

{% trans_default_domain 'form' %}

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

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

    <form action="{{ path('admin_statistics_user', {type:type}) }}" class="search-admin" method="get">
        <fieldset>
            <legend>{{ 'form.date.registration.label'|trans }}</legend>
            <div class="search-fields">
                <p>
                    <label for="datemin">{{ 'word.beginning'|trans({}, 'word') }}</label>
                    <input id="datemin" type="text" value="{{ app.request.query.get('datemin') ?? '' }}" class="date" name="datemin"/>
                </p>
                <p>
                    <label for="datemax">{{ 'word.end'|trans({}, 'word') }}</label>
                    <input id="datemax" type="text" value="{{ app.request.query.get('datemax') ?? '' }}" class="date" name="datemax"/>
                </p>
            </div>
        </fieldset>
        <fieldset>
            <div class="search-fields">
                {% if userTypeTeacher == type %}
                    <p>
                        <label for="form_search_academy">{{ 'form.academy.label'|trans }}</label>
                        <select id="form_search_academy" name="academy">
                            <option value="">- Toutes -</option>
                            {% set academy = app.request.query.get('academy') ?? '' %}
                            {% for a in academies %}
                                <option value="{{ a }}"{% if academy == a %} selected="selected"{% endif %}>{{ a }}</option>
                            {% endfor %}
                        </select>
                    </p>
                {% endif %}
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}"/>
        </p>
    </form>
    
    <table class="tableBo">
        <thead>
            <tr>
                <td>{{ 'form.date.registration.label'|trans }}</td>
                <td>{{ 'form.firstname.label'|trans }}</td>
                <td>{{ 'form.lastname.label'|trans }}</td>
                <td>{{ 'form.email.label'|trans }}</td>
                <td>Emploi</td>
                {% if userTypeTeacher == type %}
                    <td>Établissement</td>
                {% else %}
                    <td>{{ 'form.company.label'|transchoice(1, {}) }}</td>
                {% endif %}
                <td>{{ 'form.academy.label'|trans }}</td>
                <td>{{ 'form.department.label'|trans }}</td>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
                <tr>
                    <td class="center">{{ user.created|date('d/m/Y') }}</td>
                    <td>{{ user.firstname }}</td>
                    <td>{{ user.lastname }}</td>
                    <td>{{ user.email }}</td>
                    <td>
                        {% if userTypeTeacher == user.type %}
                            {% if user.categoryJob is not empty %}{{ user.categoryJob|transconst('AppBundle\\Enum\\UserJobTeacherCategory') }} / {% endif %}
                            {% if user.jobOther is not empty %}
                                {{ user.jobOther }}
                            {% else %}
                                {{ user.job|transconst('AppBundle\\Enum\\UserJobTeacher') }}
                            {% endif %}
                        {% else %}
                            {% if user.categoryJob is not empty %}{{ user.categoryJob|transconst('AppBundle\\Enum\\UserJobEngineerCategory') }} / {% endif %}{{ user.job|transconst('AppBundle\\Enum\\UserJobEngineer') }} / {{ user.jobOther }}
                        {% endif %}
                    </td>
                    <td>{{ userTypeTeacher == type ? user.establishmentName : user.establishment }}</td>
                    <td>{{ user.academy }}</td>
                    <td class="center">{{ user.establishmentZipcode|slice(0,2) }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    
    {{ include('Admin/Paginator/pagination.html.twig', {pages:nbPages}) }}
{% endblock %}