(()=>{"use strict";var e,o={981:()=>{const e=window.React,o=window.wp.components;window.wp.i18n;const t=window.wp.data,c=window.wp.element,{__,sprintf:n}=window.wp.i18n,{registerPlugin:r}=window.wp.plugins,{ExperimentalDiscountsMeta:s,extensionCartUpdate:a,registerCheckoutFilters:m}=window.wc.blocksCheckout,{CART_STORE_KEY:i,CHECKOUT_STORE_KEY:p}=window.wc.wcBlocksData,l=({extensions:n,cart:r,context:s})=>{const[m,p]=(0,c.useState)({}),{addItemToCart:l,removeItemFromCart:u}=(0,t.useDispatch)(i),[d,w]=(0,c.useState)({}),{hasCouponBeenApplied:h,appliedCoupons:g,hasCouponBeingRemoved:_}=(0,t.useSelect)(e=>{const o=e(i),t=o.getCartData(),c=o.getCouponBeingRemoved(),n="woocommerce-smart-coupons"in t.extensions?t.extensions["woocommerce-smart-coupons"]?.coupon_metadata:[];return{hasCouponBeenApplied:!("object"!=typeof t.extensions&&Object.keys(t.extensions).length<1)&&void 0!==t.extensions["woocommerce-smart-coupons"]&&Object.keys(t.extensions["woocommerce-smart-coupons"].coupon_metadata).length>0,appliedCoupons:n,hasCouponBeingRemoved:"string"==typeof c&&c.trim().length>0}},[]);return(0,c.useEffect)(()=>{if(h){let e={};g.length>0&&g.map((o,t)=>{const{code:c,action_tab_data:n=null}=o;null!==n&&(e[`${c}`]=n)}),w(e)}_&&p({})},[h,g,_]),(0,c.useEffect)(()=>{let e={};r?.cartItems.map(o=>{if(null!==o?.extensions["woocommerce-smart-coupons"]?.coupon_action?.wc_sc_product_source){let t=o?.extensions["woocommerce-smart-coupons"]?.coupon_action?.wc_sc_product_source;e[t]=o.id}}),p(o=>({...o,...e}))},[r?.cartItems]),(0,c.useEffect)(()=>{r?.cartItems.forEach(e=>{})},[r?.cartItems,m]),h?!("object"!=typeof n&&Object.keys(n).length<1)&&void 0!==n["woocommerce-smart-coupons"]&&Object.keys(n["woocommerce-smart-coupons"].coupon_metadata).length>0?(0,e.createElement)(o.Panel,{className:"wc-block-components-order-summary",header:Object.keys(n["woocommerce-smart-coupons"].coupon_metadata).length>1?__("Choose an option from each.","woocommerce-smart-coupon"):__("Choose an option.","woocommerce-smart-coupon")},Object.entries(n["woocommerce-smart-coupons"]?.coupon_metadata).map(([t,c])=>{const n=c?.settings?.message;return(0,e.createElement)(o.PanelBody,{title:n,initialOpen:!0},(0,e.createElement)(o.RadioControl,{options:c?.products?.length>0&&c?.products.map(o=>({label:(0,e.createElement)("div",{style:{display:"flex",alignItems:"center"}},(0,e.createElement)("img",{src:o.image,alt:o.name,style:{width:"50px",height:"50px",marginRight:"10px"}}),(0,e.createElement)("span",null,o.name)),value:`${o.id.toString()}`})),selected:void 0!==m[t]&&m[t].toString()||"",onChange:e=>((e,o,t)=>{const c=m[o];if(p(e=>({...e,[o]:t})),c&&c!==t){let e=r?.cartItems.filter(e=>o===e?.extensions["woocommerce-smart-coupons"]?.coupon_action?.wc_sc_product_source);e&&e.length>0&&(e=e.shift(),u(e?.key).then(()=>{console.log("Previous product removed from cart:",c)}).catch(e=>{console.error("Error removing previous product from cart:",e)}))}a({namespace:"woocommerce-smart-coupons",data:{action:"add_to_cart",data:{...e,coupon_code:o,product_id:t}}}).then(e=>{console.log("Item added to cart successfully"),console.log(e)}).catch(e=>{console.error("Error adding item to cart:",e)})})(c,t,e)}))})):(0,e.createElement)(e.Fragment,null):null},u=()=>(0,e.createElement)(s,null,(0,e.createElement)(l,null));r("woocommerce-smart-coupons-action-tab",{render:u,scope:"woocommerce-checkout"}),r("woocommerce-smart-coupons-cart",{render:u,scope:"woocommerce-cart"}),m("woocommerce-smart-coupons",{showRemoveItemLink:(e,o,t)=>{let c=o["woocommerce-smart-coupons"]?.coupon_action?.wc_sc_product_source;return!("cart"===t?.context&&"string"==typeof c&&c.trim().length>0)&&e}})}},t={};function c(e){var n=t[e];if(void 0!==n)return n.exports;var r=t[e]={exports:{}};return o[e](r,r.exports,c),r.exports}c.m=o,e=[],c.O=(o,t,n,r)=>{if(!t){var s=1/0;for(p=0;p<e.length;p++){for(var[t,n,r]=e[p],a=!0,m=0;m<t.length;m++)(!1&r||s>=r)&&Object.keys(c.O).every(e=>c.O[e](t[m]))?t.splice(m--,1):(a=!1,r<s&&(s=r));if(a){e.splice(p--,1);var i=n();void 0!==i&&(o=i)}}return o}r=r||0;for(var p=e.length;p>0&&e[p-1][2]>r;p--)e[p]=e[p-1];e[p]=[t,n,r]},c.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),(()=>{var e={405:0,134:0};c.O.j=o=>0===e[o];var o=(o,t)=>{var n,r,[s,a,m]=t,i=0;if(s.some(o=>0!==e[o])){for(n in a)c.o(a,n)&&(c.m[n]=a[n]);if(m)var p=m(c)}for(o&&o(t);i<s.length;i++)r=s[i],c.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return c.O(p)},t=globalThis.webpackChunksmart_coupon_blocks=globalThis.webpackChunksmart_coupon_blocks||[];t.forEach(o.bind(null,0)),t.push=o.bind(null,t.push.bind(t))})();var n=c.O(void 0,[134],()=>c(981));n=c.O(n)})();