(()=>{"use strict";var t={n:a=>{var e=a&&a.__esModule?()=>a.default:()=>a;return t.d(e,{a:e}),e},d:(a,e)=>{for(var i in e)t.o(e,i)&&!t.o(a,i)&&Object.defineProperty(a,i,{enumerable:!0,get:e[i]})},o:(t,a)=>Object.prototype.hasOwnProperty.call(t,a)},a={};t.d(a,{default:()=>c});const e=window.wcStripe.utils,i=window.wp.apiFetch;var s=t.n(i);const r=window.wcStripe.actions;var n=t.n(r);const c=new class{processing=!1;constructor(){this.actions=n(),this.data=(0,e.getSetting)("cart"),this.page=(0,e.getSetting)("page"),this.actions.addAction("cart_dom_updated",this.onCartUpdated.bind(this)),this.actions.addAction("updated_checkout",this.onUpdatedCheckout.bind(this)),this.actions.addAction("cart_fragments_changed",this.onCartFragmentsChanged.bind(this)),this.actions.addAction("added_to_cart",this.onAddedToCart.bind(this)),this.actions.addAction("removed_from_cart",this.onRemovedFromCart.bind(this)),this.actions.addAction("product_updated",this.onProductUpdated.bind(this)),this.actions.addAction("mini_cart_updated",this.onMiniCartUpdated.bind(this))}update(t={}){try{this._prevData={...this.data},this.data={...this.data,...t},this.actions.doAction("cart_updated",this,t)}catch(t){console.error(t)}}hasChanged(t){return this._prevData?.[t]!==this.data[t]}async onCartUpdated(t,a=null){a?.cart?this.update(a.cart):await this.refreshData()}onMiniCartUpdated(t){t.extensions?.wc_stripe?.cart&&this.update(t.extensions.wc_stripe?.cart)}applyFilters(t,...a){return this.actions.applyFilters(t,...a)}async onUpdatedCheckout(t,a){let i={};if(a?.fragments?.wc_stripe_data){i=a.fragments.wc_stripe_data;const{cart:t,sdkParams:s=null}=i;this.data={...this.data,...t},s&&(0,e.setSetting)("sdkParams",queryParams)}}onCartFragmentsChanged(){setTimeout(()=>{window.wcStripeMiniCartData&&(this.update(window.wcStripeMiniCartData),window.wcStripeMiniCartData=null)},250)}onAddedToCart(t,a={}){a?.cart&&this.update(a.cart)}onRemovedFromCart(t,a=null){a?.cart&&this.update(a.cart)}async onProductUpdated(t){t.needsCartCalculation()&&this.actions.applyFilters("cart_calculation_enabled",!1,t,this)&&await this.cartCalculation()}getCurrency(){return this.actions.applyFilters("cart_get_currency",this.data.currency,this)}getCountryCode(){return this.data.countryCode}needsPayment(){return this.actions.applyFilters("cart_needs_payment",this.data?.needsPayment,this)}needsShipping(){return this.actions.applyFilters("cart_needs_shipping",this.data?.needsShipping,this)}isEmpty(){return this.data?.isEmpty}isPaymentMethodAvailable(t){var a;return null!==(a=this.data.paymentMethods?.[t]?.available)&&void 0!==a&&a}async refreshData(t=null){if(!this.processing)try{this.processing=!0;const t=await s()({method:"POST",url:(0,e.getRestRoute)("cart/refresh"),data:{page:this.page}});return this.update(t.cart),t}catch(t){console.log(t)}finally{this.processing=!1}}async addToCart(t){return s()({method:"POST",url:(0,e.getRestRoute)("cart/item"),data:t}).then(t=>(t.cart&&this.update(t.cart),t)).catch(t=>{throw t})}removeCartItem(t){return this.actions.doAction("before_remove_cart_item",this),s()({method:"DELETE",url:(0,e.getRestRoute)("cart/item"),data:{key:t}}).then(t=>{this.update(t.cart)}).catch(t=>{console.log("Error removing item from cart. ",t)}).finally(()=>{this.actions.doAction("after_remove_cart_item",this)})}async updateShipping(t){return s()({method:"POST",url:(0,e.getRestRoute)("cart/shipping"),data:t}).then(t=>(t.code||this.update(t),t)).catch(t=>{throw t})}async updateBilling(t){return s()({method:"POST",url:(0,e.getRestRoute)("cart/billing"),data:t}).then(t=>(t.code||this.update(t.cart),t)).catch(t=>{throw t})}cartCalculation(t={}){clearTimeout(this._calculationTimeout),this.actions.doAction("before_cart_calculation",t,this),this._calculationTimeout=setTimeout(async()=>{try{const a=await s()({method:"POST",url:(0,e.getRestRoute)("cart/calculation"),data:this.actions.applyFilters("cart_calculation_data",t,this)});a.cart&&this.update(a.cart)}catch(t){console.error("Cart calculation error:",t)}finally{this.actions.doAction("after_cart_calculation",this)}},250)}getTotal(t="string"){let a=this.data?.total||0;return this.actions.applyFilters("cart_total",a,this)}getTotalCents(){return this.actions.applyFilters("cart_total_cents",parseInt(this.data?.totalCents||0),this)}getSubtotalCents(){return this.actions.applyFilters("cart_subtotal_cents",parseInt(this.data?.subtotalCents||0),this)}getLineItems(){return this.data.lineItems||[]}getShippingOptions(){return this.data.shippingOptions||[]}getSelectedShippingMethod(){return this.data.selectedShippingMethod||""}};(this.wcStripe=this.wcStripe||{}).cart=a.default})();