{% extends 'layout.twig' %}

{% block body %}

<section class="contenu">
    <h1>{{ 'Paramétrage des types incidents' | trad }}</h1>
    
    {{ ariane() }}
    <div class="tab-content clearfix" style="margin-top:15px;">    

        {% set formActionPath = selectedIncident is defined and selectedIncident 
            ? path('Parametrage.ParametrageIncident.incidentValidationUpdate', {'code': selectedIncident.COD_INC}) 
            : path('Parametrage.ParametrageIncident.incidentValidationCreate') 
        %}
        {% set formtitle = selectedIncident is defined and selectedIncident 
            ? 'Modifier un incident' 
            : 'Créer un type d\'incident'
        %}
            {% set messageInfo = selectedIncident is defined and selectedIncident
                ? 'Vos modifications ont bien été prises en compte'
                : 'La création de l\'incident s\'est bien déroulée'
            %}
            <script>
                let fnFermer = "window.location.href='{{ path('Parametrage.ParametrageIncident.incident') }}'";
                window.action.createParamSuccess = function (data) {
                    activePopupInfo(
                        {{ 'Informations' | trad | json }},
                        {{ messageInfo | trad | json }},
                        'modal_small',
                        fnFermer
                    );
                    desactiveLoader();
                };
            </script>
        <div class="p-base">
            <span class="zoneError">{{ erreur | raw }}</span>
                <form 
                    method="post"
                    action="{{ formActionPath  }}"
                    onsubmit="return ajaxSubmit(event)"
                    data-onsuccess="createParamSuccess"
                    class="form-default"
                >
                <fieldset class="scheduler-border">
                    <legend class="scheduler-border">
                        {{ formtitle | trad }}
                    </legend>

                    <div class="bs-row gutter-x-base">
                        <div class="bs-col-half" id="incident-category-select">
                            {{ inputAdvance('SELECT', {
                                titre: 'Catégorie' | trad,
                                name: 'category_code',
                                required: true,
                                listeValue: listeCategory,
                                obligatoire: true,
                                'option': selectedIncident ? 'readOnly' : '',
                                value: selectedIncident ? selectedIncident.CODE_CAT : ''
                                
                            }) }}
                        </div>
                        
                        <div class="bs-col-half" id="incident-list-select">
                            {{ inputAdvance('TEXT', {
                                titre: 'Code' | trad,
                                name: 'incident_code',
                                required: true,
                                obligatoire: true,
                                pathValidator: path('Ajax.validator.isStringAvecEspace'),
                                paramsValidator: "{'sizeMin': '1', 'sizeMax': '7'}",
                                'option': selectedIncident ? 'readOnly' : '',
                                value: selectedIncident ? selectedIncident.COD_INC : ''
                            }) }}
                        </div>

                        <div class="bs-col-half">
                            {{ inputAdvance('TEXT', {
                                titre: 'Nouveau libellé' | trad,
                                name: 'incident_label',
                                required: true,
                                value: selectedIncident ? selectedIncident.LIBELLE : '',
                                pathValidator: path('Ajax.validator.isStringAvecEspace'),
                                paramsValidator: "{'sizeMin': '1', 'sizeMax': '60'}"
                            }) }}
                        </div>
                    </div>
                    
                    <div class="bs-row gutter-x-base mt-base">
                        <div class="bs-col-half">
                            {{ inputAdvance('SWITCH', {
                                titre: 'Masquer' | trad,
                                name: 'MASQUER',
                                value: selectedIncident.isHidden | boolSql
                            }) }}
                        </div>
                    </div>
                </fieldset>
                
                <div class="text-right mt-base">
                    <button type="submit" class="button principal">
                        {{ 'Enregistrer' | trad }}
                    </button>
                    <a href="{{ path('Parametrage.ParametrageIncident.incident') }}" class="button secondaire">{{ 'Annuler' | trad }}</a>
                </div>
            </form>
        </div>
    </div>
</section>
{% endblock %}