(()=>{"use strict";var t={n:e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},d:(e,o)=>{for(var d in o)t.o(o,d)&&!t.o(e,d)&&Object.defineProperty(e,d,{enumerable:!0,get:o[d]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wp.domReady;var o=t.n(e);const d=window.wp.hooks,n=window.wp.i18n,a=window.wp.element,r=window.dokan.components,i=window.wp.data,c=window.dokan.dokanUI,s=window.ReactJSXRuntime,u=()=>{const[t,e]=(0,a.useState)(!1),[o,u]=(0,a.useState)(0),_=(0,c.useToast)(),[p,l]=(0,a.useState)(!1),{updateProduct:w}=(0,i.useDispatch)("dokan/product-editor"),k=(0,a.useCallback)(({productId:t,newData:o})=>{if("dokan_advertise_this_product"in o&&o.dokan_advertise_this_product)return window.dokanProductEditor?.is_new_product?(w(t,{dokan_advertise_this_product:!1}),void _({type:"error",title:(0,n.__)("Please save the product before advertising.","dokan")})):(e(!0),void u(t))},[_,w]);return(0,a.useEffect)(()=>((0,d.addAction)("dokan_product_editor_field_changed","dokan-product-adv/field-change-listener",k),(0,d.addAction)("dokan_product_advertise_button_click","dokan-product-adv/button-click-listener",t=>{e(!0),u(t)}),()=>{(0,d.removeAction)("dokan_product_editor_field_changed","dokan-product-adv/field-change-listener"),(0,d.removeAction)("dokan_product_advertise_button_click","dokan-product-adv/button-click-listener")}),[k]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.DokanModal,{isOpen:t,onClose:()=>e(!1),namespace:"product-adv-action-modal-confirmation",onConfirm:async()=>{await(async t=>{const e=new FormData;e.append("action","dokan_add_advertise_product_to_cart"),e.append("advertise_product_nonce",dokanProductAdv.nonce),e.append("product_id",String(t));try{l(!0);const t=await fetch(dokanProductAdv.ajaxUrl,{method:"POST",body:e}),o=await t.json();o.success?(_({type:"success",title:o.message||(0,n.__)("Product successfully added to cart.","dokan")}),window.jQuery(document.body).trigger("wc_fragment_refresh")):_({type:"error",title:o.message||(0,n.__)("Something went wrong.","dokan")})}catch(t){_({type:"error",title:(0,n.__)("Something went wrong.","dokan")})}finally{l(!1)}})(o)},dialogTitle:(0,n.__)("Advertise Product","dokan-lite"),confirmButtonText:(0,n.__)("Advertise","dokan-lite"),confirmationTitle:(0,n.__)("Confirm Advertise","dokan-lite"),confirmationDescription:(0,n.__)("Are you sure you want to advertise this product?","dokan-lite"),isLoading:p}),(0,s.jsx)(c.DokanToaster,{})]})};o()(()=>{const t=document.createElement("div");t.id="dokan-product-adv-action-modal-root",t.className="dokan-layout",document.body.appendChild(t),(0,a.createRoot)(t).render((0,s.jsx)(u,{}))})})();