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

{% set coordinates = [] %}
{% for demande in demandes %}
    {% set coordinates = coordinates|merge([{
        'latitude': demande.demande.prof.latitude,
        'longitude': demande.demande.prof.longitude
    }]) %}
{% endfor %}

<table id="listusers" class="tableBo tablesorter" data-coordinates="{{ coordinates|json_encode }}">
    <thead>
        <tr>
            <th colspan="4">{{ ('word.type.user.' ~ userTypeTeacher ~ '.label')|trans({}, 'word') }}</th>
            <th colspan="3">Établissement</th>
            <th>&nbsp;</th>
            <th colspan="2">Trajet</th>
            <th>&nbsp;</th>
        </tr>
        <tr>
            <th>Email</th>
            <th>Prénom</th>
            <th>Nom</th>
            <th>Téléphone</th>
            <th>Adresse</th>
            <th>CP</th>
            <th>Ville</th>
            <th>Niveau classe</th>
            <th>Km réel</th>
            <th>Temps voiture</th>
            <th>Créer</th>
        </tr>
    </thead>
    <tbody>
        {% for row in demandes %}
            {% set demande, isPreferred, isInterested = row.demande, false, row.demande.interest|length %}

            {% set tab = '' %}
            {% for preference in preferences %}
                {% if demande.prof.id == preference[1] %}
                    {% set isPreferred = true %}
                {% endif %}
            {% endfor %}

            {% set tr_class %}
                {%- if isPreferred -%}
                    highlighted
                {%- else -%}
                    {{ loop.index is odd ? 'odd' : 'even' }}
                {%- endif -%}
            {% endset %}

            {% if isInterested %}
                {% set tr_class = tr_class ~ ' interested' %}
            {% endif %}

            <tr class="{{ tr_class }}">
                <td>{{ demande.prof.email }}</td>
                <td><a href="{{ path('admin_user_edit', {'user':demande.prof.id}) }}" target="_blank">{{ demande.prof.firstname }}</a></td>
                <td><a href="{{ path('admin_user_edit', {'user':demande.prof.id}) }}" target="_blank">{{ demande.prof.lastname }}</a></td>
                <td>{{ demande.prof.phone }}</td>
                <td>{{ demande.prof.establishmentaddress }}</td>
                <td>{{ demande.prof.establishmentzipcode }}</td>
                <td>{{ demande.prof.establishmentcity }}</td>
                <td>{{ demande.classlevel }}</td>
                <td class="km skm" val="{{ engineer.transportKm ?? 125 }}">&nbsp;</td>
                <td class="tmp stmp" val="{{ engineer.transportTime ?? 60 }}">&nbsp;</td>
                <td{% if isInterested %} title="Cet Ingénieur a exprimé un intérêt pour cette intervention"{% endif %}><a href="{{ path('admin_demande_itdlc_generate_ope_inge', {type:'prof', demandeitdlc:demande.id, user:engineer.id}) }}">Créer</a></td>
            </tr>
        {% endfor %}
    </tbody>
</table>
