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


{% if operations is defined and operations is iterable %}
    {% for o in operations %}
        {% if o.state in [constant('AppBundle\\Enum\\OperationITDLCState::CANCELLED'), constant('AppBundle\\Enum\\OperationITDLCState::CLOSED')] %}
            {% set bgCard = 'bg-concrete' %}
        {% else %}
            {% set bgCard = 'bg-mercury' %}
        {% endif %}
        <div class="card {{ bgCard }} demande" data-did="{{ o.id }}" data-ostate="{{ o.state }}">
            <div class="item-content">
                <div class="row">
                    <div class="col-md-8 col-lg-9 col-xl-10">
                        {{ o.dateCreated }} <h2 class="h3 text-no-transform text-normal color-theme">Demande d'intervention ingénieur.e - technicien.ne ({{ o.state|transconst('AppBundle\\Enum\\OperationITDLCState') }})</h2>
                        <p>{{ o.goal|truncate(300, '…')|nl2br }}</p>
                        {#<p>#}
                            {#{% if o.availability|length > 1 %}#}
                            {#Différentes dates disponibles : <br />#}
                            {#{% endif %}#}
                            {#{% for availability in o.availability %}#}
                                {#{% if availability.dayoftheweek is null %}#}
                                    {#Le <strong>{{ availability.dateVisite|date('d/m/Y') }}</strong>#}
                                {#{% else %}#}
                                    {#Tous les <strong>{{ availability.dayoftheweek|lower }}</strong> #}
                                {#{% endif %} #}
                                {#de <strong>{{ availability.startTime|date('H\\hi') }}</strong> à <strong>{{ availability.endTime|date('H\\hi') -}}</strong><br />#}
                            {#{% endfor %}#}
                        {#</p>#}
                        <p>
                            <strong>{{ o.prof.establishmentName ?? o.prof.establishmentNameOther }}</strong><br />
                            {{ o.prof.establishmentAddress }}<br />
                            {{ o.prof.establishmentZipcode }} {{ o.prof.establishmentCity }}
                        </p>
                        <p>{{ 'form.classLevel.label'|trans({}, 'form') }}&nbsp;: <strong>{{ o.classLevel }}</strong> {% if o.classOption %}({{ o.classOption }}){% endif %}</p>
                       
                        {% if o.lastMerITDLC %}
                            {% if o.lastMerITDLC  %}
                                {% if o.lastMerITDLC and constUserTypeProf == app.user.type %}
                                    <p>
                                        Statut&nbsp;: {{ o.lastMerITDLC.lastHistory.createdAt|date('d/m/Y') }} - {{ o.lastMerITDLC.lastHistory.infos }}
                                    </p>
                                 {% endif %}
                                {% if o.lastMerITDLC and constUserTypeInge == app.user.type %}
                                    {% if o.state not in [constant('AppBundle\\Enum\\OperationITDLCState::CANCELLED'), constant('AppBundle\\Enum\\OperationITDLCState::CLOSED')] %}
                                        <p>
                                            Intervention programmée le
                                        {% if o.lastMerITDLC.answer == "date1" %}
                                            {{ o.lastMerITDLC.getFirstDate|date('d/m/Y') }} de {{ o.lastMerITDLC.getFirstDateStartTime()|date('H\\hi') }} à {{ o.lastMerITDLC.getFirstDateEndTime|date('H\\hi') }}
                                        {% elseif o.lastMerITDLC.answer == "date2" %}
                                            {{ o.lastMerITDLC.getSecondDate|date('d/m/Y') }} de {{ o.lastMerITDLC.getSeconddDateStartTime|date('H\\hi') }} à {{ o.lastMerITDLC.getSecondDateEndTime|date('H\\hi') }}
                                        {% elseif o.lastMerITDLC.answer == "date3" %}
                                            {{ o.lastMerITDLC.getThirdDate|date('d/m/Y') }} de {{ o.lastMerITDLC.getThirsDateStartTime|date('H\\hi') }} à {{ o.lastMerITDLC.getThirdDateEndTime|date('H\\hi') }}
                                        {% endif %}
                                        </p>
                                    {% endif %}
                                {% endif %}

                                {% if o.lastMerITDLC.lastHistory %}
                                    <br/><a data-fancybox data-type="ajax" href="{{ path('modal_merITDLC_histories', {'ope' : o.id }) }}" rel="nofollow">
                                        Voir l'historique
                                    </a>
                                {% endif %}

                            {% endif %}

                            
                            
                        {% endif %}
                    </div>
                    <div class="col-md-4 col-lg-3 col-xl-2 d-flex align-items-center">
                        <div class="text-center">
                        {% if o.state not in [constant('AppBundle\\Enum\\OperationITDLCState::CANCELLED'), constant('AppBundle\\Enum\\OperationITDLCState::CLOSED')] %}
                            {% if app.user.type == constUserTypeInge %}
                            <a data-fancybox data-type="ajax" class="btn btn-sm btn-white" href="{{ path('modal_cancel_operation_itdlc', {'ope' : o.id , 'type': app.user.type }) }}" rel="nofollow">
                                Annuler mon intervention
                            </a>
                            {% endif %}

                            {% if app.user.type == constUserTypeProf %}
                            <a data-fancybox data-type="ajax" class="btn btn-sm btn-white" href="{{ path('modal_cancel_operation_itdlc', {'ope' : o.id , 'type': app.user.type }) }}" rel="nofollow">
                                Annuler la rencontre
                            </a>
                            {% endif %}
                        {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
{% else %}
    {#% if dWaitingValidation is defined and dWaitingValidation > 0 %}
        <p>Vos demandes sont en cours de traitement et apparaîtront ici une fois traitées.</p>
    {% else %}
        <p>Aucune demande.</p>
    {% endif %#}
{% endif %}
