import*as t from"@woocommerce/stores/woocommerce/cart";import*as e from"@wordpress/interactivity";import*as o from"@woocommerce/stores/woocommerce/products";var n={1401:e=>{e.exports=t}},a={};function r(t){var e=a[t];if(void 0!==e)return e.exports;var o=a[t]={exports:{}};return n[t](o,o.exports,r),o.exports}r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const i=(s={getContext:()=>e.getContext,store:()=>e.store,useLayoutEffect:()=>e.useLayoutEffect},c={},r.d(c,s),c);var s,c;r.d({},{});const m="I acknowledge that using a private store means my plugin will inevitably break on the next store release.";var d=function(t){return t.IDLE="IDLE",t.SLIDE_OUT="SLIDE-OUT",t.SLIDE_IN="SLIDE-IN",t}(d||{});const{state:u}=(0,i.store)("woocommerce",{},{lock:m}),{state:p}=(0,i.store)("woocommerce/add-to-cart-with-options",{},{lock:m}),{state:y}=(0,i.store)("woocommerce/products",{},{lock:m}),l={state:{get quantity(){const t=y.productInContext;if(!t)return 0;const e=(0,i.getContext)("woocommerce/add-to-cart-with-options"),o=u.findItemInCart({id:t.id,variation:e?.selectedAttributes});return o?.quantity??0},get slideInAnimation(){const{animationStatus:t}=(0,i.getContext)();return t===d.SLIDE_IN},get slideOutAnimation(){const{animationStatus:t}=(0,i.getContext)();return t===d.SLIDE_OUT},get addToCartText(){const{animationStatus:t,tempQuantity:e,addToCartText:o,groupedProductIds:n,hasPressedButton:a,inTheCartText:r}=(0,i.getContext)(),s=t===d.IDLE||t===d.SLIDE_OUT?e||0:I.quantity;if("grouped"===y.productInContext?.type){const t=n?.map(t=>{const e=u.findItemInCart({id:t});return e?.quantity||0});return t?.some(t=>t>0)&&a?r:o}return s>0?r.replace("###",s.toString()):o},get displayViewCart(){const{displayViewCart:t}=(0,i.getContext)();return!!t&&I.quantity>0}},actions:{*addCartItem(){const t=y.productInContext;if(!t)return;yield Promise.resolve().then(r.bind(r,1401));const{actions:e}=(0,i.store)("woocommerce",{},{lock:m}),o=(0,i.getContext)();yield e.addCartItem({id:t.id,quantityToAdd:o.quantityToAdd,type:t.type},{showCartUpdatesNotices:!1}),o.displayViewCart=!0},*refreshCartItems(){yield Promise.resolve().then(r.bind(r,1401));const{actions:t}=(0,i.store)("woocommerce",{},{lock:m});t.refreshCartItems()},handleAnimationEnd(t){const e=(0,i.getContext)();"slideOut"===t.animationName?e.animationStatus=d.SLIDE_IN:"slideIn"===t.animationName&&(e.tempQuantity=I.quantity,e.animationStatus=d.IDLE)},handlePressedState(){const t=(0,i.getContext)();(void 0===p?.isFormValid||p?.isFormValid)&&(t.hasPressedButton=!0,t.tempQuantity!==I.quantity&&t.animationStatus===d.IDLE&&(t.animationStatus=d.SLIDE_OUT))}},callbacks:{syncTempQuantityOnLoad(){const t=(0,i.getContext)();(0,i.useLayoutEffect)(()=>{t.tempQuantity=I.quantity},[])},startAnimation(){const t=(0,i.getContext)();t.tempQuantity!==I.quantity&&t.animationStatus===d.IDLE&&(t.animationStatus=d.SLIDE_OUT)}}},{state:I}=(0,i.store)("woocommerce/product-button",l,{lock:!0});