{#
 # For the full copyright and license information, please view the
 # docs/licenses/LICENSE.txt file that was distributed with this source code.
 #}
{% use '@PrestaShop/Admin/TwigTemplateForm/bootstrap_4_layout.html.twig' %}
{% block form_start -%}
    {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
    {{- parent() -}}
{%- endblock form_start %}

{# Labels #}

{% block form_label -%}
    {% apply spaceless %}
        {% if label is same as(false) %}
            <div class="{{ block('form_label_class') }}"></div>
        {% else %}
            {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %}
            {{- parent() -}}
        {% endif %}
    {% endapply %}
{%- endblock form_label %}

{% block form_label_class -%}
  form-control-label
{%- endblock form_label_class %}

{# Rows #}

{% block form_row -%}
    {% apply spaceless %}
        <div class="{{ block('form_row_class') }} {% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
            {{ form_label(form) }}
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
                {{ form_errors(form) }}
                {{ block('form_help') }}
            </div>
        </div>
    {% endapply %}
{%- endblock form_row %}

{% block checkbox_row -%}
    {{- block('checkbox_radio_row') -}}
{%- endblock checkbox_row %}

{% block radio_row -%}
    {{- block('checkbox_radio_row') -}}
{%- endblock radio_row %}

{% block checkbox_radio_row -%}
    {% apply spaceless %}
        <div class="form-group{% if not valid %} has-error{% endif %}">
            <div class="{{ block('form_label_class') }}"></div>
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
                {{ form_errors(form) }}
            </div>
        </div>
    {% endapply %}
{%- endblock checkbox_radio_row %}

{% block submit_row -%}
    {% apply spaceless %}
        <div class="form-group">
            <div class="{{ block('form_label_class') }}"></div>
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
            </div>
        </div>
    {% endapply %}
{% endblock submit_row %}

{% block form_group_class -%}
    col-sm
{%- endblock form_group_class %}

{% block form_row_class -%}
    form-group row
{%- endblock form_row_class %}

{% block ip_address_text_widget %}
<div class="input-group">
    {{- block('form_widget_simple') -}}
    <button type="button" class="btn btn-outline-primary add_ip_button" data-ip="{{ currentIp }}">
        <i class="material-icons">add_circle</i> {{ 'Add my IP'|trans({}, 'Admin.Actions') }}
    </button>
</div>
{% endblock ip_address_text_widget %}

{% block switch_widget %}
<div class="input-group">
    {{- parent() -}}
</div>
{% endblock switch_widget %}

{% block text_with_length_counter_widget %}
  <div class="input-group js-text-with-length-counter">
    {% set current_length = form.vars.max_length - form.vars.value|length %}

    {% if form.vars.position == 'before' %}
      <div class="input-group-prepend">
        <span class="input-group-text js-countable-text">{{ current_length }}</span>
      </div>
    {% endif %}

    {% set attr = attr|merge(input_attr) -%}
    {% set attr = attr|merge({'data-max-length': form.vars.max_length, maxlength: form.vars.max_length, class: (attr.class|default('') ~ ' js-countable-input')|trim}) -%}

    {% if form.vars.input == 'textarea' %}
      {{- block('textarea_widget') -}}
    {% else %}
      {{- block('form_widget_simple') -}}
    {% endif %}

    {% if form.vars.position == 'after' %}
      <div class="input-group-append">
        <span class="input-group-text js-countable-text">{{ current_length }}</span>
      </div>
    {% endif %}
  </div>
{% endblock text_with_length_counter_widget %}

{%- block number_widget -%}
  {%- set type = type|default('text') -%}
  <div class="input-group">
    {{- block('form_unit_prepend') -}}
    <div class="w-100">{{- block('form_widget_simple') -}}</div>
    {{- block('form_unit') -}}
  </div>
{%- endblock number_widget -%}

{%- block integer_widget -%}
  {%- set type = type|default('number') -%}
  <div class="input-group">
    {{- block('form_unit_prepend') -}}
    {{- block('form_widget_simple') -}}
    {{- block('form_unit') -}}
  </div>
{%- endblock integer_widget -%}

{% block form_unit %}
  {% if form.vars.unit is defined and not form.vars.prepend_unit %}
    <div class="input-group-append">
      <span class="input-group-text">{{ form.vars.unit }}</span>
    </div>
  {% endif %}
{% endblock form_unit %}

{% block form_unit_prepend %}
  {% if form.vars.unit is defined and form.vars.prepend_unit %}
    <div class="input-group-prepend">
      <span class="input-group-text">{{ form.vars.unit }}</span>
    </div>
  {% endif %}
{% endblock form_unit_prepend %}

{% block amount_currency_widget %}
  <div class="input-group">
    <input id="{{ form.amount.vars.id }}" type="text" class="form-control" name="{{ form.amount.vars.full_name }}" required>
    <div class="input-group-append">
      {% if form.amount.vars.unit is defined %}
        <span class="input-group-text">{{ form.amount.vars.unit }}</span>
        {{ form_widget(form.id_currency) }}
      {% else %}
        {{ form_widget(form.id_currency, {attr: {class: 'form-control'}}) }}
      {% endif %}
    </div>
  </div>
{% endblock %}
