{% set menuActive = 'DocConsult' %}
{% set menuLeft = 'gestionAO' %}
{% extends '@Consultation/Consultation/details.twig' %}
{% block tab %}

<div id="refreshDocConsult">
    {% include "@Consultation/Consultation/_navbarConsultation.twig" with {
        idAO: idAO,
        consultation: consultation,
        onglet: 'DocConsult',
    } only %}
    <div class="clearfix">
        <p style="font-style: italic">{{"Seuls les documents enregistrés seront visibles par les fournisseurs" | trad}}</p>
        <div class="colonne2">
            <h4>{{ "Pièces Jointes" | trad }}
            {% if canEdit and not enCours %}
                <a class="ajouter_v2  white-tooltip"  href="{{ path('Consultation.PJ.create', {idAO:idAO}) }}" style="float: right;">
                    <span class="infos_tooltip left fw-normal" style="font-size: var(--fs-base);">
                        {{ 'Ajouter une pièce jointe' | trad }}
                    </span>
                </a>
            {% endif %}
            </h4>
            <table class="table table-hover tableV2">
                <thead class="thead-dark" style="display: none;">
                    <th scope="col"  width="25%"></th>
                    <th scope="col" colspan="5"></th>
                </thead>
                <tbody>
                    {% set Count = 0 %}
                    {% set listDocAttTitres = listDocAttendu | column('TITRE_DOC') %}
                    {% for key, PJ in listePJ %}
                        <tr id="PJ_{{ PJ.NO_ORDRE }}">
                            <td width="25%"><b>{{ PJ.TITRE ?? PJ.LIBELLE }}</b>
                            {% set match = listDocAttendu|filter((value, key) => value.TITRE_DOC == PJ.TITRE) %}
                            {% if match is not empty %}
                                <span class="obligatoire">*</span>
                            {% endif %}
                            </td>
                            <td>
                                <a href="{{ path(
                                    'GlobalApplication.AjaxPiecesJointes.downloadFichier',
                                    {MODULE: 'AO', id: idAO, ordre: PJ.NO_ORDRE}
                                ) }}" target="_blank">
                                    {{- PJ.NOM_ORI -}}
                                </a>
                            </td>
                            <td>
                                {% if canEdit and not enCours %}
                                    {{ hover_action('PJ_'~PJ.NO_ORDRE, 'modifier_v2' , "window.location.href ='"~path('Consultation.PJ.edit', {idAO: idAO,noOrdre:PJ.NO_ORDRE})~"'", 'float: right;margin-right:5px;') }}
                                    {{ hover_action('PJ_'~PJ.NO_ORDRE, 'Supprimer_v2' , "popupConfirmation(\'"~path('Ajax.Erreur.popupConfirmationSuppresion')~"\', \'\', \'"~path('Consultation.PJ.delete',{idAO:idAO, numOrdre:PJ.NO_ORDRE})~"\', \'"~('Etes-vous sûr de vouloir supprimer la pièce jointe' | trad |e('js')|raw)~" "~(PJ.TITRE |e('js')|raw)~" ?\', \'refreshDocConsult\')", 'float: right;margin-right:5px;') }}
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    {% set listAlreadyPresent = listePJ | column('TITRE') %}
                    {% for docAttendu in listDocAttendu | filter(
                        item => item.TITRE_DOC not in listAlreadyPresent
                    ) %}
                        <tr id="{{ 'DocAttendu' ~ loop.index }}">
                            <td><b>{{ docAttendu.TITRE_DOC }}</b>
                            {% if boolSql(docAttendu[typeConsult.name ~ '_OBLIG']) %}
                                <span class="obligatoire">*</span>
                            {% endif %}
                            <td>{{"Non renseignée" | trad}}</td>
                            <td class="text-right">
                                {% if canEdit and not enCours %}
                                    {{ hover_action(
                                        'DocAttendu' ~ loop.index, 'ajouter_v2',
                                        'redirectJSWithPost('
                                        ~ path('Consultation.PJ.create', {idAO: idAO}) | json
                                        ~ ', ' 
                                        ~ {TITRE: docAttendu.TITRE_DOC} | json
                                        ~ ')'
                                    ) }}
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    {% if listePJ | length + listDocAttendu | length <= 0 %}
                        <tr><td colspan="3" style="text-align: center; color: DarkGray">{{"Aucun élément" | trad}}</td></tr>
                    {% endif %}
                </tbody>                
            </table>
        </div>
        <div class="colonne2 last">
                <h4>{{ "Clauses" | trad }}
                {% if canEdit and not enCours %}
                    <a class="ajouter_v2 white-tooltip"  href="{{ path('Consultation.Clause.creatEdit', {idAO:idAO}) }}" style="float: right;">
                        <span class="infos_tooltip left fw-normal" style="font-size: var(--fs-base);">
                            {{ 'Ajouter une clause' | trad }}
                        </span>
                    </a>
                {% endif %}
                </h4>
                <table class="table table-hover tableV2">
                    <thead class="thead-dark" style="display: none;">
                        <th scope="col" colspan="6"></th>
                    </thead>
                    <tbody>					
                        {% for clause in listeClause %}
                            <tr id="Clause_{{ clause.NO_ORDRE }}">
                                <td>{{ clause.CONTMEMO |nl2br }}</td>
                                <td>
                                    {% if canEdit and not enCours %}
                                        {{ hover_action('Clause_'~clause.NO_ORDRE, 'modifier_v2' , "window.location.href ='"~path('Consultation.Clause.creatEdit', {idAO: idAO,noOrdre:clause.NO_ORDRE})~"'", 'float: right;margin-right:5px;') }}
                                        {{ hover_action('Clause_'~clause.NO_ORDRE, 'Supprimer_v2' , "popupConfirmation(\'"~path('Ajax.Erreur.popupConfirmationSuppresion')~"\', \'\', \'"~path('Consultation.Clause.delete', {idAO: idAO,noOrdre:clause.NO_ORDRE})~"\', \'"~('Etes-vous sûr de vouloir supprimer la clause' | trad |e('js')|raw)~" ?\', \'refreshDocConsult\')", 'float: right;margin-right:5px;') }}
                                    {% endif %}
                                </td>
                            </tr>
                        {% else %}
                            <tr><td colspan="2" style="text-align: center; color: DarkGray">{{"Aucun élément" | trad}}</td></tr>
                        {% endfor %}
                        {# {% if listeClause | length <= 0 %}
                        {% endif %} #}
                    </tbody>
                </table>
            {# {% endif %} #}
        </div>
    </div>
</div>

{% endblock %}