jQuery((function(e){let n=e(".shopengine_coupon_country").data("selected"),o=e(".shopengine_coupon_country_state").data("selected"),t=JSON.parse(shopengine_advanced_coupon.country),i=e(".shopengine_coupon_payment_method").data("selected");function p(n){let i=function(e){let n=[],o=t[e];for(let e in o)o.hasOwnProperty(e)&&n.push({id:e,text:o[e]});return n}(n);0===i.length?e(".shopengine_coupon_country_state").prop("disabled",!0):e(".shopengine_coupon_country_state").prop("disabled",!1),e(".shopengine_coupon_country_state").empty().select2({allowClear:!0,multiple:!0,placeholder:"Select states",data:i}).val(o).trigger("change")}e(".shopengine_coupon_country").select2({allowClear:!0,placeholder:"Select a country"}).val(n).trigger("change"),p(n),e(".shopengine_coupon_country").change((function(e){p(e.target.value)})),e(".shopengine_coupon_payment_method").select2({allowClear:!0,multiple:!0,placeholder:"Select payment methods",data:JSON.parse(shopengine_advanced_coupon.payment_methods)}).val(i).trigger("change"),e('input[name="shopengine_bulk_coupon_status"]').prop("checked",!1),e(".shopengine_bulk_coupon_status").change((function(n){n.target.checked?(e("#titlewrap").css("display","none"),e("#misc-publishing-actions").css("display","none"),e(".shopengine_bulk_coupon").css("display","block"),e("#shopengine_number_of_digit").attr("required",!0),e("#shopengine_coupon_length").attr("required",!0),e("#shopengine_coupon_identifier").attr("required",!0),e("#shopengine_coupon_action").attr("required",!0)):(e("#shopengine_number_of_digit").removeAttr("required"),e("#shopengine_coupon_length").removeAttr("required"),e("#shopengine_coupon_identifier").removeAttr("required"),e("#shopengine_coupon_action").removeAttr("required"),e("#titlewrap").css("display","block"),e("#misc-publishing-actions").css("display","block"),e(".shopengine_bulk_coupon").css("display","none"))})),e("#publish").click((function(n){if(e('input[name="shopengine_bulk_coupon_status"]').prop("checked")){let o=e("#shopengine_coupon_length").val();if(o){o=parseInt(o),o-(e("#shopengine_coupon_prefix").val().length+e("#shopengine_coupon_suffix").val().length)<5&&(alert("Dynamic coupon code's character length must be at least 5 characters, excluding prefix and suffix."),n.preventDefault())}}})),e(".shopengine-export-coupon").click((function(){let n=e("#shopengine_coupon_identifier").val();if(0!=n){let e=new URL(shopengine_advanced_coupon.export_api);e.searchParams.set("term",n),window.location=e.href}else alert("Please Select a Coupon identifier")}))}));