const S=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,w]=t(!1),r=o(null),E=()=>{if(w(!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")}},k=()=>{if(a)return React.createElement("span",{className:"caret"},React.createElement("img",{src:a}))};return c(()=>{_==="yes"&&(w(!0),E())},[_]),React.createElement("div",{className:"acfw-accordion"},React.createElement("div",{className:"acfw-accordion acfw-store-credits-checkout-ui ".concat(g?"show":"")},React.createElement("h3",{onClick:E},React.createElement("span",{className:"acfw-accordion-title"},n),k()),React.createElement("div",{className:"acfw-accordion-inner",ref:r},React.createElement("div",{className:"acfw-accordion-content"},s))))},T=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}})),React.createElement("div",{className:"wc-block-components-totals-item__description"},o)))},I={Accordion:S,OrderSummarySubtotalBlock:T},{extensionCartUpdate:y}=wc.blocksCheckout,F=()=>y({namespace:"acfwf_dummy_update",data:{}}),v={dummyUpdateCart:F},A=(e,t)=>{let c;return function(...o){clearTimeout(c),c=setTimeout(()=>e(...o),t)}},{subscribe:X,select:C,dispatch:u,useSelect:m,useDispatch:Y}=wp.data,{VALIDATION_STORE_KEY:O}=wc.wcBlocksData,l="wc/store/cart",h=C("wc/store/cart"),x=()=>!!h.getCartData().coupons.filter(t=>t.discount_type==="acfw_bogo").length,D={debounce:A,hasBOGOCoupon:x};function q(){acfwfObj.components=I,acfwfObj.wc=v,acfwfObj.utils=D}const W=()=>{const e=m(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(T,{label:c.coupon_code},React.createElement("div",{className:"acfwf-bogo-discount-summary-block",dangerouslySetInnerHTML:{__html:c.content}})))):null};function J(){const{registerPlugin:e}=wp.plugins;e("acfw-coupons-summary",{render:W,scope:"woocommerce-checkout"})}const N="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"},R=e=>{let t=document.createElement("div");return t.innerHTML=e,t.textContent||t.innerText},H=e=>/<[^>]+>|&[a-z]+;/i.test(e),B=e=>e.find(t=>t.code==="woocommerce_rest_cart_coupon_error"&&H(t.message));function G(){const e=m(o=>o(l).getCartErrors()),t=m(o=>o(O).getValidationError("coupon")),c=B(e);if(c&&t){u(O).setValidationErrors({coupon:{message:" ",hidden:!1}});const o=c.message||"";u(d).createNotice("error",R(o),{context:f,id:p.ACFWF_NOTICE_CART_CONDITIONS})}}function L(){const e=m(a=>a(l).getCartData()),{dummyUpdateCart:t}=acfwfObj.wc,c=C(l).isApplyingCoupon(),o=C(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=>{u(d).createNotice("info",R(a),{context:f,id:p.ACFWF_NOTICE_BOGO})})}const M="acfwf-wc-checkout-block",j={integration:M},{wcSettings:U}=wc,P=e=>U.getSetting("".concat(e,"_data")),b=jQuery,V=e=>{setTimeout(function(){u(d).createNotice("error",e,{context:N,id:p.ACFWF_NOTICE_STORE_CREDIT}),b(".acfw-reapply-sc-discount").on("click",$)},400)},$=()=>{const e=b(".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=m(s=>s(l).getHasCalculatedShipping()),{store_credits:t}=P(j.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&&V(o)}const z=[f,N],Q=()=>{z.forEach(e=>{u(d).removeNotices(Object.values(p).filter(t=>t),e)}),G(),L(),K()};function Z(){const{registerPlugin:e}=wp.plugins;e("acfwf-notices",{render:Q,scope:"woocommerce-checkout"})}export{J as a,j as c,P as g,q as i,Z as r,h as s};
