{% import "@A2lixTranslationForm/macros_bootstrap_3.html.twig" as a2lixTranslations %}

    {% if not form.vars.valid %}
        <div class="alert alert-danger alert-dismissible" role="alert">
            <h5>Les erreurs a corriger !</h5>
            {% if not form.vars.valid %}
                <ul class="list-error">
                    {% for error in form.vars.errors %}
                        <span class="title-error">{{ (error.origin.config.name)|trans([]) }}</span>
                        <li>{{ error.message }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% for children in form.children %}
                {% if not children.vars.valid %}
                    <span class="title-error"> {{ (children.vars.name)|trans([]) }}</span>
                    <ul>
                        {% for error in children.vars.errors.form.getErrors(true) %}
                            <li>{{ error.message }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            {% endfor %}
        </div>
    {% endif %}

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">
                Configuration de la boutique
            </div>
            <div class="panel-body">
                {{ form_row(form.image) }}
                {{ form_row(form.hidePriceDefault) }}
                {{ form_row(form.enableAwardShop) }}
                {{ form_row(form.invoice) }}
                <div id="{{ form.invoicePaymentTerm.vars.id }}_wrapper">
                    {{ form_row(form.invoicePaymentTerm) }}
                </div>
                <div id="{{ form.invoiceSuffix.vars.id }}_wrapper">
                    {{ form_row(form.invoiceSuffix) }}
                </div>
                {{ form_row(form.enablePartnerCodeFront) }}
                {{ form_row(form.enableProductPageFront) }}
                {{ form_row(form.showCategoryMenuFront) }}
                {{ form_row(form.showPartnerCodeWhenShopBlocked) }}

            </div>
        </div>
    </div>
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">
                Activer seulement la boutique pour :
            </div>
            <div class="panel-body">
                {{ form_row(form.enableCountriesForShop) }}

            </div>
        </div>
    </div>
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">
                Désactiver seulement la boutique pour :
            </div>
            <div class="panel-body">
                {{ form_row(form.disableCountries) }}
            </div>
        </div>
    </div>
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">
                Multiples de commande autorisées
            </div>
            <div class="panel-body">
                {{ form_row(form.multiples) }}
            </div>
        </div>
    </div>
    <div class="col-md-12">
        <div class="panel panel-info">
            <div class="panel-heading">
                Boutique en vacances
            </div>
            <div class="panel-body">
                {{ form_row(form.vacationOf) }}
                {{ form_row(form.vacationAt) }}
                {{ form_row(form.disableShopForVacation) }}
                {{ form_row(form.disableOrdersForVacation) }}
                {{ a2lixTranslations.partialTranslations(form.translations, ['vacation']) }}
            </div>
        </div>
    </div>
</div>
<script>
    (function () {
        var invoiceField = document.getElementById('{{ form.invoice.vars.id }}');
        var invoicePaymentTermField = document.getElementById('{{ form.invoicePaymentTerm.vars.id }}');
        var invoicePaymentTermWrapper = document.getElementById('{{ form.invoicePaymentTerm.vars.id }}_wrapper');
        var invoiceSuffixWrapper = document.getElementById('{{ form.invoiceSuffix.vars.id }}_wrapper');

        if (!invoiceField || !invoicePaymentTermField || !invoicePaymentTermWrapper || !invoiceSuffixWrapper) {
            return;
        }

        function toggleInvoicePaymentTerm() {
            var enabled = invoiceField.checked;
            invoicePaymentTermWrapper.style.display = enabled ? '' : 'none';
            invoiceSuffixWrapper.style.display = enabled ? '' : 'none';
            invoicePaymentTermField.required = enabled;
        }

        toggleInvoicePaymentTerm();
        invoiceField.addEventListener('change', toggleInvoicePaymentTerm);
    })();
</script>
{{ form_rest(form) }}
