import{a as h,s as f,u,d as m,W as l,V as O,b as T}from"./sanitize.7727159a.js";const I=(e,t)=>{let c;return function(...o){clearTimeout(c),c=setTimeout(()=>e(...o),t)}},y=()=>!!h.getCartData().coupons.filter(t=>t.discount_type==="acfw_bogo").length,F={debounce:I,hasBOGOCoupon:y,sanitizeHtml:f},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:f(c)}})),React.createElement("div",{className:"wc-block-components-totals-item__description"},o)))},A={Accordion:v,OrderSummarySubtotalBlock:N},{extensionCartUpdate:x}=wc.blocksCheckout,D=()=>x({namespace:"acfwf_dummy_update",data:{}}),W={dummyUpdateCart:D};function q(){acfwfObj.components=A,acfwfObj.wc=W,acfwfObj.utils=F}const H=()=>{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:f(c.content)}})))):null};function J(){const{registerPlugin:e}=wp.plugins;e("acfw-coupons-summary",{render:H,scope:"woocommerce-checkout"})}const R="wc/checkout",C="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},B=e=>/<[^>]+>|&[a-z]+;/i.test(e),G=e=>e.find(t=>t.code==="woocommerce_rest_cart_coupon_error"&&B(t.message));function L(){const e=u(o=>o(l).getCartErrors()),t=u(o=>o(O).getValidationError("coupon")),c=G(e);if(c&&t){m(O).setValidationErrors({coupon:{message:" ",hidden:!1}});const o=c.message||"";m(d).createNotice("error",b(o),{context:C,id:p.ACFWF_NOTICE_CART_CONDITIONS})}}function M(){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:C,id:p.ACFWF_NOTICE_BOGO})})}const j="acfwf-wc-checkout-block",U={integration:j},{wcSettings:V}=wc,P=e=>V.getSetting("".concat(e,"_data")),k=jQuery,$=e=>{setTimeout(function(){m(d).createNotice("error",e,{context:R,id:p.ACFWF_NOTICE_STORE_CREDIT}),k(".acfw-reapply-sc-discount").on("click",z)},400)},z=()=>{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 K(){const e=u(s=>s(l).getHasCalculatedShipping()),{store_credits:t}=P(U.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&&$(o)}const Q=[C,R],X=()=>{Q.forEach(e=>{m(d).removeNotices(Object.values(p).filter(t=>t),e)}),L(),M(),K()};function Z(){const{registerPlugin:e}=wp.plugins;e("acfwf-notices",{render:X,scope:"woocommerce-checkout"})}export{J as a,U as c,P as g,q as i,Z as r};
