{% extends '@Fournisseur/DocFournisseur/_rowDocBase.twig' %}

{% set dateTmpPartenaire = false %}
{% set matchTmpPartenaire = false %}
{% for matchingPar in docAtt.Matching|split(',') %}
    {% if dateTmpPartenaire < resultAPI[matchingPar]['state']['validityEnd']  %}
        {% set matchTmpPartenaire = matchingPar %}
    {% endif %}
    {% set dateTmpPartenaire = resultAPI[matchingPar]['state']['validityEnd'] %}
{% endfor %}
    
{% block colStatus %}
    <td class="etat">
        {% if docAtt.DOC_INUTILE | boolSql %}
            <span class="sans_objet">{{ 'Sans objet' | trad }}</span>	
        {% elseif str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityStart']) == "" %}
            <span class="sans_objet">{{ 'Absent' | trad }}</span>
        {% elseif  date<=str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityStart']) and date>=str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityEnd']) %}
            <span class="absent">{{ 'Proche péremption' | trad }}</span>
        {% elseif  (str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityEnd'])>=date) %}
            <span class="ajour">{{ 'À jour' | trad }}</span>
        {% elseif  date>str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityEnd'])  %}
            <span class="perime">{{ 'Périmé' | trad }}</span>
        {% endif %}
    </td>
{% endblock %}
{% block colCentre %}
    {% if resultAPI[matchTmpPartenaire]['revisionId'] == '' %}
        {{ parent() }}
    {% else %}
        <td></td>
    {% endif %}
{% endblock %}
{% block colAuteur %}
    {% if resultAPI[matchTmpPartenaire]['revisionId'] == '' %}
        {{ parent() }}
    {% else %}
        <td></td>
    {% endif %}
{% endblock %}
{% block colValable %}
    <td>
        {% if resultAPI[matchTmpPartenaire]['state']['validityStart'] %}
            {{ 'Du' | trad }} {{ str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityStart']) | dateTrad  }}<br/>
            {{ 'au' | trad }} {{  str_replace("-","",resultAPI[matchTmpPartenaire]['state']['validityEnd']) | dateTrad }}
        {% endif %}
    </td>
{% endblock %}
{% block colAction %}
    <td>
        {% if matchTmpPartenaire != '' 
            and resultAPI[matchTmpPartenaire]['revisionId'] != ''
        %}
                {{ hover_action(
                    'docFrs_'~loop.index,
                    'download_v2' ,
                    "window.location.href ='"
                    ~ path(
                        'API.Eattestations.telechargementDocument',
                        {
                            documentId: resultAPI[matchTmpPartenaire]['documentId'], dossierId: resultAPI[matchTmpPartenaire]['dossierId'], 
                            fileId: resultAPI[matchTmpPartenaire]['fileId']
                        }
                    )
                    ~"';",
                    'float: right;margin-right: 10px;',
                    ('Télécharger depuis' | trad~' E-attestations')
                ) }}
        {% else %}
            {% if docAtt.NOM_FIC != "" and (docAtt.DOC_INUTILE|boolSql)==0 %}
                {{ hover_action(
                    'docFrs_'~loop.index,
                    'download_v2', 
                    "window.location.href ='"~path('Fournisseur.DocFournisseur.downloadFichier', {id: code_fournisseur, ordre: docAtt.NO_ORDRE})~"';", 
                    'float: right;margin-right: 10px;'
                ) }}
            {% endif %}
        {% endif %}
        {% if demandeActif == false %}
            {% if (docAtt.NPRELANCE | boolSql ==0 ) 
                and gestionALG == FALSE 
                and (
                    (
                        (docAtt.NOM_FIC != "" 
                        and date>docAtt.DT_VALID 
                        and docAtt.DT_VALID!='00000000'
                    ) 
                    or docAtt.NOM_FIC == ""
                ) and docAtt.DOC_INUTILE |boolSql == 0
            ) %}
                {{ hover_action(
                    'docFrs_'~loop.index,
                    'refresh_v2',
                    "ajaxPopup(\'"
                        ~ path('Fournisseur.DocFournisseur.PopupRelance',{id:code_fournisseur})
                        ~ "\', \'" ~ ('Relance du document' | trad ~ " " ~ (docAtt.TITRE  |e('js')|raw))~"\', \'"~(docAtt.TITRE |e('js')|raw)~"\', \'"~docAtt.NO_ORDRE~"\');", 
                    'float: right;margin-right: 10px;',
                    'Relance' |trad
                ) }}
            {% endif %}
        {% endif %}
    </td>
{% endblock %}