{"version":3,"file":"AddToCartButton.FvCnnvFN.mjs","names":["React.useState"],"sources":["https:/framerusercontent.com/modules/jkQ2m5rBrgksBAYmRVfE/qUHRg0fztHUvF9OxECce/AddToCartButton.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";export default function AddToCartButton(props){const productId=props.productId||props.title;const[quantity,setQuantity]=React.useState(0);const getCart=()=>{return JSON.parse(localStorage.getItem(\"cart\")||\"[]\");};const saveCart=cart=>{localStorage.setItem(\"cart\",JSON.stringify(cart));window.dispatchEvent(new Event(\"cartUpdated\"));};const checkCart=()=>{const cart=getCart();const item=cart.find(item=>item.id===productId);setQuantity(item?item.quantity||1:0);};React.useEffect(()=>{checkCart();window.addEventListener(\"cartUpdated\",checkCart);return()=>{window.removeEventListener(\"cartUpdated\",checkCart);};},[productId]);const addFirstItem=()=>{const cart=getCart();const newCart=[...cart,{id:productId,title:props.title,price:props.price,quantity:1}];saveCart(newCart);};const increase=()=>{const cart=getCart();const newCart=cart.map(item=>item.id===productId?{...item,quantity:(item.quantity||1)+1}:item);saveCart(newCart);};const decrease=()=>{const cart=getCart();const newCart=cart.map(item=>item.id===productId?{...item,quantity:(item.quantity||1)-1}:item).filter(item=>item.quantity>0);saveCart(newCart);};if(quantity===0){return /*#__PURE__*/_jsx(\"button\",{onClick:addFirstItem,style:{width:\"100%\",padding:\"10px\",borderRadius:\"10px\",border:\"none\",background:\"#2E2E2E\",color:\"white\",cursor:\"pointer\",whiteSpace:\"nowrap\",transition:\"0.2s\",fontSize:\"10px\"},children:\"Добавить\"});}return /*#__PURE__*/_jsxs(\"div\",{style:{width:\"100%\",display:\"flex\",alignItems:\"center\",justifyContent:\"space-between\",background:\"#688683\",borderRadius:\"10px\",overflow:\"hidden\",color:\"white\",fontSize:\"12px\"},children:[/*#__PURE__*/_jsx(\"button\",{onClick:decrease,style:{width:\"32%\",padding:\"10px\",border:\"none\",background:\"transparent\",color:\"white\",cursor:\"pointer\",fontSize:\"14px\"},children:\"-\"}),/*#__PURE__*/_jsx(\"div\",{style:{width:\"36%\",textAlign:\"center\",fontSize:\"12px\"},children:quantity}),/*#__PURE__*/_jsx(\"button\",{onClick:increase,style:{width:\"32%\",padding:\"10px\",border:\"none\",background:\"transparent\",color:\"white\",cursor:\"pointer\",fontSize:\"14px\"},children:\"+\"})]});}addPropertyControls(AddToCartButton,{productId:{type:ControlType.String,title:\"Product ID\"},title:{type:ControlType.String,title:\"Title\"},price:{type:ControlType.String,title:\"Price\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AddToCartButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AddToCartButton.map"],"mappings":"sMAAyI,SAAwB,EAAgB,EAAM,CAAC,IAAM,EAAU,EAAM,WAAW,EAAM,MAAW,CAAC,EAAS,GAAaA,EAAe,CAAC,EAAQ,MAAoB,KAAK,MAAM,aAAa,QAAQ,MAAM,GAAG,IAAI,EAAU,EAAS,GAAM,CAAC,aAAa,QAAQ,OAAO,KAAK,UAAU,CAAI,CAAC,EAAE,EAAO,cAAc,IAAI,MAAM,aAAa,CAAC,CAAE,EAAQ,MAAc,CAAsB,IAAM,EAAhB,EAAwB,CAAC,CAAC,KAAK,GAAM,EAAK,KAAK,CAAS,EAAE,EAAY,EAAK,EAAK,UAAU,EAAE,CAAC,CAAE,EAAi6B,OAA/5B,OAAqB,EAAU,EAAE,EAAO,iBAAiB,cAAc,CAAS,MAAY,CAAC,EAAO,oBAAoB,cAAc,CAAS,CAAE,GAAI,CAAC,CAAS,CAAC,EAAkf,IAAW,EAAuB,EAAK,SAAS,CAAC,YAA1gB,CAAsB,IAAM,EAAQ,CAAC,GAAzB,EAA+B,EAAE,CAAC,GAAG,EAAU,MAAM,EAAM,MAAM,MAAM,EAAM,MAAM,SAAS,CA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