{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/F1msxdpcAW9cfgKrg8ff/g4pxpEtwB87KsYfIHm4A/CartOverrides.js"],
  "sourcesContent": ["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{createStore}from\"https://framerusercontent.com/modules/NF27GMRnRQIwaQZ2G9YY/yEILKTPL9l4PImY26MTI/CreateStore.js\";import{formatPrice,useLocale}from\"https://framerusercontent.com/modules/RRKeJWRObO6zvJYvvGR6/Qsx4ZWLAxrWSMmYgPYrT/Helpers.js\";import{isBrowser}from\"framer\";import{MAX_PRODUCT_QTY,PRICES}from\"https://framerusercontent.com/modules/o1aeipZQQXsUUIIJuQBL/XYNkdIExnB4dYaVTTqMO/Constants.js\";// DIFFERENT IMPLEMENTATION IDEA\n// Each product has a name, price, and maybe a Q limit (in the CMS? in an external file?)\n// The basket can store an array of product names and quantity values\n// Values can be calculated dynamically for the basket: subtotal, sales tax, shipping, total due\nexport const useCartQuantities=createStore({essentialCardMachine:0,proCardMachine:0,goCardMachine:0});export const useCartValues=()=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const totalCartQuantity=Number(Object.values(cartQuantities).reduce((acc,key)=>acc+key,0));const subTotal=Object.keys(cartQuantities).reduce((acc,key)=>acc+cartQuantities[key]*PRICES[key],0);const shipping=0;const salesTax=(subTotal+shipping)*.2;const totalDue=subTotal+shipping+salesTax;return{totalCartQuantity,subTotal,shipping,salesTax,totalDue};};export function withQuantity(Component){return props=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const name=props.name||props[\"data-framer-name\"];return /*#__PURE__*/_jsx(Component,{text:String(cartQuantities[name]??0),...props});};}export function withChangeQuantity(Component){return props=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const{totalCartQuantity}=useCartValues();const name=props.name||props[\"data-framer-name\"];const{command,product}=findProductCommand(name)||{};const productQuantity=cartQuantities[product]||0;const handleClick=()=>{if(!command||!product)return null;if(command===\"Increment\"){if(totalCartQuantity<MAX_PRODUCT_QTY){setCartQuantities({...cartQuantities,[product]:productQuantity+1});}}if(command===\"Decrement\"){if(productQuantity>0){setCartQuantities({...cartQuantities,[product]:productQuantity-1});}}};return /*#__PURE__*/_jsx(Component,{onClick:handleClick,...props});};}export function withTotalCartQuantity(Component){return props=>{const{totalCartQuantity}=useCartValues();return /*#__PURE__*/_jsx(Component,{text:String(totalCartQuantity),...props});};}export function withProductSubTotal(Component){return props=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const product=props.name||props[\"data-framer-name\"];const quantity=cartQuantities[product];const subTotal=quantity*PRICES[product];return /*#__PURE__*/_jsx(Component,{text:formatPrice(subTotal,\"GB\"),...props});};}export function withSubTotal(Component){return props=>{const{subTotal}=useCartValues();return /*#__PURE__*/_jsx(Component,{text:formatPrice(subTotal,\"GB\"),...props});};}export function withSalesTax(Component){return props=>{const{salesTax}=useCartValues();return /*#__PURE__*/_jsx(Component,{text:formatPrice(salesTax,\"GB\"),...props});};}export function withTotalDue(Component){return props=>{const{totalDue}=useCartValues();return /*#__PURE__*/_jsx(Component,{text:formatPrice(totalDue,\"GB\"),...props});};}export function withAddToCart(Component){return props=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const{totalCartQuantity}=useCartValues();const[variant,setVariant]=useState(totalCartQuantity<MAX_PRODUCT_QTY?\"Enabled\":\"Disabled\");useEffect(()=>{setVariant(totalCartQuantity<MAX_PRODUCT_QTY?\"Enabled\":\"Disabled\");},[totalCartQuantity]);const handleSubmit=e=>{e.preventDefault();if(totalCartQuantity>=MAX_PRODUCT_QTY)console.error(\"The cart is already at its max size\");const formData=new FormData(e.target);const product=String(formData.get(\"product\"));const additionalQuantity=Number(formData.get(\"quantity\"));const newProductQuantity=Math.min((cartQuantities[product]??0)+additionalQuantity,MAX_PRODUCT_QTY);if(typeof additionalQuantity!==\"number\")console.error(\"Quantity must be a number\");if(!Object.keys(cartQuantities).includes(product))console.error(\"Product name is not recognised\");if(additionalQuantity>MAX_PRODUCT_QTY)console.error(\"Quantity is too large\");setCartQuantities({...cartQuantities,[product]:newProductQuantity});if(isBrowser&&globalThis.dataLayer){globalThis.dataLayer.push({event:\"add_to_cart\"});}e.target.querySelector(\"a\").click();};return /*#__PURE__*/_jsx(\"form\",{onSubmit:e=>handleSubmit(e),children:/*#__PURE__*/_jsx(\"fieldset\",{disabled:variant===\"Disabled\",style:{display:\"flex\",flexDirection:\"column\",width:\"100%\",margin:0,padding:0,border:\"none\",outline:\"none\"},children:/*#__PURE__*/_jsx(Component,{...props,variant:variant})})});};}export function withCartVisibility(Component){return props=>{const[cartQuantities,setCartQuantities]=useCartQuantities();const product=props.name||props[\"data-framer-name\"];if(cartQuantities[product]>0){return /*#__PURE__*/_jsx(Component,{...props});}if(cartQuantities.proCardMachine>0&&cartQuantities.essentialCardMachine>0&&cartQuantities.goCardMachine>0&&product===\"both\"){return /*#__PURE__*/_jsx(Component,{...props});}if(Object.values(cartQuantities).filter(value=>value>0).length>0){if(product===\"anything\"){return /*#__PURE__*/_jsx(Component,{...props});}}if(Object.values(cartQuantities).filter(value=>value>0).length===0){if(product===\"nothing\"){return /*#__PURE__*/_jsx(Component,{...props});}}return null;};}export function withMaxQtyWarning(Component){return props=>{const{totalCartQuantity}=useCartValues();if(totalCartQuantity===MAX_PRODUCT_QTY){return /*#__PURE__*/_jsx(Component,{...props});}return null;};}export function withPrimaryCTA(Component){return props=>{const{totalCartQuantity}=useCartValues();const locale=useLocale();return /*#__PURE__*/_jsx(Component,{...props,variant:totalCartQuantity>0&&locale===\"GB\"?\"Non-empty\":\"Empty\"});};}const findProductCommand=str=>{const words=str.trim().split(/\\s+/);if(words.length!==2){return undefined;}return{command:words[0],product:words[1]};};\nexport const __FramerMetadata__ = {\"exports\":{\"withTotalCartQuantity\":{\"type\":\"reactHoc\",\"name\":\"withTotalCartQuantity\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPrimaryCTA\":{\"type\":\"reactHoc\",\"name\":\"withPrimaryCTA\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withMaxQtyWarning\":{\"type\":\"reactHoc\",\"name\":\"withMaxQtyWarning\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useCartQuantities\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCartVisibility\":{\"type\":\"reactHoc\",\"name\":\"withCartVisibility\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withChangeQuantity\":{\"type\":\"reactHoc\",\"name\":\"withChangeQuantity\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useCartValues\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAddToCart\":{\"type\":\"reactHoc\",\"name\":\"withAddToCart\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSubTotal\":{\"type\":\"reactHoc\",\"name\":\"withSubTotal\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSalesTax\":{\"type\":\"reactHoc\",\"name\":\"withSalesTax\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withProductSubTotal\":{\"type\":\"reactHoc\",\"name\":\"withProductSubTotal\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTotalDue\":{\"type\":\"reactHoc\",\"name\":\"withTotalDue\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withQuantity\":{\"type\":\"reactHoc\",\"name\":\"withQuantity\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],
  "mappings": "6FAIO,IAAMA,EAAkBC,EAAY,CAAC,qBAAqB,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC,EAAeC,EAAc,IAAI,CAAC,GAAK,CAACC,EAAeC,CAAiB,EAAEJ,EAAkB,EAAQK,EAAkB,OAAO,OAAO,OAAOF,CAAc,EAAE,OAAO,CAACG,EAAIC,IAAMD,EAAIC,EAAI,CAAC,CAAC,EAAQC,EAAS,OAAO,KAAKL,CAAc,EAAE,OAAO,CAACG,EAAIC,IAAMD,EAAIH,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AC,CAAE,CAAE,CAAC,IAAMG,EAAmBC,GAAK,CAAC,IAAMC,EAAMD,EAAI,KAAK,EAAE,MAAM,KAAK,EAAE,GAAGC,EAAM,SAAS,EAAqB,MAAM,CAAC,QAAQA,EAAM,CAAC,EAAE,QAAQA,EAAM,CAAC,CAAC,CAAE",
  "names": ["useCartQuantities", "createStore", "useCartValues", "cartQuantities", "setCartQuantities", "totalCartQuantity", "acc", "key", "subTotal", "PRICES", "shipping", "salesTax", "totalDue", "withChangeQuantity", "Component", "props", "cartQuantities", "setCartQuantities", "useCartQuantities", "totalCartQuantity", "useCartValues", "name", "command", "product", "findProductCommand", "productQuantity", "p", "MAX_PRODUCT_QTY", "withTotalCartQuantity", "withPrimaryCTA", "Component", "props", "totalCartQuantity", "useCartValues", "locale", "useLocale", "p", "findProductCommand", "str", "words"]
}
