{"version":3,"file":"CartTrigger.bqFNTHSc.mjs","names":["useState","useCallback"],"sources":["https:/framerusercontent.com/modules/ipwnVsdWgrjFNA05lcj7/gL57TLydDFQI0DmyxkHm/CartTrigger.js"],"sourcesContent":["/**\n * CartTrigger Component\n *\n * This component serves as a trigger for the shopping cart functionality in the Umbrel Home product.\n * It works in conjunction with the Cart component (defined in Cart.tsx) to manage the cart state\n * across different components and browser instances.\n *\n * Key features:\n * - Displays a button that can trigger the opening of the cart\n * - Optionally shows the current quantity of items in the cart\n * - Can add an item to the cart if it's empty\n * - Persists cart state across page reloads and browser tabs using localStorage\n *\n * Relationship with Cart.tsx:\n * Since Framer components can't directly share state, this component uses localStorage and custom events\n * to synchronize the cart state with the Cart component. This approach allows for consistent cart\n * behavior across different parts of the application without direct state sharing.\n */import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useEffect,useCallback}from\"react\";export default function CartTrigger({children,showQuantity=false,addToCart=false}){// Initialize quantity state from localStorage\n// This ensures the quantity persists across page reloads\nconst[quantity,setQuantity]=useState(()=>{if(typeof window===\"undefined\")return 0;return parseInt(window.localStorage.getItem(\"cartQuantity\")||\"0\",10);});// Create a memoized callback to handle cart updates\n// This function will be called whenever the cart is updated in any component\nconst handleCartUpdate=useCallback(()=>{if(typeof window===\"undefined\")return;const newQuantity=parseInt(window.localStorage.getItem(\"cartQuantity\")||\"0\",10);setQuantity(newQuantity);},[]);// Set up an event listener for cart updates\n// This allows the CartTrigger to react to changes made in the Cart component\nuseEffect(()=>{if(typeof window===\"undefined\")return;window.addEventListener(\"cartUpdate\",handleCartUpdate);// Clean up the event listener when the component unmounts\nreturn()=>{window.removeEventListener(\"cartUpdate\",handleCartUpdate);};},[handleCartUpdate]);// Handle click events on the cart trigger\nconst handleClick=()=>{console.log(\"clicked...\");if(typeof window===\"undefined\"){console.log(\"window is undefined\");return;}// If addToCart is true and the cart is empty, add one item\nif(addToCart&&quantity===0){console.log(\"adding to cart\");window.localStorage.setItem(\"cartQuantity\",\"1\");}console.log(\"setting isCartOpen to true\");// Open the cart\nwindow.localStorage.setItem(\"isCartOpen\",\"true\");console.log(\"dispatching cartUpdate event\");// Notify other components (especially Cart.tsx) about the update\nwindow.dispatchEvent(new Event(\"cartUpdate\"));};// Render the cart trigger button\nreturn /*#__PURE__*/_jsxs(\"button\",{onClick:handleClick,style:{cursor:\"pointer\",position:\"relative\",background:\"none\",border:\"none\",padding:0},children:[children,showQuantity&&quantity>0&&/*#__PURE__*/_jsx(\"span\",{style:quantityBadgeStyle,children:quantity})]});}// Add property controls for Framer\n// This allows users to customize the component's behavior in the Framer interface\naddPropertyControls(CartTrigger,{children:{type:ControlType.ComponentInstance},showQuantity:{type:ControlType.Boolean,title:\"Show Quantity\",defaultValue:false},addToCart:{type:ControlType.Boolean,title:\"Add to Cart\",defaultValue:true}});// Style for the quantity badge\n// This creates a small circular badge to display the cart quantity\nconst quantityBadgeStyle={position:\"absolute\",top:\"-0.35rem\",right:\"-0.35rem\",background:\"radial-gradient(circle, #5351F3, #312EE9)\",color:\"white\",fontSize:\"0.5rem\",fontWeight:\"bold\",borderRadius:\"50%\",width:\"0.8rem\",height:\"0.8rem\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",fontFamily:\"var(--framer-font-family, Inter, Inter Placeholder, sans-serif)\"};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CartTrigger\",\"slots\":[\"children\"],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CartTrigger.map"],"mappings":"6MAiBkK,SAAwB,EAAY,CAAC,WAAS,eAAa,GAAM,YAAU,IAAO,CAEpP,GAAK,CAAC,EAAS,GAAaA,MAAwB,IAAS,OAAmB,EAAS,SAAS,EAAO,aAAa,QAAQ,eAAe,EAAE,IAAI,GAAG,CAAG,CAEnJ,EAAiBC,MAAgB,CAAW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