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

      <div class="isl-margin">
        Seçilen kategorilerdeki ürünlere:
      </div>
      <div class="isl-margin isl-w-l">
        <input type="text" placeholder="Type category name" data-isl-autocomplete='{"type":"category", "target":"isl-autocomplete-a", "name":"{{ module_setting }}[condition_category_ids][]"}' class="form-control input-sm">
        <div class="well well-sm isl-well isl-autocomplete-a">
          {% for category in condition_category_ids_data %}
            <div class="isl-autocomplete-a{{ category['category_id'] }}"><i class="fa fa-minus-circle pointer"></i> {{ category['path'] ? category['path'] ~ '&nbsp;&nbsp;&gt;&nbsp;&nbsp;' ~ category['name'] : category['name'] }}<input type="hidden" name="{{ module_setting }}[condition_category_ids][]" value="{{ category['category_id'] }}"></div>
          {% endfor %}
        </div>
      </div>

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

      <div class="isl-margin">
       sabit veya yüzde
        <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>
        olarak indirimi uygula:
      </div>
      <div class="isl-margin isl-w-l">
        <table class="table table-hover">
          <thead>
            <tr>
              <th style="width:140px">Minimum Miktar</th>
              <th>İndirim</th>
              <th class="text-center" style="width:50px">
                <a class="btn btn-sm btn-primary btn-add-tier btn-xs"><i class="fa fa-plus"></i></a>
              </th>
            </tr>
          </thead>
          <tbody class="xoffitemsinycategoriestiered-table">
            {% if not condition_min_quantities_data %}
              <tr>
                <td>
                  <input type="number" name="{{ module_setting }}[condition_min_quantities][]" value="1" min="1" class="form-control input-sm isl-inline-block isl-w-xs 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"></td>
              </tr>
            {% endif %}

            {% set i = 0 %}
            {% for tier in condition_min_quantities_data %}
              <tr>
                <td>
                  <input type="number" name="{{ module_setting }}[condition_min_quantities][]" value="{{ tier['quantity'] }}" min="1" class="form-control input-sm isl-inline-block isl-w-xs 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="tier-template" class="hidden" hidden>
<tr>
  <td>
    <input type="number" name="{{ module_setting }}[condition_min_quantities][]" value="1" min="1" class="form-control input-sm isl-inline-block isl-w-xs 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-tier btn-xs"><i class="fa fa-minus"></i></a>
  </td>
</tr>
</template>

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

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

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