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

{% trans_default_domain 'form' %}

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

{% block body %}
    {# Search form #}
    <form action="{{ path('admin_list_user', {type:type}) }}" class="search-admin" method="get">
        <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>
                            {% for academy in academies %}
                                <option value="{{ academy }}"{% if academy_selected == academy %} selected="selected"{% endif %}>
                                    {{ academy }}
                                </option>
                            {% endfor %}
                        </select>
                    </p>
                {% elseif userTypeEngineer == type %}
                    <p>
                        <label for="form_search_company">{{ 'form.company.label'|transchoice(1, []) }}</label>
                        <select id="form_search_company" name="company">
                            <option value="">- Toutes -</option>
                            {% for company in companies %}
                                <option value="{{ company.name }}"{% if company_selected == company.name %} selected="selected"{% endif %}>
                                    {{ company.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </p>
                {% else %}
                    <p>
                        <label for="firstname">{{ 'form.firstname.label'|trans }}</label>
                        <input id="firstname" type="text" name="firstname" value="{{ firstname }}"/>
                    </p>
                    <p>
                        <label for="lastname">{{ 'form.lastname.label'|trans }}</label>
                        <input id="lastname" type="text" name="lastname" value="{{ lastname }}"/>
                    </p>
                    <p>
                        <label for="username">{{ 'form.username.label'|trans }}</label>
                        <input id="username" type="text" name="username" value="{{ username }}"/>
                    </p>
                    <p>
                        <label for="email">{{ 'form.email.label'|trans }}</label>
                        <input id="email" type="text" name="email" value="{{ email }}"/>
                    </p>
                {% endif %}
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}"/>
        </p>
    </form>

    <table class="tableBo">
        <thead>
            <tr>
                {# <td>id</td> #}
                <td>{{ 'form.lastname.label'|trans }}</td>
                <td>{{ 'form.firstname.label'|trans }}</td>
                {# <td>{{ 'form.username.label'|trans }}</td> #}
                <td>{{ 'form.email.label'|trans }}</td>
                <td>{{ 'form.type.label'|trans }}</td>
                <td>{{ 'form.department.label'|trans }}</td>
                <td>{{ 'form.academy.label'|trans }}</td>
                {# <td>{{ 'form.latitude.label'|trans }}</td> #}
                {# <td>{{ 'form.longitude.label'|trans }}</td> #}
                <td>{{ 'form.date.creation.label'|trans }}</td>
                <td colspan="4">{{ 'word.actions'|trans({}, 'word') }}</td>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
                <tr class="delete-element-container">
                    {# <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.id }}</a></td> #}
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.lastname }}</a></td>
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.firstname }}</a></td>
                    {# <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.username }}</a></td> #}
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.email }}</a></td>
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">
                    {{ ('word.type.user.' ~ user.type ~ '.label')|trans({}, 'word') }}
                   

                    {% if user.getEstablishment().getPartnerGroup() != '' %}
                        ({{ user.getEstablishment().getPartnerGroup() }})
                    {% endif %}
                    </a></td>
                    <td>
                        <a href="{{ path('admin_user_edit', {'user':user.id}) }}">
                            {% if user.personalZipcode is not empty %}
                                {% if user.personalZipcode|length == 5 %}
                                    {{ user.personalZipcode[:2] }}
                                {% elseif user.personalZipcode|length == 6 %}
                                    {{ user.personalZipcode[:3] }}
                                {% endif %}
                            {% else %}
                                {% if user.establishmentZipcode|length == 5 %}
                                    {{ user.establishmentZipcode[:2] }}
                                {% elseif user.establishmentZipcode|length == 6 %}
                                    {{ user.establishmentZipcode[:3] }}
                                {% endif %}
                            {% endif %}
                        </a>
                    </td>
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.academy }}</a></td>
                    {# <td class="center">
                        <a href="{{ path('admin_user_edit', {'user':user.id}) }}">
                            {% if user.latitude %}
                                {{ user.latitude }}
                            {% else %}
                                <span style="color: red;">X</span>
                            {% endif %}
                        </a>
                    </td> #}
                    {# <td class="center">
                        <a href="{{ path('admin_user_edit', {'user':user.id}) }}">
                            {% if user.longitude %}
                                {{ user.longitude }}
                            {% else %}
                                <span style="color: red;">X</span>
                            {% endif %}
                        </a>
                    </td> #}
                    <td><a href="{{ path('admin_user_edit', {'user':user.id}) }}">{{ user.created|date("d/m/Y") }}</a></td>
                    <td class="action">
                        <a class="edit" href="{{ path('admin_user_edit', {'user':user.id}) }}">
                            <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                        </a>
                    </td>
                    <td class="action">
                        <label for="user-{{ user.id }}-active">Actif</label>
                        <input
                            class="input-active"
                            data-type="is_active"
                            data-url="{{ path('user_actif')}}"
                            id="user-{{ user.id }}-active"
                            type="checkbox"
                            value="{{ user.id }}"
                            {% if user.isactive %} checked="checked"{% endif %}
                        />
                        <span class="checkbox"></span>
                    </td>
                    <td class="action">
                        <label for="user-{{ user.id }}-enabled">Compte</label>
                        <input
                            class="input-active"
                            data-type="enabled"
                            data-url="{{ path('user_actif')}}"
                            id="user-{{ user.id }}-enabled"
                            type="checkbox"
                            value="{{ user.id }}"
                            {% if user.enabled %} checked="checked"{% endif %}
                        />
                        <span class="checkbox"></span>
                    </td>
                    <td class="action">
                        {% if user.isDeletable() %}
                            <a class="delete-element" href="{{ path('admin_user_delete', {user:user.id}) }}">
                                <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                            </a>
                        {% endif %}
                    </td>
                </tr>
            {% else %}
                <tr>
                    <td colspan="13"></td>
                </tr>
            {% endfor %}
        </tbody>
    </table>

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