<script>
  function updateTargetVisibility() {
    var applies = $('#applies_to').val();
    $('.target').addClass('d-none');
    if (applies === 'PRODUCT') $('.target-product').removeClass('d-none');
    if (applies === 'PRODUCT_CATEGORY') $('.target-product-category').removeClass('d-none');
    if (applies === 'SERVICE') $('.target-service').removeClass('d-none');
    if (applies === 'SERVICE_CATEGORY') $('.target-service-category').removeClass('d-none');
  }
  $(document).ready(function() {
    $('.form-validate').validate();
    $('.select2').select2();
    updateTargetVisibility();
    $('#applies_to').on('change', updateTargetVisibility);
  });
</script>

