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

{% set interest_txt_unchecked = ('sentence.interest.select')|trans({}, 'sentence') %}
{% set interest_txt_checked = ('sentence.interest.selected')|trans({}, 'sentence') %}

{% if demandes is defined and demandes is iterable %}
    {% for demande in demandes %}
        {% set d = demande["demande"] is defined ? demande["demande"] : demande %}

        {% if app.user.type == constUserTypeProf %}
            <div class="card bg-concrete demande" data-did="{{ d.id }}" data-dstate="{{ d.state }}">
                <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énieur.e - technicien.ne ({{ d.state|transconst('AppBundle\\Enum\\OperationITDLCState') }})</h2>
                            {% if d.goalCategory %}<h3 class="h4 text-no-transform text-normal color-theme">{{ d.goalCategory|transconst('\\AppBundle\\Enum\\ITDLCGoalCategory') }}"</h3>{% endif %}
                            <p>{{ d.goal|truncate(300, '…')|nl2br }}</p>
                            {#<p>#}
                                {#{% if d.availability|length > 1 %}#}
                                {#Différentes dates disponibles : <br />#}
                                {#{% endif %}#}
                                {#{% for availability in d.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>{{ d.prof.establishmentName ?? d.prof.establishmentNameOther }}</strong><br />
                                {{ d.prof.establishmentAddress }}<br />
                                {{ d.prof.establishmentZipcode }} {{ d.prof.establishmentCity }}
                            </p>
                            <p>{{ 'form.classLevel.label'|trans({}, 'form') }}&nbsp;: <strong>{{ d.classLevel }}</strong> {% if d.classOption %}({{ d.classOption }}){% endif %}</p>


                            {% if d.lastMerITDLC %}
                                {% if d.lastMerITDLC.lastHistory %}
                                    <p>
                                        Statut&nbsp;: {{ d.lastMerITDLC.lastHistory.createdAt|date('d/m/Y') }} - {{ d.lastMerITDLC.lastHistory.infos }}
                                    </p>
                                    <br />
                                    <a data-fancybox data-type="ajax" href="{{ path('modal_merITDLC_histories', {'ope' : d.id }) }}" rel="nofollow">
                                        Voir l'historique
                                    </a>
                                {% endif %}
                            {% endif %}

                        </div>

                        <div class="d-block col-md-4 col-lg-3 col-xl-2 d-flex align-items-center">
                            <div class="w-100 text-center">
                            {% if d.state not in [constant('AppBundle\\Enum\\OperationITDLCState::CANCELLED'), constant('AppBundle\\Enum\\OperationITDLCState::CLOSED'), constant('AppBundle\\Enum\\OperationITDLCState::CLOSED'), constant('AppBundle\\Enum\\OperationITDLCState::ONGOING')] %}
                                
                                <a style="display: block;line-height: 1.3;" class="btn btn-sm btn-white" href="{% if app.user.type == constUserTypeProf %}{{ path('espace_perso_prof_itdlc_edit', {ope:d.id, step: 3}) }}{% else %}{{ path('espace_perso_inge_itdlc', {ope:d.id}) }}{% endif %}">
                                    Choisir un intervenant<br/>
                                    ou modifier ma demande
                                </a>
                                -
                               
                                <a style="display: block;" data-fancybox data-type="ajax" class="btn btn-sm btn-white" href="{{ path('modal_cancel_demande_itdlc', {'demande' : d.id }) }}" rel="nofollow">
                                    Annuler ma demande
                                </a>
                                
                            {% endif %}

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% else %}
            {#{% set isInterested = demande.isInterested %}#}
            <div class="col-md-6">
                <div class="card bg-concrete item demande" data-did="{{ d.id }}">
                    <div class="item-content">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="block-donnees-photo photo-badge">
                                    {% if d.prof.photo %}
                                        <img alt="Photo de profil" class="img-fluid" src="{{ d.prof.getWebPhoto|imagine_filter('150Lx150H') }}">
                                    {% else %}
                                        {{ include('Front/_component/icon.html.twig', {id: 'user--user', class:'icon-profile-default'}) }}
                                    {% endif %}
                                </div>
                            </div>
                            <div class="col-md-8">
                                <h3 class="item-title h6 text-no-transform">
                                    {{ d.prof.establishmentName ?? d.prof.establishmentNameOther }}
                                </h3>
                                <p class="">
                                    {{ d.prof.establishmentAddress }}<br />
                                    {{ d.prof.establishmentZipcode }} {{ d.prof.establishmentCity }}
                                </p>
                                <p class="text-small">
                                    <strong>Intervention&nbsp;:</strong>
                                    {% if d.goalCategory %}"{{ d.goalCategory|transconst('\\AppBundle\\Enum\\ITDLCGoalCategory') }}"{% endif %}
                                    {% if 1 == d.availability|length %}
                                        {% set availability = d.availability|first %}
                                        
                                        {% 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>
                                    {% endif %}
                                </p>

                                <div class="clearfix">
                                    <a data-fancybox data-type="ajax" class="float-right mt-1" href="{{ path('modal_demande_itdlc', {'demande' : d.id }) }}" rel="nofollow">Voir plus</a>
                                </div>
                            </div>
                            {#{% if interest_txt_checked is defined %}#}
                            {#<div class="col-md-12">    #}
                                {#&#123;&#35;<input id="ditdlc_interest_{{ d.id }}_checkbox" type="checkbox" value="{{ d.id }}" name="interest[]" style="display: none;"{% if isInterested %} checked {% endif %}/>&#35;&#125;#}
                                {#<button id="ditdlc_interest_{{ d.id }}_select" type="button" class="btn btn-white btn-sm select-interest-itdlc{% if isInterested %} has-select-icon{% endif %}" data-ajax-url="{{ path('interest_itdlc', { 'ope' : d.id }) }}">#}
                                    {#{% if isInterested %}  #}
                                        {#{{ interest_txt_checked|raw }}#}
                                    {#{% else %}#}
                                        {#{{ interest_txt_unchecked|raw }}#}
                                    {#{% endif %}#}
                                {#</button>#}
                            {#</div>#}
                            {#{% endif %}#}
                        </div>
                    </div>
                </div>
            </div>
        {% endif %}
    {% endfor %}
{% endif %}
