{"version":3,"file":"ProductState.MFmt0Avm.mjs","names":["useContext","useMemo"],"sources":["https:/framerusercontent.com/modules/Be5mN5EUhdOwl54qCG8y/Icj1ZU450uFtWcyrdGTm/CartItemContext.js","https:/framerusercontent.com/modules/LrldJJ60fjHs91m6XdHT/2FUoEFQ8UfRjbsZiejBU/SharedStore.js","https:/framerusercontent.com/modules/ajKYBgRXgNyNgL1GkpqG/prknJU66nI5iRE43ff6z/ProductState.js"],"sourcesContent":["import{createContext,useContext}from\"react\";export const CartItemContext=/*#__PURE__*/createContext({inCart:false,cartItemId:null,shopifyId:null,variantId:null,quantity:1,price:null,compareAtPrice:null,sku:null,barcode:null,variant:null});export const useCartItem=()=>useContext(CartItemContext);\nexport const __FramerMetadata__ = {\"exports\":{\"useCartItem\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CartItemContext\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CartItemContext.map","import create from\"zustand\";const WINDOW_STORES_KEY=\"__frameship_stores__\";// Initialize the shared stores object if it doesn't exist\nconst initializeStores=()=>{if(typeof window!==\"undefined\"&&!window[WINDOW_STORES_KEY]){window[WINDOW_STORES_KEY]={};}};// Call initialization on client side\nif(typeof window!==\"undefined\"){initializeStores();}/**\n * Creates a shared Zustand store that can be accessed across different instances\n * @param id - Unique identifier for the store\n * @param config - Configuration object containing version, state creator, and optional migrator\n * @returns A Zustand store that is shared across instances with the same id\n */export function createSharedStore(id,config){const{version,createState,migrateState}=config;// Return a dummy store during SSR\nif(typeof window===\"undefined\"){return create(createState);}// Ensure stores are initialized\ninitializeStores();const existingStore=window[WINDOW_STORES_KEY][id];// If the store exists and has a higher or equal version, return it\nif(existingStore&&existingStore.version>=version){return existingStore.store;}// Create a new store\nconst store=create(createState);// If there's an existing store, migrate the state using either the provided migrator or the default one\nif(existingStore){const currentState=existingStore.store.getState();const migratedState=migrateState?migrateState(currentState):defaultMigrateState(currentState);store.setState(migratedState);}// Store the new version and store\nwindow[WINDOW_STORES_KEY][id]={store,version};return store;}/**\n * Gets an existing shared store by its ID\n * @param id - The ID of the store to retrieve\n * @returns The store if it exists, undefined otherwise\n */export function getSharedStore(id){if(typeof window===\"undefined\")return undefined;// Ensure stores are initialized\ninitializeStores();return window[WINDOW_STORES_KEY][id]?.store;}/**\n * Gets the version of a shared store by its ID\n * @param id - The ID of the store to check\n * @returns The version number if the store exists, undefined otherwise\n */export function getSharedStoreVersion(id){if(typeof window===\"undefined\")return undefined;// Ensure stores are initialized\ninitializeStores();return window[WINDOW_STORES_KEY][id]?.version;}/**\n * Default migration function that copies all non-function properties from the old state\n */function defaultMigrateState(oldState){const newState={};for(const key in oldState){if(typeof oldState[key]!==\"function\"){newState[key]=oldState[key];}}return newState;}\nexport const __FramerMetadata__ = {\"exports\":{\"getSharedStoreVersion\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"createSharedStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSharedStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SharedStore.map","import{useMemo}from\"react\";import{createSharedStore}from\"https://framerusercontent.com/modules/LrldJJ60fjHs91m6XdHT/2FUoEFQ8UfRjbsZiejBU/SharedStore.js\";import{parseShopifyData}from\"https://framerusercontent.com/modules/gd3dcT3w5rYoRy7ZcKte/sH6FZizM8jJ11j2dQOhQ/Shared.js\";export const useProductStore=createSharedStore(\"product-store\",{version:1,createState:set=>({products:{},setSelectedVariantOption:(productId,variantOption,option)=>set(state=>({products:{...state.products,[productId]:{...state.products[productId],selectedVariantOptions:{...state.products[productId]?.selectedVariantOptions,[variantOption]:option}}}})),setQuantity:(productId,quantity)=>{set(state=>({products:{...state.products,[productId]:{...state.products?.[productId],quantity:Math.max(quantity,1)}}}));}}),migrateState:oldState=>{return{products:oldState.products};}});export function useSelectedVariant(shopifyData){const parsedData=useMemo(()=>parseShopifyData(shopifyData),[shopifyData]);const{shopifyId,variants}=parsedData;const selectedVariantOptions=useProductStore(state=>state.products[shopifyId]?.selectedVariantOptions);const selectedVariant=useMemo(()=>{if(!Array.isArray(variants)||!selectedVariantOptions){return variants[0];}for(const variant of variants){if(variant.selectedOptions.every(option=>selectedVariantOptions[option.name]===option.value)){return variant;}}return variants[0];},[variants,selectedVariantOptions]);return selectedVariant;}\nexport const __FramerMetadata__ = {\"exports\":{\"useSelectedVariant\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useProductStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"kTAA4C,CAAa,EAA6B,EAAc,CAAC,OAAO,GAAM,WAAW,KAAK,UAAU,KAAK,UAAU,KAAK,SAAS,EAAE,MAAM,KAAK,eAAe,KAAK,IAAI,KAAK,QAAQ,KAAK,QAAQ,KAAK,CAAC,CAAc,MAAgBA,EAAW,EAAgB,ICOpS,SAAgB,EAAkB,EAAG,EAAO,CAAC,GAAK,CAAC,UAAQ,cAAY,gBAAc,EACxF,GAAU,IAAS,OAAa,OAAO,EAAO,EAAY,CAC1D,GAAkB,CAAC,IAAM,EAAc,EAAO,GAAmB,GACjE,GAAG,GAAe,EAAc,SAAS,EAAS,OAAO,EAAc,MACvE,IAAM,EAAM,EAAO,EAAY,CAC/B,GAAG,EAAc,CAAC,IAAM,EAAa,EAAc,MAAM,UAAU,CAAO,EAAc,EAAa,EAAa,EAAa,CAAC,EAAoB,EAAa,CAAC,EAAM,SAAS,EAAc,CACjJ,MAA9C,GAAO,GAAmB,GAAI,CAAC,QAAM,UAAQ,CAAQ,EAYlD,SAAS,EAAoB,EAAS,CAAC,IAAM,EAAS,EAAE,CAAC,IAAI,IAAM,KAAO,EAAa,OAAO,EAAS,IAAO,aAAY,EAAS,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