import{c as h,s as C,u,d as m,W as l,V as O,b as T}from"./sanitize.d66553f0.js";const I=(e,t)=>{let c;return function(...o){clearTimeout(c),c=setTimeout(()=>e(...o),t)}},y="acfw_bogo",F=()=>!!h.getCartData().coupons.filter(t=>t.discount_type===y).length,A={debounce:I,hasBOGOCoupon:F,sanitizeHtml:C},v=e=>{const{useState:t,useEffect:c,useRef:o}=wp.element,{title:n,children:s,caret_img_src:a,auto_display_store_credits_redeem_form:_}=e,[g,E]=t(!1),r=o(null),w=()=>{if(E(!g),r.current){let i=r.current.style.maxHeight;i=parseInt(i.replace("px","")),i=i>0?0:r.current.scrollHeight,r.current.style.maxHeight="".concat(i,"px")}},S=()=>{if(a)return React.createElement("span",{className:"caret"},React.createElement("img",{src:a}))};return c(()=>{_==="yes"&&(E(!0),w())},[_]),React.createElement("div",{className:"acfw-accordion"},React.createElement("div",{className:"acfw-accordion acfw-store-credits-checkout-ui ".concat(g?"show":"")},React.createElement("h3",{onClick:w},React.createElement("span",{className:"acfw-accordion-title"},n),S()),React.createElement("div",{className:"acfw-accordion-inner",ref:r},React.createElement("div",{className:"acfw-accordion-content"},s))))},N=e=>{const{label:t,value:c,children:o}=e;return React.createElement("div",{className:"wp-block-woocommerce-checkout-order-summary-subtotal-block wc-block-components-totals-wrapper"},React.createElement("div",{className:"wc-block-components-totals-item"},React.createElement("span",{className:"wc-block-components-totals-item__label"},t),React.createElement("span",{className:"wc-block-components-totals-item__value"},React.createElement("div",{dangerouslySetInnerHTML:{__html:C(c)}})),React.createElement("div",{className:"wc-block-components-totals-item__description"},o)))},x={Accordion:v,OrderSummarySubtotalBlock:N},{extensionCartUpdate:D}=wc.blocksCheckout,W=()=>D({namespace:"acfwf_dummy_update",data:{}}),H={dummyUpdateCart:W};function J(){acfwfObj.components=x,acfwfObj.wc=H,acfwfObj.utils=A}const B=()=>{const e=u(c=>{var s;const o=c("wc/store/cart").getCartData(),{acfwf_block:n}=o.extensions;return!n||!n.couponSummaries?[]:(s=n.couponSummaries)!=null?s:[]}),{ExperimentalDiscountsMeta:t}=wc.blocksCheckout;return e.length?React.createElement(t,null,e.map(c=>React.createElement(N,{label:c.coupon_code},React.createElement("div",{className:"acfwf-bogo-discount-summary-block",dangerouslySetInnerHTML:{__html:C(c.content)}})))):null};function Z(){const{registerPlugin:e}=wp.plugins;e("acfw-coupons-summary",{render:B,scope:"woocommerce-checkout"})}const R="wc/checkout",f="wc/cart",d="core/notices",p={ACFWF_NOTICE_BOGO:"ACFWF_NOTICE_BOGO",ACFWF_NOTICE_CART_CONDITIONS:"ACFWF_NOTICE_CART_CONDITIONS",ACFWF_NOTICE_STORE_CREDIT:"ACFWF_NOTICE_STORE_CREDIT"},b=e=>{let t=document.createElement("div");return t.innerHTML=e,t.textContent||t.innerText},G=e=>/<[^>]+>|&[a-z]+;/i.test(e),L=e=>e.find(t=>t.code==="woocommerce_rest_cart_coupon_error"&&G(t.message));function M(){const e=u(o=>o(l).getCartErrors()),t=u(o=>o(O).getValidationError("coupon")),c=L(e);if(c&&t){m(O).setValidationErrors({coupon:{message:" ",hidden:!1}});const o=c.message||"";m(d).createNotice("error",b(o),{context:f,id:p.ACFWF_NOTICE_CART_CONDITIONS})}}function j(){const e=u(a=>a(l).getCartData()),{dummyUpdateCart:t}=acfwfObj.wc,c=T(l).isApplyingCoupon(),o=T(l).isRemovingCoupon();(c||o)&&t();const{acfwf_block:n}=e.extensions;if(!n||!n.bogo_deals)return null;const s=n.bogo_deals;s&&s.forEach(a=>{m(d).createNotice("info",b(a),{context:f,id:p.ACFWF_NOTICE_BOGO})})}const U="acfwf-wc-checkout-block",P={integration:U},{wcSettings:V}=wc,$=e=>V.getSetting("".concat(e,"_data")),k=jQuery,z=e=>{setTimeout(function(){m(d).createNotice("error",e,{context:R,id:p.ACFWF_NOTICE_STORE_CREDIT}),k(".acfw-reapply-sc-discount").on("click",K)},400)},K=()=>{const e=k(".acfw-checkout-ui-block"),t=e.find(".acfw-store-credits-checkout-ui"),c=e.find("h3");t.hasClass("show")||c.trigger("click"),setTimeout(function(){var n;window.scroll({top:(n=e==null?void 0:e.offset())==null?void 0:n.top,behavior:"smooth"}),e.find("input").trigger("focus")},400)};function Y(){const e=u(s=>s(l).getHasCalculatedShipping()),{store_credits:t}=$(P.integration);if(!t)return null;const{apply_type:c,notice_store_credits_text:o}=t,{acfwf_block:n}=h.getCartData().extensions;c!=="coupon"&&e&&n.store_credits.notice&&z(o)}const Q=[f,R],X=()=>{Q.forEach(e=>{m(d).removeNotices(Object.values(p).filter(t=>t),e)}),M(),j(),Y()};function ee(){const{registerPlugin:e}=wp.plugins;e("acfwf-notices",{render:X,scope:"woocommerce-checkout"})}export{y as A,Z as a,P as c,$ as g,J as i,ee as r};
