<style type="text/css">
  .coupon-categories-box {
    max-height: 420px;
    overflow: auto;
    border: 1px solid #d6d6d6;
    border-radius: 4px;
    padding: 8px 10px;
    background: #fff;
  }

  .coupon-categories-tree {
    margin: 0;
    padding: 0 0 0 16px;
    list-style: none;
  }

  .coupon-category-item {
    margin: 2px 0;
  }

  .coupon-category-item.is-collapsed > ol {
    display: none;
  }

  .coupon-category-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
  }

  .coupon-tree-toggle,
  .coupon-tree-spacer {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    padding: 0;
  }

  .coupon-tree-toggle {
    cursor: pointer;
    color: #666;
  }

  .coupon-tree-toggle:focus,
  .coupon-tree-toggle:active,
  .coupon-tree-toggle:focus-visible {
    outline: none;
    box-shadow: none;
  }

  .coupon-category-item:not(.is-collapsed) > .coupon-category-row .coupon-tree-toggle i {
    transform: rotate(90deg);
  }

  .coupon-category-label {
    margin: 0;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .coupon-category-row .icheckbox_minimal-blue {
    margin-top: 0;
  }
</style>

<script type="text/javascript">
  (function($) {
    if (!$) {
      return;
    }

    $(document).off('click.shopCouponTree', '.coupon-tree-toggle');
    $(document).on('click.shopCouponTree', '.coupon-tree-toggle', function(e) {
      e.preventDefault();
      var $item = $(this).closest('.coupon-category-item');
      $item.toggleClass('is-collapsed');
      $(this).attr('aria-expanded', $item.hasClass('is-collapsed') ? 'false' : 'true');
      this.blur();
    });

    function initCouponCategoryCheckboxes() {
      if (!$.fn || typeof $.fn.iCheck !== 'function') {
        return;
      }

      $('.coupon-categories-box .g-checkbox').each(function() {
        var $checkbox = $(this);
        if ($checkbox.parent().hasClass('icheckbox_minimal-blue')) {
          return;
        }

        $checkbox.iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
      });
    }

    initCouponCategoryCheckboxes();
  })(window.jQuery);
</script>
