{% use '@PrestaShop/Admin/TwigTemplateForm/bootstrap_4_horizontal_layout.html.twig' %}

{% block material_choice_table_widget %}
  <div {{ block('widget_container_attributes') }}>
    {% if searchable is defined and searchable is same as(true) %}
      <div class="search search-with-icon">
        <input type="text"
               class="form-control js-choice-table-search"
               autocomplete="off"
               placeholder="{{ 'Search'|trans({}, 'Admin.Actions') }}..."
        >
      </div>
    {% endif %}
    <div class="choice-table">
      <table class="table table-bordered mb-0">
        <thead>
        <tr>
          <th class="checkbox">
            <div class="md-checkbox">
              <label>
                <input
                    type="checkbox"
                    class="js-choice-table-select-all"
                    {% if isCheckSelectAll is defined and isCheckSelectAll %}
                      checked
                    {% endif %}
                >
                <i class="md-checkbox-control"></i>
                {{ 'Select all'|trans({}, 'Admin.Actions') }}
              </label>
            </div>
          </th>
        </tr>
        </thead>
        <tbody>
        {% for child in form %}
          <tr{% if searchable is defined and searchable is same as(true) %} class="js-choice-table-row" data-name="{{ child.vars.label }}"{% endif %}>
            <td>
              {{ form_widget(child, {'material_design': true}) }}
            </td>
          </tr>
        {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
{% endblock material_choice_table_widget %}

{% block _create_consignment_parcels_widget %}
  {% with {'child': prototype} %}
    <div {{ block('widget_container_attributes') }} data-prototype="{{ block('parcel_collection_item_widget')|e('html_attr') }}">
      <div class="js-parcel-collection-item-container">
        {% for child in form %}
          <div class="js-parcel-collection-item">
            {{ block('parcel_collection_item_widget') }}
          </div>
        {% endfor %}
      </div>

      <button type="button" class="js-add-parcel-collection-item btn btn-outline-primary">
        <i class="material-icons">add_circle</i>
        {{ 'Add another parcel'|trans({}, 'Modules.Glspoland.Consignment') }}
      </button>
    </div>
  {% endwith %}
{% endblock %}

{% block parcel_collection_item_widget %}
  <div class="input-group row">
    <div class="col-6">
      {{ form_label(child.reference) }}
      <div class="form-group">
        {{ form_widget(child.reference) }}
        {{ form_errors(child.reference) }}
      </div>
    </div>

    <div class="col-5">
      {{ form_label(child.weightKg) }}
      <div class="form-group">
        {{ form_widget(child.weightKg) }}
        {{ form_errors(child.weightKg) }}
      </div>
    </div>

    <div class="input-group-btn col-1 m-auto">
      <button type="button" class="js-remove-parcel-collection-item btn btn-outline-secondary float-right btn-sm" title="{{ 'Remove'|trans({}, 'Admin.Actions') }}">
        <i class="material-icons icon-delete">clear</i>
      </button>
    </div>
  </div>
{% endblock %}

{% block _create_consignment_serviceDetails_parcelShopId_widget %}
  {% if form.vars.required is same as(true) %}
    <div class="input-group js-parcel-shop-widget">
      {{ block('form_widget_simple') }}

      <div class="input-group-append">
        <button class="btn btn-outline-secondary js-parcel-shop-map-button" type="button">
          {{ 'Open map'|trans({}, 'Modules.Glspoland.Consignment') }}
        </button>
      </div>
    </div>
  {% else %}
    {{ block('hidden_widget') }}
  {% endif %}
{% endblock %}

{%- block number_widget -%}
  {%- set type = type|default('text') -%}
  <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 number_widget -%}

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

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

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

{%- block form_rest -%}
  {% import '@PrestaShop/Admin/macros.html.twig' as ps %}

  {% for child in form -%}
    {% if not child.rendered %}
      {% set inputType = child.vars.block_prefixes.1|default('text') %}
      {{- ps.form_group_row(child, { attr: child.vars.attr }, {
        'label': child.vars.label is same as(false) ? null : child.vars.label,
        'class': 'type-' ~ inputType
      }) -}}
    {% endif %}
  {%- endfor %}
{% endblock form_rest %}
