{#**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 *#}
{% 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 -%}
    {% 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 %}
    {% endspaceless %}
{%- endblock form_label %}

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

{# Rows #}

{% block form_row -%}
    {% 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>
    {% endspaceless %}
{%- 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 -%}
    {% 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>
    {% endspaceless %}
{%- endblock checkbox_radio_row %}

{% block submit_row -%}
    {% spaceless %}
        <div class="form-group">
            <div class="{{ block('form_label_class') }}"></div>
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
            </div>
        </div>
    {% endspaceless %}
{% 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 text_with_unit_widget %}
<div class="input-group">
    {{- block('form_widget_simple') -}}
    {% if form.vars.unit is defined %}
        <div class="input-group-append">
            <span class="input-group-text">{{ form.vars.unit }}</span>
        </div>
    {% endif %}
</div>
{% endblock text_with_unit_widget %}

{% 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({'data-max-length': form.vars.max_length, 'maxlength': form.vars.max_length, 'class': 'js-countable-input'}) -%}
    {% set attr = attr|merge(input_attr) -%}

    {% 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 %}
