(()=>{var e;e=jQuery,{init(){const n=e("#dokan-pro-connect-printful-btn"),t=e("#dokan-pro-disconnect-printful-btn"),o=e("#dokan-pro-printful-enable-shipping-toggle"),a=e("#dokan-pro-printful-enable-rates-toggle"),i=e("#dokan-printful-add-size-guide-btn");n&&n.on("click",this.connect),t&&t.on("click",this.disconnect),o&&o.on("change",this.enableShipping),a&&a.on("change",this.enableRates),i&&i.on("click",this.addSizeGuide),this.handleDependentFieldVisibility(a,o)},connect(n){n.preventDefault();const t=e(n.target),o=e("#dokan-pro-connect-printful-spiner"),a={_nonce:t.data("nonce"),action:"dokan_printful_connect_vendor_to_store"};o.show(),e.post(dokan.ajaxurl,a,e=>{!0===e.success?(o.hide(),window.location.replace(e.data)):(o.hide(),dokan_sweetalert("",{icon:"error",html:e.data}))})},async disconnect(n){n.preventDefault();const t=e(n.target),o=e("#dokan-pro-disconnect-printful-spiner"),a={_nonce:t.data("nonce"),action:"dokan_printful_disconnect_vendor_to_store"},i=await dokan_sweetalert(DokanPrintful.vendor_disconnect_alert_msg,{action:"confirm",icon:"warning"});"undefined"!==i&&i.isConfirmed&&(o.show(),e.post(dokan.ajaxurl,a,e=>{!0===e.success?dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout(()=>{o.hide(),window.location.reload()},2e3)}}):(o.hide(),dokan_sweetalert("",{icon:"error",html:e.data}))}))},enableShipping(n){const t=e(n.target),o={_nonce:t.data("nonce"),action:"dokan_printful_enable_shipping_toggle",value:this.checked?"yes":"no"},a=t.closest("#dokan-pro-printful-shipping-inputs-wrapper"),i=a.find("#dokan-pro-printful-enable-rates-toggle"),s=i.closest(".dokan-switch");this.checked?(i.prop("disabled",!1),s.removeClass("printful-settings-overlay")):(i.prop("checked")||(i.prop("checked",!0),i.trigger("change")),i.prop("disabled",!0),s.addClass("printful-settings-overlay")),a.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.post(dokan.ajaxurl,o,async e=>{!0===e.success?await dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout(()=>{a.unblock()},2e3)}}):(dokan_sweetalert("",{icon:"error",html:e.data}),a.unblock())})},enableRates(n){const t=e(n.target),o={_nonce:t.data("nonce"),action:"dokan_printful_enable_rates_toggle",value:this.checked?"yes":"no"},a=t.closest("#dokan-pro-printful-shipping-inputs-wrapper");a.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.post(dokan.ajaxurl,o,async e=>{!0===e.success?await dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout(()=>{a.unblock()},2e3)}}):(dokan_sweetalert("",{icon:"error",html:e.data}),a.unblock())})},addSizeGuide(n){n.preventDefault();const t=e(n.target),o=e("#dokan-printful-add-size-guide-spiner"),a={_nonce:t.data("nonce"),product_id:t.data("product_id"),catalog_id:t.data("catalog_id"),vendor_id:t.data("vendor_id"),action:"dokan_printful_add_size_guide"};o.show(),e.post(dokan.ajaxurl,a,async e=>{!0===e.success?await dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout(()=>{o.hide()},2e3)}}):(o.hide(),dokan_sweetalert("",{icon:"error",html:e.data}))})},handleDependentFieldVisibility(e,n){const t=n.prop("checked");e.closest(".dokan-switch").toggleClass("printful-settings-overlay",!t),t||e.prop("checked",!0).prop("disabled",!0)}}.init()})();