{"version":3,"file":"Collection_variant_preference.5L_zMaDA.mjs","names":["useState","useMemo","useCallback","_jsx","useContext","createContext","__esmMin","ne","init_npm_react_18_3_1","oe","pe","init_jsx_runtime","B","_e","CollectionVariantPreferenceProvider","children","value","variantOverrides","setVariantOverrides","explicitVariantOverrideByProductId","activeOverrides","productId","override","setExplicitVariantOverride","variantId","currentOverrides","contextValue","c","CollectionVariantPreferenceContext","useCollectionVariantPreference","DEFAULT_COLLECTION_VARIANT_PREFERENCE","init_Collection_variant_preference_context","normalizeCollectionVariantText","doesProductVariantMatchCriteria","variant","criteria","criterion","normalizedGroupName","selectedValues","option","resolveEffectiveProductVariant","variants","explicitVariant","init_Collection_variant_preference"],"sources":["https:/framerusercontent.com/modules/i7ZQIq8WO7VzqaEGgq3A/rPdbdxj6dhOjzJYEaBer/Collection_variant_preference_context.js","https:/framerusercontent.com/modules/Ep4l0IXbghfZTQHUUsaQ/2ydcKli7zrf0qcCBe8RI/Collection_variant_preference.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{createContext,useCallback,useContext,useMemo,useState}from\"react\";const DEFAULT_COLLECTION_VARIANT_PREFERENCE={criteria:Object.freeze([]),explicitVariantOverrideByProductId:Object.freeze({}),setExplicitVariantOverride:()=>undefined};const CollectionVariantPreferenceContext=/*#__PURE__*/createContext(DEFAULT_COLLECTION_VARIANT_PREFERENCE);export function CollectionVariantPreferenceProvider({children,value}){const[variantOverrides,setVariantOverrides]=useState({});const explicitVariantOverrideByProductId=useMemo(()=>{const activeOverrides={};for(const[productId,override]of Object.entries(variantOverrides)){if(override.criteria===value.criteria){activeOverrides[productId]=override.variantId;}}return activeOverrides;},[value.criteria,variantOverrides]);const setExplicitVariantOverride=useCallback((productId,variantId)=>{if(!productId||!variantId)return;setVariantOverrides(currentOverrides=>({...currentOverrides,[productId]:{criteria:value.criteria,variantId}}));},[value.criteria]);const contextValue=useMemo(()=>({...value,explicitVariantOverrideByProductId,setExplicitVariantOverride}),[explicitVariantOverrideByProductId,setExplicitVariantOverride,value]);return /*#__PURE__*/_jsx(CollectionVariantPreferenceContext.Provider,{value:contextValue,children:children});}export function useCollectionVariantPreference(){return useContext(CollectionVariantPreferenceContext);}\nexport const __FramerMetadata__ = {\"exports\":{\"useCollectionVariantPreference\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CollectionVariantPreferenceProvider\":{\"type\":\"reactComponent\",\"name\":\"CollectionVariantPreferenceProvider\",\"slots\":[\"children\"],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Collection_variant_preference_context.map","export function normalizeCollectionVariantText(value){return typeof value===\"string\"?value.trim().toLowerCase():\"\";}export function doesProductVariantMatchCriteria(variant,criteria){if(!variant||criteria.length===0){return criteria.length===0;}if(!Array.isArray(variant.selectedOptions)){return false;}return criteria.every(criterion=>{const normalizedGroupName=normalizeCollectionVariantText(criterion.groupName);const selectedValues=new Set(criterion.selectedValues.map(normalizeCollectionVariantText).filter(Boolean));if(!normalizedGroupName||selectedValues.size===0){return false;}return variant.selectedOptions?.some(option=>normalizeCollectionVariantText(option?.name)===normalizedGroupName&&selectedValues.has(normalizeCollectionVariantText(option?.value)));});}export function resolveEffectiveProductVariant({variants,explicitVariant,criteria}){if(criteria.length===0){return explicitVariant;}if(doesProductVariantMatchCriteria(explicitVariant,criteria)){return explicitVariant;}return variants.find(variant=>doesProductVariantMatchCriteria(variant,criteria))??null;}\nexport const __FramerMetadata__ = {\"exports\":{\"ProductVariantWithSelectedOptions\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"resolveEffectiveProductVariant\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"normalizeCollectionVariantText\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"doesProductVariantMatchCriteria\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CollectionVariantCriterion\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Collection_variant_preference.map"],"mappings":"A,yIAAsY,SAAgBc,EAAoC,CAACC,WAASC,SAAO,CAAC,GAAK,CAACC,EAAiBC,GAAqBlB,EAAS,CAAC,CAAC,EAAQmB,EAAmClB,MAAY,CAAC,IAAMmB,EAAgB,CAAC,EAAE,IAAI,GAAK,CAACC,EAAUC,KAAY,OAAO,QAAQL,CAAgB,EAAMK,EAAS,WAAWN,EAAM,WAAUI,EAAgBC,GAAWC,EAAS,WAAY,OAAOF,CAAgB,EAAE,CAACJ,EAAM,SAASC,CAAgB,CAAC,EAAQM,EAA2BrB,GAAamB,EAAUG,IAAY,CAAKH,GAAYG,GAAiBN,EAAoBO,IAAmB,CAAC,GAAGA,GAAkBJ,GAAW,CAAC,SAASL,EAAM,SAASQ,WAAS,CAAC,EAAE,CAAE,EAAE,CAACR,EAAM,QAAQ,CAAC,EAAQU,EAAazB,OAAa,CAAC,GAAGe,EAAMG,qCAAmCI,4BAA0B,GAAG,CAACJ,EAAmCI,EAA2BP,CAAK,CAAC,EAAE,MAAoBb,gBAAKyB,EAAmC,SAAS,CAAC,MAAMF,EAAsBX,UAAQ,CAAC,CAAE,CAAC,SAAgBc,GAAgC,CAAC,OAAOzB,EAAWwB,CAAkC,CAAE,C,8CAA9xCE,EAAsC,CAAC,SAAS,OAAO,OAAO,CAAC,CAAC,EAAE,mCAAmC,OAAO,OAAO,CAAC,CAAC,EAAE,+BAA+B,IAAA,EAAS,EAAQF,EAAgDvB,gBAAcyB,CAAqC,C,OCApY,SAAgBE,EAA+BhB,EAAM,CAAC,OAAO,OAAOA,GAAQ,SAASA,EAAM,KAAK,CAAC,CAAC,YAAY,EAAE,EAAG,CAAC,SAAgBiB,EAAgCC,EAAQC,EAAS,CAAyH,MAArH,CAACD,GAASC,EAAS,SAAS,EAAUA,EAAS,SAAS,EAAO,M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