{"version":3,"file":"AddToCart.BA68FPXT.mjs","names":["useState","__esmMin","init_npm_react_18_3_1","_e","p","c","init_jsx_runtime","ce","init_framer_CaDWdxiz","addPropertyControls","ControlType","isCanvas","init_ShopCore","useProducts","useShopActive","maxFor","cartActions","formatMoney","T","buttonStyle","AddToCart","props","active","qty","setQty","added","setAdded","id","variationId","product","products","max","t","root","style","legacyUrl","legacyLabel","note","disabled","label","endsAt","ENDED_AFTER_MS","error","showQuantity","stepBtn","q","init_AddToCart","LEGACY_STORE_URL"],"sources":["https:/framerusercontent.com/modules/Hk6OaQlEALdSAw57coJB/dk4XmtQR7XMVyyYVlUdX/AddToCart.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{T,buttonStyle,formatMoney,useProducts,useShopActive,cartActions,maxFor,isCanvas,LEGACY_STORE_URL}from\"https://framerusercontent.com/modules/KV4rrzD9WIN7jZRg2JY1/Hjl5FWjHofQwd0cdxi6J/ShopCore.js\";const stepBtn={appearance:\"none\",width:44,height:46,border:\"none\",background:\"transparent\",color:T.strong,fontFamily:T.display,fontSize:20,cursor:\"pointer\"};// Class dates are stored as 23:00Z on the class day, so a class counts as over 12 hours later (same as ClassDateGate).\nconst ENDED_AFTER_MS=12*60*60*1e3;/**\n * Add to cart button for one Square item variation, with live price and stock.\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function AddToCart(props){const{variationId,legacyUrl,legacyLabel,showQuantity,endsAt,style}=props;const active=useShopActive();const{products,error}=useProducts();const[qty,setQty]=useState(1);const[added,setAdded]=useState(false);const id=(variationId||\"\").trim();const product=products?products.find(p=>p.variationId===id):null;const max=maxFor(product);useEffect(()=>{if(!added)return;const t=setTimeout(()=>setAdded(false),1800);return()=>clearTimeout(t);},[added]);useEffect(()=>{if(max>0&&qty>max)setQty(max);},[max]);const root={display:\"flex\",flexDirection:\"column\",gap:8,fontFamily:T.bodyFont,...style};if(!active){return /*#__PURE__*/_jsx(\"div\",{style:root,children:/*#__PURE__*/_jsx(\"a\",{href:legacyUrl||LEGACY_STORE_URL,target:\"_blank\",rel:\"noopener\",style:{...buttonStyle(\"primary\"),textDecoration:\"none\",width:\"100%\"},children:legacyLabel||\"Buy online\"})});}let note=null;let disabled=true;let label=\"Loading\";const ended=!!endsAt&&!isCanvas()&&Date.now()>Date.parse(endsAt)+ENDED_AFTER_MS;if(ended)label=\"This class has ended\";else if(error)note=error;else if(products&&!product){label=\"Not available online\";if(isCanvas())note=id?\"No online item with this variation ID in \"+\"the current Square account.\":\"Set the Square Variation ID.\";}else if(product&&max===0)label=\"Sold out\";else if(product){disabled=false;label=added?\"Added to cart\":\"Add to cart \\xb7 \"+formatMoney(product.priceCents*qty);if(product.maxQuantity!=null&&product.maxQuantity<=5)note=\"Only \"+product.maxQuantity+\" left\";}const add=()=>{if(!product||disabled)return;if(cartActions.add(product,qty)){setAdded(true);setQty(1);}};return /*#__PURE__*/_jsxs(\"div\",{style:root,children:[/*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",gap:8,width:\"100%\"},children:[showQuantity&&!disabled&&/*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",alignItems:\"center\",border:\"1px solid \"+T.borderStrong,borderRadius:4,flexShrink:0},children:[/*#__PURE__*/_jsx(\"button\",{type:\"button\",\"aria-label\":\"Decrease quantity\",style:stepBtn,onClick:()=>setQty(q=>Math.max(1,q-1)),children:\"-\"}),/*#__PURE__*/_jsx(\"span\",{\"aria-live\":\"polite\",style:{minWidth:24,textAlign:\"center\",color:T.strong,fontFamily:T.display,fontSize:16},children:qty}),/*#__PURE__*/_jsx(\"button\",{type:\"button\",\"aria-label\":\"Increase quantity\",style:stepBtn,onClick:()=>setQty(q=>Math.min(max,q+1)),children:\"+\"})]}),/*#__PURE__*/_jsx(\"button\",{type:\"button\",onClick:add,disabled:disabled,style:{...buttonStyle(\"primary\",disabled),flex:1,minWidth:0},children:label})]}),note&&/*#__PURE__*/_jsx(\"p\",{style:{margin:0,fontSize:14,color:error?T.danger:T.muted},children:note})]});}AddToCart.defaultProps={variationId:\"\",legacyUrl:LEGACY_STORE_URL,legacyLabel:\"Buy online\",showQuantity:true};addPropertyControls(AddToCart,{variationId:{type:ControlType.String,title:\"Variation ID\",defaultValue:\"\"},showQuantity:{type:ControlType.Boolean,title:\"Quantity\",defaultValue:true},endsAt:{type:ControlType.Date,title:\"Class date\"},legacyLabel:{type:ControlType.String,title:\"Before launch\",defaultValue:\"Buy online\"},legacyUrl:{type:ControlType.Link,title:\"Old store\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AddToCart\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"A,mSAKG,SAAwBoB,EAAU,EAAM,CAAC,GAAK,CAAC,cAAY,YAAU,cAAY,eAAa,SAAO,SAAOC,EAAYC,EAAOR,EAAc,EAAO,CAAC,WAAS,SAAOD,EAAY,EAAO,CAACU,EAAIC,GAAQxB,EAAS,CAAC,EAAO,CAACyB,EAAMC,GAAU1B,EAAS,EAAK,EAAQ2B,GAAIC,GAAa,GAAA,CAAI,KAAK,EAAQC,EAAQC,EAASA,EAAS,KAAK,GAAG1B,EAAE,cAAcuB,CAAE,EAAE,KAAWI,EAAIhB,EAAOc,CAAO,EAAEtB,MAAc,CAAC,GAAG,CAACkB,EAAM,OAAO,IAAMO,EAAE,eAAeN,EAAS,EAAK,EAAE,IAAI,EAAE,UAAU,aAAaM,CAAC,CAAE,EAAE,CAACP,CAAK,CAAC,EAAElB,MAAc,CAAIwB,EAAI,GAAGR,EAAIQ,GAAIP,EAAOO,CAAG,CAAE,EAAE,CAACA,CAAG,CAAC,EAAE,IAAME,EAAK,CAAC,QA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