{% do subtitle = strBuild('Paramétrage @1@' | trad, ['Edicom']) %}
{% do setAriane(1, subtitle) %}
{% extends 'layout.twig' %}
     
{% block body %}

<section class="contenu">
    <h1>{{ 'Paramétrage' | trad }}</h1>

    {{ ariane() }}

    <h2>{{ subtitle }}</h2>

    <form method="POST" action="{{ path('Parametrage.Edicom.update') }}"
        class="box-form form-default",
        onsubmit="return ajaxSubmit(event)"
        data-onsuccess="mainFormSuccess"
    >
        <fieldset class="scheduler-border">
            <legend class="scheduler-border">{{ 'Authentification' | trad}}</legend>
            
            <div class="bs-row gutter-x-base">
                <div class="bs-col-6">
                    {{ formInput(form.USERNAME, subject, 'Username') }}
                    {{ formInput(form.PASSWORD, subject, 'Password') }}
                </div>
                <div class="bs-col-6">
                    {{ formInput(form.CLIENT_ID, subject, 'Client ID') }}
                    {{ formInput(form.CLIENT_SECRET, subject, 'Client secret') }}
                </div>
            </div>
        </fieldset>
        <div class="bs-row gutter-x-base">
            <div class="bs-col-6">
                {{ formInput(form.GROUP, subject, 'Groupe') }}
                {{ formInput(form.DOMAIN, subject, 'Domaine') }}
            </div>
            <div class="bs-col-6">
                {{ formInput(form.APP, subject, 'Application') }}
            </div>
        </div>
        <div class="text-right">
            <button type="submit" class="button principal m-0">
                {{- 'Enregistrer' | trad -}}
            </button>
        </div>
    </form>

</section>
<script>

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();
}

//____________________

function updateFormMapping(codePartn) {
    let wrapper = document.getElementById('wrapper-form-mapping');
    if (codePartn.length == 0) {
        wrapper.innerHTML = '';
        return;
    }
    ajaxHtmlUpdate(
        wrapper,
        {{ path('Parametrage.ApiExt.formMapping') | json }},
        {partn: codePartn}
    );
}
</script>
{% endblock %}