{% use "bootstrap_4_horizontal_layout.html.twig" %}

{% block form_label_class -%}
col-md-4
{%- endblock form_label_class %}

{% block form_group_class -%}
col-md-8
{%- endblock form_group_class %}

{% block form_help %}
    {% if help is defined and help is not null %}
    <small class="form-text text-muted">
        {{ help|nl2br }}
    </small>
    {% endif %}
{% endblock form_help %}

{% block form_widget_simple %}
    {{- parent() -}}
    {{- block('form_help') -}}
{% endblock form_widget_simple %}

{% block choice_widget %}
    {{- parent() -}}
    {{- block('form_help') -}}
{% endblock choice_widget %}

{% block choice_widget_collapsed %}
    <div class="select-wrapper">
        {%- set attr = attr|merge({class: (attr.class|default('') ~ ' ')|trim}) -%}
        {{- parent() -}}
    </div>
{% endblock choice_widget_collapsed %}

{% block choice_widget_expanded %}
    <div {{ block('widget_container_attributes') }}>
        <div class="row">
            {%- for child in form %}
                <div class="col-lg-6">
                    {{- form_widget(child, {
                        parent_label_class: label_attr.class|default(''),
                        translation_domain: choice_translation_domain,
                        valid: valid,
                    }) -}}
                </div>
            {% endfor -%}
        </div>
    </div>
{% endblock choice_widget_expanded %}

{% block textarea_widget %}
    {{- parent() -}}
    {{- block('form_help') -}}
{% endblock textarea_widget %}

{% block checkbox_widget %}
    {{- parent() -}}
    {{- block('form_help') -}}
{% endblock checkbox_widget %}

{% block radio_widget %}
    {{- parent() -}}
    {{- block('form_help') -}}
{% endblock radio_widget %}

{% block file_widget %}
    {% spaceless %}

    {% if image_path is defined and image_path is not null %}
        {% set absoluteUrl = (image_filter is defined) ? asset(image_path|imagine_filter(image_filter)) : asset(image_path) %}
    {% elseif absolute_url is defined and absolute_url is not null %}
        {% set absoluteUrl = absolute_url %}
    {% endif %}

    {% if absoluteUrl is defined and absoluteUrl is not null %}
        {# <div class="contenerInputFile-extras"> #}   
            {% if 'image_input' in attr.class %}
                <div class="form-group">
                    <img alt="" src="{{ absoluteUrl }}" style="max-width: 100%;" />
                </div>
                <div class="form-check">
                    <input id="display-{{ form.vars.id }}" class="form-check-input" name="remove_picture" type="checkbox" />
                    <label for="display-{{ form.vars.id }}" class="form-check-label">Supprimer le fichier</label>
                </div>
            {% else %}
                <div class="form-group">
                    <a href="{{ absoluteUrl }}" class="link-theme" target="_blank">Voir le fichier existant</a>
                </div>
                <div class="form-check">
                    <input id="display-{{ form.vars.id }}" class="form-check-input" name="remove_document" type="checkbox" />
                    <label for="display-{{ form.vars.id }}" class="form-check-label">Supprimer le fichier existant</label>
                </div>
            {% endif %}
        {# </div> #}
    {% endif %}
    {{ block('form_widget') }}

    {% endspaceless %}
{% endblock file_widget %}

{%- block collection_row -%}
    <div class="form-group form-collection--wrapper row">
        <label class="{{ block('form_label_class') }} col-form-label">{{ label|trans({}, 'form') }}</label>
        <div class="{{ block('form_group_class') }}">
                {{- block('collection_widget') -}}
        </div>
    </div>
{%- endblock collection_row -%}

{%- block collection_widget -%}
    <ul id="collection-{{ name|e }}" class="form-collection no-style" data-prototype="{{ prototype is defined ? form_widget(prototype)|e : '' }}" data-widget-tags="{{ '<li></li>'|e }}" {% if allow_delete %}data-remove-tags="{{ ('<a href="#" class="link link-theme form-collection--delete">' ~ ( label_delete ? (label_delete|trans({}, 'form')):  ('action.delete.label'|trans({}, 'action')) ) ~ '</a>')|e }}"{% endif %} >
        {% for counter, field in form.children %}
            <li>
                {{ form_widget(field) }}
                {{ form_errors(field) }}
                {% if counter > 1 and allow_delete %}
                {{ ('<a href="#" class="link link-theme form-collection--delete">' ~ ( label_delete ? (label_delete|trans({}, 'form')):  ('action.delete.label'|trans({}, 'action')) ) ~ '</a>')|raw }}
                {% endif %}
            </li>
        {% endfor %}
        <li></li>
    </ul>
    {% if allow_add %}
    <a href="#" class="btn btn-sm btn-theme form-collection--add" data-list="#collection-{{ name|e }}">{{ label_add ? (label_add|trans({}, 'form')):  ('action.add.label'|trans({}, 'action')) }}</a>
    {% endif %}
{%- endblock collection_widget -%}

{% block form_row -%}
    {%- if expanded is defined and expanded -%}
        {{ block('fieldset_form_row') }}
    {%- else -%}
        <div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
            {{- form_label(form) -}}
            <div class="{{ block('form_group_class') }}">
                {{- form_widget(form) -}}
                {{- form_errors(form) -}}
            </div>
    {##}</div>
    {%- endif -%}
{%- endblock form_row %}

{% block form_label_errors -%}{%- endblock form_label_errors %}

{% block form_errors -%}
    {%- if errors|length > 0 -%}
        <span class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %} d-block">
            {%- for error in errors -%}
                <span class="d-block">
                    <span class="form-error-icon badge badge-danger text-uppercase">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span>
                </span>
            {%- endfor -%}
        </span>
    {%- endif %}
{%- endblock form_errors %}
