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

      <div class="isl-margin">
        Discount type
        <select name="<?php echo $module_setting; ?>[discount_type]" class="form-control input-sm isl-inline-block isl-w-xs isl-mh-5">
          <option value="fixed" <?php echo $setting['item']['discount_type'] == 'fixed' ? 'selected' : ''; ?>><?php echo $currency; ?></option>
          <option value="percentage" <?php echo $setting['item']['discount_type'] == 'percentage' ? 'selected' : ''; ?>>%</option>
        </select> off
      </div>
      <div class="isl-margin isl-w-l">
        <table class="table table-hover">
          <thead>
            <tr>
              <th style="width:140px">Min. order value</th>
              <th>Discount value</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">
            <?php if (!$condition_min_amounts_data) { ?>
              <tr>
                <td>
                  <?php echo $currency; ?> <input type="text" name="<?php echo $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="<?php echo $module_setting; ?>[discount_values][]" value="" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td></td>
              </tr>
            <?php } ?>

            <?php $i=0; foreach ($condition_min_amounts_data as $tier) { ?>
              <tr>
                <td>
                  <?php echo $currency; ?> <input type="text" name="<?php echo $module_setting; ?>[condition_min_amounts][]" value="<?php echo $tier['amount']; ?>" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td>
                  <input type="text" name="<?php echo $module_setting; ?>[discount_values][]" value="<?php echo $tier['discount']; ?>" class="form-control input-sm isl-inline-block isl-w-s isl-mh-5" required>
                </td>
                <td class="text-center">
                  <?php if ($i > 0) { ?>
                    <a class="btn btn-sm btn-danger btn-remove-tier btn-xs"><i class="fa fa-minus"></i></a>
                  <?php } ?>
                </td>
              </tr>
            <?php $i++; } ?>
          </tbody>
        </table>
      </div>

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

<template id="value-template" class="hidden" hidden>
<tr>
  <td>
    <?php echo $currency; ?> <input type="text" name="<?php echo $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="<?php echo $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>
