{"version":3,"file":"Cart_Preview.DxeTLg2s.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/2j2tCLeRImvWBR8vNpj8/pl89xQdHZgoiTMgSB6Gs/Cart_Preview.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useState}from\"react\";import Cart_Card_Preview from\"https://framerusercontent.com/modules/AddYIHWM7uKeLq525AAm/0zCR3jXcMZam9xRD21Ap/Cart_Card_Preview.js\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n * @framerDisableUnlink\n * By FRAMAX - Complete Cart Preview with Unit-Based Item Support\n */// Helper function to determine if an item is sold by units vs packs\nconst isUnitBasedItem=product=>{// Check if product has no size selection, size is \"1\", is a dispenser, or is explicitly marked as unit-based\nconst size=product?.size||product?.additionalData?.[0]?.Size||\"\";const productName=(product?.productName||\"\").toLowerCase();return!size||size===\"\"||size===null||size===undefined||size===\"1\"||// Pack size of 1 = unit-based\nsize===1||productName.includes(\"dispenser\")||// Dispensers are unit-based\nproduct?.sellBy===\"unit\"||product?.isUnitBased===true;};// Helper function to get the correct unit label\nconst getUnitLabel=product=>{const productName=(product?.productName||\"\").toLowerCase();if(isUnitBasedItem(product)){if(productName.includes(\"dispenser\")){return product?.quantity===1?\"dispenser\":\"dispensers\";}return product?.quantity===1?\"unit\":\"units\";}else{// For pack-based items, show pack size information\nconst size=product?.size||product?.additionalData?.[0]?.Size||\"\";return product?.quantity===1?`${size}-pack`:`${size}-packs`;}};// Helper function to calculate accurate price per unit\nconst calculateUnitPrice=product=>{// Always use the stored price as the unit price for consistency\nreturn parseFloat(product?.price)||0;};export default function Cart_Preview(props){const[products,setProducts]=useState([]);const[itemQuantities,setItemQuantities]=useState([]);// Set updated product data\nuseEffect(()=>{const updateItemsFromStorage=()=>{const savedData=JSON.parse(localStorage.getItem(\"cart-items\"))||[];// Handle empty cart case\nif(!savedData||savedData.length===0){setProducts([]);setItemQuantities([]);return;}// Process each item to ensure proper unit handling and backwards compatibility\nconst processedData=savedData.map(item=>{// Ensure item exists and has required properties\nif(!item)return null;// Handle backwards compatibility - extract size from additionalData if needed\nconst size=item.size||item.additionalData?.[0]?.Size||\"\";const color=item.color||item.additionalData?.[1]?.Color||\"\";const unitPrice=calculateUnitPrice(item);const quantity=parseInt(item.quantity)||1;const totalPrice=(unitPrice*quantity).toFixed(2);const isUnitBased=isUnitBasedItem({...item,size});return{...item,size:size,color:color,unitPrice:unitPrice,price:unitPrice,quantity:quantity,totalPrice:totalPrice,isUnitBased:isUnitBased,unitLabel:getUnitLabel({...item,size,quantity})};}).filter(item=>item!==null)// Remove any null items\n;const initialQuantities=processedData.map(item=>item?.quantity||0);setProducts(processedData);setItemQuantities(initialQuantities);};updateItemsFromStorage();const pollingInterval=setInterval(()=>{updateItemsFromStorage();},500)// Check for updated local storage value every 500ms\n;// Listen for storage events for immediate updates\nconst handleStorageChange=e=>{if(e.key===\"cart-items\"){updateItemsFromStorage();}};window.addEventListener(\"storage\",handleStorageChange);return()=>{clearInterval(pollingInterval);window.removeEventListener(\"storage\",handleStorageChange);};},[]);// Handle quantity update - Updated for unit-based items\nconst handleUpdateQuantity=(uid,newQuantity)=>{if(newQuantity<1||newQuantity>1e3)return;// Update items state\nconst updatedProducts=products.map(product=>{if(product.uid===uid){const unitPrice=parseFloat(product.price)// Use existing price\n;const totalPrice=(unitPrice*newQuantity).toFixed(2);return{...product,quantity:newQuantity,totalPrice:totalPrice,unitLabel:getUnitLabel({...product,quantity:newQuantity})};}return product;});setProducts(updatedProducts)// Update items state\n;setItemQuantities(updatedProducts.map(product=>product.quantity))// Update quantities state\n;localStorage.setItem(\"cart-items\",JSON.stringify(updatedProducts))// Update localStorage with updated items\n;// Force subtotal recalculation by triggering a storage event\nwindow.dispatchEvent(new StorageEvent(\"storage\",{key:\"cart-items\",newValue:JSON.stringify(updatedProducts)}));};// Handle product delete\nconst handleProductDelete=uid=>{const updatedItems=products.filter(product=>product.uid!==uid);setProducts(updatedItems);localStorage.setItem(\"cart-items\",JSON.stringify(updatedItems));// Force subtotal recalculation by triggering a storage event\nwindow.dispatchEvent(new StorageEvent(\"storage\",{key:\"cart-items\",newValue:JSON.stringify(updatedItems)}));};return products.length<1?/*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\",textAlign:\"center\"},children:/*#__PURE__*/_jsx(\"h3\",{style:emptyMessageStyles,children:props.styles?.containerStyle?.emptyMessage})}):/*#__PURE__*/_jsx(\"div\",{style:{height:\"100%\",overflow:\"auto\"},children:products?.map((product,index)=>/*#__PURE__*/_jsx(Cart_Card_Preview,{product:product,handleUpdateQuantity:handleUpdateQuantity,handleProductDelete:handleProductDelete,styles:props.styles,isUnitBased:product.isUnitBased,unitLabel:product.unitLabel},product.uid||index))});}const emptyMessageStyles={fontSize:\"24px\",color:\"#828282\",fontFamily:\"outfit, arial\",opacity:\"0.6\"};// Property Controls\naddPropertyControls(Cart_Preview,{styles:{type:ControlType.Object,controls:{containerStyle:{title:\"Container\",type:ControlType.Object,controls:{padding:{type:ControlType.Padding,title:\"Padding\"},dividerColor:{type:ControlType.Color,title:\"Divider Color\",defaultValue:\"#EAEAEA\"},emptyMessage:{type:ControlType.String,title:\"Empty Cart Message\",defaultValue:\"Your cart is empty!\"}}},imageStyle:{title:\"Image\",type:ControlType.Object,controls:{width:{type:ControlType.Number,title:\"Width\",defaultValue:120,displayStepper:true},height:{type:ControlType.Number,title:\"Height\",defaultValue:120,displayStepper:true},padding:{type:ControlType.Padding,title:\"Padding\"},bgColor:{type:ControlType.Color,title:\"Background Color\",defaultValue:\"#F5F6F8\"},fill:{type:ControlType.Enum,options:[\"fill\",\"contain\",\"cover\"],defaultValue:\"cover\"}}},titleStyle:{type:ControlType.Object,title:\"Title\",controls:{font:{type:ControlType.Font,title:\"Font\",defaultValue:\"outfit\",controls:\"extended\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#232327\"}}},priceStyle:{type:ControlType.Object,title:\"Price\",controls:{font:{type:ControlType.Font,title:\"Font\",defaultValue:\"outfit\",controls:\"extended\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#232327\"}}},sizeStyle:{type:ControlType.Object,title:\"Size & Color\",controls:{font:{type:ControlType.Font,title:\"Font\",defaultValue:\"outfit\",controls:\"extended\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#232327\"},labelColor:{type:ControlType.Color,title:\"Size Label Color\",defaultValue:\"#6E717D\"},colorIndicatorStyle:{type:ControlType.Object,title:\"Color Label\",controls:{width:{type:ControlType.Number,title:\"Width\",defaultValue:14,displayStepper:true},height:{type:ControlType.Number,title:\"Height\",defaultValue:14,displayStepper:true},radius:{type:ControlType.BorderRadius,title:\"Radius\"}}}}},quantityCounterStyles:{type:ControlType.Object,title:\"Quantity Counter\",controls:{buttonBGColor:{type:ControlType.Color,title:\"Button Background\",defaultValue:\"#F5F5F5\"},borderColor:{type:ControlType.Color,title:\"Border Color\",defaultValue:\"#23232733\"},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#232327\"}}}}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Cart_Preview\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Cart_Preview.map"],"mappings":"oPAauC,SAAwB,EAAa,EAAM,CAAC,GAAK,CAAC,EAAS,GAAaA,EAAS,EAAE,CAAC,CAAM,CAAC,EAAe,GAAmBA,EAAS,EAAE,CAAC,CAChL,MAAc,CAAC,IAAM,MAA2B,CAAC,IAAM,EAAU,KAAK,MAAM,aAAa,QAAQ,aAAa,CAAC,EAAE,EAAE,CACnH,GAAG,CAAC,GAAW,EAAU,SAAS,EAAE,CAAC,EAAY,EAAE,CAAC,CAAC,EAAkB,EAAE,CAAC,CAAC,OAC3E,IAAM,EAAc,EAAU,IAAI,GAAM,CACxC,GAAG,CA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