{% 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 %}
        <div class="card bg-mercury demande" data-did="{{ o.id }}">
            <div class="item-content">
                <div class="row">
                    <div class="col-md-8 col-lg-9 col-xl-10">
                        <h2 class="h3 text-no-transform text-normal color-theme">Demande d'intervention Ingénieurs
                            ({{ o.state|transconst('AppBundle\\Enum\\OperationITDLCState') }})</h2>

                        <p>{{ o.goal|truncate(300, '…')|nl2br }}</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>
                    </div>

                    <div class="col-md-4 col-lg-3 col-xl-2 d-flex align-items-center">
                        <div class="w-100 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 }) }}" rel="nofollow">#}
                            {#Annuler ma visite#}
                            {#</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 }) }}" rel="nofollow">#}
                            {#Annuler la visite#}
                            {#</a>#}
                            {#{% endif %}#}
                            {#{% endif %}#}
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xl-12 text-center">

                        {% if o.lastMerITDLC is not empty %}
                            {% if o.lastMerITDLC.answer is null %}
                                {% for date in o.lastMerITDLC.AllDates %}
                                    {% if date.day is not null %}
                                        <a href="{{ path('espace_perso_merITDLC_reponse', {mer: o.lastMerITDLC.id, reponse: 'date'~loop.index}) }}"
                                           class="btn btn-theme btn-sm" onclick="return confirm(txt_confirm)"
                                           style="{% if loop.first %}margin-top: 15px;{% endif %}margin-right: 15px">
                                            Valider le {{ date.day|date('d/m/Y') }}
                                            de {{ date.hours.startTime|date('H\\hi') }}
                                            à {{ date.hours.endTime|date('H\\hi') -}}</a>
                                    {% endif %}
                                {% endfor %}

                                <br/>

                                <a class="btn btn-theme btn-sm" style="margin-top: 15px;margin-right:15px" href="{{ path('espace_perso_merITDLC_reponse', {mer: o.lastMerITDLC.id, reponse: 'autre'}) }}"
                                   onclick="return confirm(txt_confirm)">
                                    Je souhaite participer mais aucune date <br/>ne me convient
                                </a>

                                <a class="btn btn-theme btn-sm" data-fancybox data-type="ajax"
                                   href="{{ path('espace_perso_merITDLC_reponse', {mer: o.lastMerITDLC.id, reponse: 'non'}) }}">
                                    Je ne souhaite pas participer à <br/>cette rencontre
                                </a>
                            {% elseif o.lastMerITDLC.answer == "autre" %}
                                <p class="p-sm-5 bg-white">Vous êtes intéressé mais les dates proposées ne vous conviennent pas.</p>
                            {% endif %}
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
{% endif %}

<script>
    var txt_confirm = "Merci de confirmer votre réponse;";
</script>