{"version":3,"file":"AddToCartButton.D8jS3vmN.mjs","names":["useState","useRef","useMemo","useCallback","startTransition"],"sources":["https:/framerusercontent.com/modules/idBq8nLco16jQkw5xz70/vBhJZdKpYVDIbpVEUjTV/AddToCartButton.js"],"sourcesContent":["// Instructions: Create a Framer Code Component called AddToCartButton that dispatches window.dispatchEvent(new CustomEvent(\"cart:add\", { detail: payload })) with required/optional payload fields, shows a temporary \"Added ✓\" state for 1.2s, disables during that state, and exposes the specified Framer property controls and styling controls. Fully self-contained in one file.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{startTransition,useCallback,useEffect,useMemo,useRef,useState}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * @framerIntrinsicWidth 180\n * @framerIntrinsicHeight 44\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function AddToCartButton(props){const{sku,name,price,quantity,stripePriceId,stripeProductId,image=\"https://framerusercontent.com/images/GfGkADagM4KEibNcIiRUWlfrR0.jpg\",productUrl,type,description,cartBulletsText,openCartOnAdd,debug,buttonText,addedText,backgroundColor,textColor,borderColor,radius,padding,font,hoverOpacity,style}=props;const isStatic=useIsStaticRenderer();const[added,setAdded]=useState(false);const[hovered,setHovered]=useState(false);const timeoutRef=useRef(null);useEffect(()=>{return()=>{if(timeoutRef.current!==null&&typeof window!==\"undefined\"){window.clearTimeout(timeoutRef.current);timeoutRef.current=null;}};},[]);const cartBullets=useMemo(()=>{const raw=(cartBulletsText??\"\").split(\"\\n\").map(s=>s.trim());const filtered=raw.filter(Boolean);return filtered.length?filtered:undefined;},[cartBulletsText]);const computed=useMemo(()=>{const safeSku=(sku??\"\").trim();const safeName=(name??\"\").trim();const safeStripePriceId=(stripePriceId??\"\").trim();const hasValidSku=Boolean(safeSku);const hasValidName=Boolean(safeName);const hasValidQuantity=Number.isFinite(quantity)&&quantity>=1;const invalid=[];if(!hasValidSku)invalid.push(\"sku\");if(!hasValidName)invalid.push(\"name\");if(!hasValidQuantity)invalid.push(\"quantity\");const q=hasValidQuantity?Math.floor(quantity):Math.max(1,Math.floor(Number(quantity)||1));const p=Number.isFinite(price)?price:0;const detail={sku:safeSku,name:safeName,price:p,quantity:q,type:type??\"one_time\"};if(safeStripePriceId)detail.stripePriceId=safeStripePriceId;const spid=(stripeProductId??\"\").trim();if(spid)detail.stripeProductId=spid;const img=(image??\"\").trim();if(img)detail.image=img;const url=(productUrl??\"\").trim();if(url)detail.productUrl=url;const desc=(description??\"\").trim();if(desc)detail.description=desc;if(cartBullets)detail.cartBullets=cartBullets;return{payload:detail,invalid,safeStripePriceId};},[sku,name,stripePriceId,quantity,price,type,stripeProductId,image,productUrl,description,cartBullets]);useEffect(()=>{if(!debug)return;if(!computed.safeStripePriceId)return;if(!computed.safeStripePriceId.startsWith(\"price_\")){console.warn(\"[AddToCartButton] stripePriceId does not start with 'price_':\",computed.safeStripePriceId);}},[debug,computed.safeStripePriceId]);const canAdd=computed.invalid.length===0;const onClick=useCallback(()=>{if(isStatic)return;if(added)return;if(debug){console.log(\"[AddToCartButton] click attempt payload:\",computed.payload);if(!canAdd){console.warn(\"[AddToCartButton] button disabled due to invalid fields:\",computed.invalid);}}if(!canAdd)return;if(typeof window===\"undefined\")return;const ok=window.__CartSystem__?.addItem?.({sku:computed.payload.sku,name:computed.payload.name,price:computed.payload.price,quantity:computed.payload.quantity,stripePriceId:computed.payload.stripePriceId,stripeProductId:computed.payload.stripeProductId,image:computed.payload.image,productUrl:computed.payload.productUrl,type:computed.payload.type,description:computed.payload.description,cartBullets:computed.payload.cartBullets});if(ok!==true)return;const klaviyoPayload={$value:computed.payload.price*computed.payload.quantity,AddedItemProductName:computed.payload.name,AddedItemProductID:computed.payload.stripeProductId||computed.payload.sku,AddedItemSKU:computed.payload.sku,AddedItemCategories:[computed.payload.type],AddedItemImageURL:computed.payload.image,AddedItemURL:computed.payload.productUrl,AddedItemPrice:computed.payload.price,AddedItemQuantity:computed.payload.quantity,ItemNames:[computed.payload.name],CheckoutURL:typeof window!==\"undefined\"?window.location.href:\"\",Items:[{ProductID:computed.payload.stripeProductId||computed.payload.sku,SKU:computed.payload.sku,ProductName:computed.payload.name,Quantity:computed.payload.quantity,ItemPrice:computed.payload.price,RowTotal:computed.payload.price*computed.payload.quantity,ProductURL:computed.payload.productUrl,ImageURL:computed.payload.image}]};try{window._learnq=window._learnq||[];window._learnq.push([\"track\",\"Added to Cart\",klaviyoPayload]);if(debug){console.log(\"[AddToCartButton] Klaviyo Added to Cart fired:\",klaviyoPayload);}}catch(err){if(debug){console.log(\"[AddToCartButton] Klaviyo Added to Cart failed:\",err);}}window.dispatchEvent(new CustomEvent(\"cart:changed\",{detail:{source:\"addToCart\"}}));if(openCartOnAdd){window.dispatchEvent(new CustomEvent(\"cart:open\",{detail:{source:\"addToCart\"}}));}startTransition(()=>setAdded(true));if(timeoutRef.current!==null)window.clearTimeout(timeoutRef.current);timeoutRef.current=window.setTimeout(()=>{startTransition(()=>setAdded(false));timeoutRef.current=null;},1200);},[isStatic,added,debug,computed,canAdd,openCartOnAdd]);const isDisabled=added||!canAdd;const computedOpacity=useMemo(()=>{if(isDisabled)return .6;if(hovered)return Math.max(0,Math.min(1,hoverOpacity));return 1;},[isDisabled,hovered,hoverOpacity]);const label=added?addedText:buttonText;return /*#__PURE__*/_jsx(\"button\",{type:\"button\",onClick:onClick,disabled:isDisabled,\"aria-disabled\":isDisabled,\"aria-label\":typeof label===\"string\"?label:\"Add to Cart\",onMouseEnter:isStatic?undefined:()=>startTransition(()=>setHovered(true)),onMouseLeave:isStatic?undefined:()=>startTransition(()=>setHovered(false)),style:{position:\"relative\",width:\"100%\",height:\"100%\",appearance:\"none\",WebkitAppearance:\"none\",border:`1px solid ${borderColor}`,background:backgroundColor,color:textColor,borderRadius:radius,padding,cursor:isDisabled?\"not-allowed\":\"pointer\",opacity:computedOpacity,userSelect:\"none\",outline:\"none\",display:\"inline-flex\",alignItems:\"center\",justifyContent:\"center\",gap:8,whiteSpace:\"nowrap\",overflow:\"hidden\",textOverflow:\"ellipsis\",...font??{},...style??{}},children:/*#__PURE__*/_jsx(\"span\",{style:{minWidth:\"max-content\"},children:label})});}addPropertyControls(AddToCartButton,{debug:{type:ControlType.Boolean,title:\"Debug\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},openCartOnAdd:{type:ControlType.Boolean,title:\"Open Cart\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"},sku:{type:ControlType.String,title:\"SKU\",defaultValue:\"\",placeholder:\"e.g. tshirt-black-s\"},name:{type:ControlType.String,title:\"Name\",defaultValue:\"\",placeholder:\"Product name\"},price:{type:ControlType.Number,title:\"Price\",defaultValue:0,min:0,step:.01},quantity:{type:ControlType.Number,title:\"Quantity\",defaultValue:1,min:1,step:1},stripePriceId:{type:ControlType.String,title:\"Stripe Price ID\",defaultValue:\"\",placeholder:\"price_...\"},stripeProductId:{type:ControlType.String,title:\"Stripe Product ID\",defaultValue:\"\",placeholder:\"prod_... (optional)\"},image:{type:ControlType.File,title:\"Image\",allowedFileTypes:[\"jpg\",\"jpeg\",\"png\",\"webp\",\"svg\"]},productUrl:{type:ControlType.String,title:\"Product URL\",defaultValue:\"\",placeholder:\"https://... (optional)\"},type:{type:ControlType.Enum,title:\"Type\",defaultValue:\"one_time\",options:[\"one_time\",\"subscription\"],optionTitles:[\"One-time\",\"Subscription\"],displaySegmentedControl:true},description:{type:ControlType.String,title:\"Description\",defaultValue:\"\",displayTextArea:true},cartBulletsText:{type:ControlType.String,title:\"Cart Bullets\",defaultValue:\"\",displayTextArea:true,placeholder:\"Bullet 1\\nBullet 2\\nBullet 3\"},buttonText:{type:ControlType.String,title:\"Button Text\",defaultValue:\"Add to Cart\"},addedText:{type:ControlType.String,title:\"Added Text\",defaultValue:\"Added ✓\"},backgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"},textColor:{type:ControlType.Color,title:\"Text\",defaultValue:\"#000000\"},borderColor:{type:ControlType.Color,title:\"Border\",defaultValue:\"#EEEEEE\"},radius:{type:ControlType.BorderRadius,title:\"Radius\",defaultValue:\"12px\"},padding:{type:ControlType.Padding,title:\"Padding\",defaultValue:\"12px 16px\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"14px\",variant:\"Semibold\",letterSpacing:\"-0.01em\",lineHeight:\"1em\"}},hoverOpacity:{type:ControlType.Number,title:\"Hover Opacity\",defaultValue:.9,min:0,max:1,step:.01}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AddToCartButton\",\"slots\":[],\"annotations\":{\"framerIntrinsicHeight\":\"44\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerIntrinsicWidth\":\"180\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AddToCartButton.map"],"mappings":"mOAOG,SAAwB,EAAgB,EAAM,CAAC,GAAK,CAAC,MAAI,OAAK,QAAM,WAAS,gBAAc,kBAAgB,QAAM,sEAAsE,aAAW,OAAK,cAAY,kBAAgB,gBAAc,QAAM,aAAW,YAAU,kBAAgB,YAAU,cAAY,SAAO,UAAQ,OAAK,eAAa,SAAO,EAAY,EAAS,GAAqB,CAAM,CAAC,EAAM,GAAUA,EAAS,GAAM,CAAM,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAO,EAAWC,EAAO,KAAK,CAAC,UAAyB,CAAI,EAAW,UAAU,MAAa,IAAS,SAAa,EAAO,aAAa,EAAW,QAAQ,CAAC,EAAW,QAAQ,OAAU,EAAE,CAAC,CAAC,IAAM,EAAYC,MAAY,CAA8D,IAAM,GAAxD,GAAiB,IAAI,MAAM;EAAK,CAAC,IAAI,GAAG,EAAE,MAAM,CAAC,CAAoB,OAAO,QAAQ,CAAC,OAAO,EAAS,OAAO,E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