<ul class="isl-nodetree">
  <li>
    <div>

      <div class="isl-margin">
		İndirim Tipi
        <select name="{{ module_setting }}[discount_type]" class="form-control input-sm isl-inline-block isl-w-xs isl-mh-5">
          <option value="fixed" {{ setting['item']['discount_type'] == 'fixed' ? 'selected' : '' }}>{{ currency }}</option>
          <option value="percentage" {{ setting['item']['discount_type'] == 'percentage' ? 'selected' : '' }}>%</option>
        </select>
      </div>
      <div class="isl-margin isl-w-l">
        <table class="table table-hover">
          <thead>
            <tr>
              <th style="width:140px">Min. sipariş tutarı</th>
              <th>İndirim</th>
              <th class="text-center" style="width:50px">
                <a class="btn btn-sm btn-primary btn-add-value btn-xs"><i class="fa fa-plus"></i></a>
              </th>
            </tr>
          </thead>
          <tbody class="xamountoffwhenxormore-table">
            {% if not condition_min_amounts_data %}
              <tr>
                <td>
                  {{ currency }} <input type="text" name="{{ module_setting }}[condition_min_amounts][]" value="" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td>
                  <input type="text" name="{{ module_setting }}[discount_values][]" value="" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td></td>
              </tr>
            {% endif %}

            {% set i = 0 %}
            {% for tier in condition_min_amounts_data %}
              <tr>
                <td>
                  {{ currency }} <input type="text" name="{{ module_setting }}[condition_min_amounts][]" value="{{ tier['amount'] }}" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td>
                  <input type="text" name="{{ module_setting }}[discount_values][]" value="{{ tier['discount'] }}" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td class="text-center">
                  {% if i > 0 %}
                    <a class="btn btn-sm btn-danger btn-remove-tier btn-xs"><i class="fa fa-minus"></i></a>
                  {% endif %}
                </td>
              </tr>
              {% set i = i + 1 %}
            {% endfor %}
          </tbody>
        </table>
      </div>

    </div>
  </li>
</ul>

<template id="value-template" class="hidden" hidden>
<tr>
  <td>
    {{ currency }} <input type="text" name="{{ module_setting }}[condition_min_amounts][]" value="" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
  </td>
  <td>
    <input type="text" name="{{ module_setting }}[discount_values][]" value="" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
  </td>
  <td class="text-center">
    <a class="btn btn-sm btn-danger btn-remove-value btn-xs"><i class="fa fa-minus"></i></a>
  </td>
</tr>
</template>

<script>
$(document).trigger('isl.autocomplete');

$('.btn-add-value').on('click', function () {
  var tier = $('#value-template').html();
  $('.xamountoffwhenxormore-table').append(tier);
});

$('.xamountoffwhenxormore-table').on('click', '.btn-remove-value', function () {
  $(this).closest('tr').remove();
});
</script>
