{% extends '@ParamFac/_layout.twig' %}

{% block content %}

    <article class="box-form mb-base"> 
        <header class="bs-row">
            <h2 class="bs-col">
                {{ 'Plateformes agréées' | trad }}
            </h2>
            <div class="bs-col text-right">
                <a class="button principal"
                    href="{{ path('Parametrage.FactureDematPartn.formCreate') }}"
                >{{ 'Ajouter' | trad }}</a>
            </div>
        </header>

        {% embed '@EtatStatistiques/Tableau/_gestable.twig' with {
            table: {
                listCol: [
                    {
                        name: 'PARTN',
                        label: 'Partenaire' | trad,
                    },
                    {
                        name: 'LABEL',
                        label: 'Libellé' | trad,
                    },
                    {
                        name: 'DATE_DEBUT',
                        label: 'Date d’activation' | trad,
                        format: 'date',
                    },
                    {
                        name: 'DATE_FIN',
                        label: 'Date de désactivation' | trad,
                        format: 'date',
                    },
                    {
                        name: 'isActive',
                        label: 'Actif' | trad,
                    },
                ],
                listRow: listRow,
                action: true,
            },
        } %}
            {% block cell_PARTN %}
                <td>{{ mapPartnLabel[ item.PARTN ] }}</td>
            {% endblock  %}
            {% block cell_info %}
                <td>
                    <dl class="dl-info" style="width: 50em;">
                    {% if item.PARTN == 'AGN3' %}
                        <dt>{{ 'Identifiant de l’entreprise' | trad }}</dt>
                        <dd>{{ item.COMPANY_ID }}</dd>
                    {% else %}
                        <dt>{{ 'URL' | trad }}</dt>
                        <dd>{{ item.URL }}</dd>
                        <dt>{{ 'Login' | trad }}</dt>
                        <dd>{{ item.CLIENT_ID }}</dd>
                    {% endif %}
                    </dl>
                </td>
            {% endblock  %}
            {% block cell_isActive %}
                <td>
                    {{ item.isActive ? 'Oui' | trad : 'Non' | trad }}
                </td>
            {% endblock  %}
        {% endembed %}
    </article>
    
    <form method="POST" class="form-default box-form"
        action="{{ path('Parametrage.FactureDematPartn.updateConfig') | e('html_attr') }}"
        onsubmit="return ajaxSubmit(event)"
        data-onsuccess="mainFormSuccess"
    >
        <h2 class="bs-col">{{ 'Refus automatique' | trad }}</h2>

        {{ inputAdvance('SWITCH', {
            titre: 'Facture en doublon' | trad,
            name: 'REFUS_AUTO_DUPLI',
            value: paravrac.FAC_DEMAT.REFUS_AUTO_DUPLI,
        }) }}
        {{ inputAdvance('SWITCH', {
            titre: 'N° de commande incorrect ou manquant' | trad,
            name: 'REFUS_AUTO_BADCDE',
            value: paravrac.FAC_DEMAT.REFUS_AUTO_BADCDE,
        }) }}

        <h2>
            {{ 'Fournisseur autorisant les factures sans référence de commande' | trad }}
        </h2>
        {{ formInput(form.listFouException, paravrac) }}
        
        {% if form.listCsMapping %}
        <h2 class="bs-col">{{ 'Mapping des champs supplémentaires de l’entête de facture' | trad }}</h2>
        {{ formInput(form.listCsMapping, paravrac) }}
        
        {% endif %}
        <footer class="text-right">
            <button type="submit" class="button principal m-0">
                {{- 'Enregistrer' | trad -}}
            </button>
        <footer>
    </form>

{#
    <article class="box-form mb-base"> 
        <header class="bs-row">
            
            <div class="bs-col text-right">
                <a class="button principal"
                    href="{{ path('Parametrage.FactureDematPartn.formCreate') }}"
                >{{ 'Ajouter' | trad }}</a>
            </div>
        </header>

        {% embed '@EtatStatistiques/Tableau/_gestable.twig' with {
            table: {
                listCol: [
                    {
                        name: 'CODE',
                        label: 'Code' | trad,
                    },
                    {
                        name: 'RS',
                        label: 'Raison sociale' | trad,
                    },
                    action: true
                ],
                listRow: listFouException,
            },
        } only %}
            {% block action_header %}

            {% endblock %}
        {% endembed %}
    </article>
    #}
<script>
// TODO : factorize
let flashbag = localStorage.getItem('flashbag');
if (flashbag) {
    activePopupInfo('', flashbag, 'modal_small');
    localStorage.removeItem('flashbag');
}
window.action.mainFormSuccess = function() {
    localStorage.setItem(
        'flashbag',
        {{ 'Vos modifications ont été prises en compte.' | trad | json }}
    );
    window.action.pageRefresh();
}
</script>
{% endblock %}