{{ header }}
<div id="root">
  <div class="page-loader" v-show="isLoading"></div>

  <validation-observer ref="validationObserver" tag="div" v-slot="{ handleSubmit }">
    <form
      ref="form"
      @submit.prevent="handleSubmit(onSubmit)"
      action="{{ data.action }}"
      method="post">

      <the-header
        title="{{ heading_title }}"
        :breadcrumbs='{{ breadcrumbs|json_encode() }}'>

        <base-button
          href="{{ data.back }}"
          apperance="outline">
          {{ button_cancel }}
        </base-button>
        <base-button
          type="submit"
          :disabled="disableForm"
          :loading="btnSubmitLoading">
          {{ button_save }}
        </base-button>

        <template #notification>
          <base-alert
            v-show="alert.type"
            :apperance="alert.type"
            @close="alert = {}">
            <span v-text="alert.message"></span>
          </base-alert>
        </template>
      </the-header>

      <div class="container-fluid">
        <div class="row">
          <div class="col-xs-12 col-sm-8">
            <base-card
              class="padding-large bottom-margin-medium"
              v-for="(discount, discountIndex) in configurations.desconto_tipo_pagamento"
              :key="discountIndex">

              <div class="row small-space-xs">
                <div class="col-xs-12 col-sm-6">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][text_desconto]`
                    rules=""
                    v-slot="{ errors, valid }">
                    <base-input
                      label="{{ entry_text_desconto }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][text_desconto]`
                      v-model="discount.text_desconto"
                      :error="errors[0]"
                      :valid="valid"
                      mask="alphanumeric"
                      maxlength="35"
                      :disabled="disableForm">
                    </base-input>
                  </validation-provider>
                </div>
                <div class="col-xs-6 col-sm-4">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][pagamento_desconto]`
                    rules="required"
                    v-slot="{ errors, valid }">
                    <base-select
                      label="{{ entry_forma_pagamento }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][pagamento_desconto]`
                      v-model="discount.pagamento_desconto"
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                      {% for  key, tipo_pagamento in tipos_pagamento %}
                        <option value="{{ tipo_pagamento.arquivo }}">{{ tipo_pagamento.title }}</option>
                      {% endfor %}
                    </base-select>
                  </validation-provider>
                </div>
                <div class="col-xs-6 col-sm-2">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][prioridade_desconto]`
                    rules=""
                    v-slot="{ errors, valid }">
                    <base-input
                      label="{{ entry_prioridade }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][prioridade_desconto]`
                      v-model="discount.prioridade_desconto"
                      mask="positiveInteger"
                      maxlength="2"
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                    </base-input>
                  </validation-provider>
                </div>

                <div class="col-xs-12 col-sm-2">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][val_desconto]`
                    rules="required|minmax_number:0,100"
                    v-slot="{ errors, valid }">
                    <base-input
                      label="{{ entry_desconto }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][val_desconto]`
                      v-model="discount.val_desconto"
                      mask="percentage"
                      required
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                    </base-input>
                  </validation-provider>
                </div>
                <div class="col-xs-6 col-sm-4">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][modo_desconto]`
                    rules="required"
                    v-slot="{ errors, valid }">
                    <base-select
                      label="{{ entry_modo_desconto }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][modo_desconto]`
                      v-model="discount.modo_desconto"
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                      <option value="0">{{ text_desc_sobre_total }}</option>
                      <option value="1">{{ text_desc_sobre_desc }}</option>
                    </base-select>
                  </validation-provider>
                </div>
                <div class="col-xs-6 col-md-3">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][valor_minimo]`
                    rules=""
                    v-slot="{ errors, valid }">
                    <base-input
                      label="{{ entry_valor_minimo }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][valor_minimo]`
                      v-model="discount.valor_minimo"
                      mask="brazilCurrency"
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                    </base-input>
                  </validation-provider>
                </div>
                <div class="col-xs-6 col-sm-3">
                  <validation-provider
                    tag="div"
                    :name=`desconto_tipo_pagamento[${discountIndex}][status_desconto]`
                    rules="required"
                    v-slot="{ errors, valid }">
                    <base-select
                      label="{{ entry_status }}"
                      :name=`desconto_tipo_pagamento[${discountIndex}][status_desconto]`
                      v-model="discount.status_desconto"
                      :error="errors[0]"
                      :valid="valid"
                      :disabled="disableForm">
                      {% for  key, value in Type_Status %}
                        <option value="{{ key }}">{{ value }}</option>
                      {% endfor %}
                    </base-select>
                  </validation-provider>
                </div>

                <div class="col-xs-12">
                  <group-checkbox
                    v-if="customerGroups"
                    label='{{ text_tabelas_preco }}'>

                    <base-checkbox
                      label="Todos"
                      :name=`desconto_tipo_pagamento[${discountIndex}][tabela_preco][]`
                      v-model="discount.tabela_preco"
                      value="0"
                      @change="() => onChangeTablePrice(discountIndex)">
                    </base-checkbox>

                    <base-checkbox
                      v-for="(customerGroup, index) in customerGroups"
                      :key="index"
                      :label="customerGroup.name"
                      :name=`desconto_tipo_pagamento[${discountIndex}][tabela_preco][]`
                      v-model="discount.tabela_preco"
                      :value="customerGroup.customer_group_id"
                      :disabled="discount.tabela_preco[0] == 0"
                      @change="() => onChangeTablePrice(discountIndex)">
                    </base-checkbox>
                  </group-checkbox>
                </div>
                <div class="col-xs-12">
                  <base-button
                    apperance="outline"
                    @click.native="() => onRemoveDiscount(discountIndex)">
                    {{ button_remove }}
                  </base-button>
                </div>
              </div>

            </base-card>
          </div>

          <div class="col-xs-12 col-sm-4">
            <base-card class="padding-large">
              <validation-provider
                tag="div"
                name="descontoporpagamento_status"
                rules="required"
                v-slot="{ errors, valid }">
                <base-select
                  label="{{ entry_status }}"
                  name="descontoporpagamento_status"
                  v-model="configurations.descontoporpagamento_status"
                  :error="errors[0]"
                  :valid="valid"
                  :disabled="disableForm">
                  {% for  key, value in Type_Status %}
                    <option value="{{ key }}">{{ value }}</option>
                  {% endfor %}
                </base-select>
              </validation-provider>

              <validation-provider
                tag="div"
                name="descontoporpagamento_sort_order"
                class="top-margin-large"
                rules="numeric"
                v-slot="{ errors, valid }">
                <base-input
                  label="{{ entry_ordem }}"
                  name="descontoporpagamento_sort_order"
                  v-model="configurations.descontoporpagamento_sort_order"
                  mask="positiveInteger"
                  maxlength="2"
                  :error="errors[0]"
                  :valid="valid"
                  :disabled="disableForm">
                </base-input>
              </validation-provider>

            </base-card>

            <base-button @click.native="onAddDiscount" class="top-margin-large">
              {{ button_add_Desconto_Pagamento }}
            </base-button>
          </div>

        </div>
      </div>

    </form>
  <validation-observer>
</div>



<script>
  const DATA = {{ data|json_encode() }};
</script>
{{ footer }}
