{"version":3,"file":"Shopify_ProductVariantSelector.Dh08DbWM.mjs","names":["useState","p"],"sources":["https:/framerusercontent.com/modules/IySki7zU6gj9mB2w3PpE/h31IqUNQ4B6I3NYZ0qym/Shopify_ProductVariantSelector.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{motion}from\"framer-motion\";import{cn,ProductBaseControls,ConfigControls,textProperties,isOnCanvas}from\"https://framerusercontent.com/modules/eAejHXy6apg0StNmpKvK/urqFMX8moevipl03sMG8/_framer_utils.js\";import{useProduct}from\"https://framerusercontent.com/modules/xEahqZEsyG5uoZky61jQ/4ANjnqbmpaLaLb8jiNAF/_useProduct.js\";import ComponentWrapper from\"https://framerusercontent.com/modules/hQlZBgGeLDev5WuUJA4d/efplB9Cs5ZjhxVN6gafY/ComponentWrapper.js\";function isValidColor(strColor){// Normalize input - trim whitespace and convert to lowercase\nconst color=(strColor||\"\").toLowerCase().trim();if(!color)return false;// For better testing of hex values and RGB\nconst hexPattern=/^#([0-9A-F]{3}){1,2}$/i;const rgbPattern=/^rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)$/i;const rgbaPattern=/^rgba\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d*(?:\\.\\d+)?)\\s*\\)$/i;if(hexPattern.test(color)||rgbPattern.test(color)||rgbaPattern.test(color)){return true;}// Standard CSS named colors\nconst CSS_COLORS=new Set([\"aliceblue\",\"antiquewhite\",\"aqua\",\"aquamarine\",\"azure\",\"beige\",\"bisque\",\"black\",\"blanchedalmond\",\"blue\",\"blueviolet\",\"brown\",\"burlywood\",\"cadetblue\",\"chartreuse\",\"chocolate\",\"coral\",\"cornflowerblue\",\"cornsilk\",\"crimson\",\"cyan\",\"darkblue\",\"darkcyan\",\"darkgoldenrod\",\"darkgray\",\"darkgreen\",\"darkgrey\",\"darkkhaki\",\"darkmagenta\",\"darkolivegreen\",\"darkorange\",\"darkorchid\",\"darkred\",\"darksalmon\",\"darkseagreen\",\"darkslateblue\",\"darkslategray\",\"darkslategrey\",\"darkturquoise\",\"darkviolet\",\"deeppink\",\"deepskyblue\",\"dimgray\",\"dimgrey\",\"dodgerblue\",\"firebrick\",\"floralwhite\",\"forestgreen\",\"fuchsia\",\"gainsboro\",\"ghostwhite\",\"gold\",\"goldenrod\",\"gray\",\"green\",\"greenyellow\",\"grey\",\"honeydew\",\"hotpink\",\"indianred\",\"indigo\",\"ivory\",\"khaki\",\"lavender\",\"lavenderblush\",\"lawngreen\",\"lemonchiffon\",\"lightblue\",\"lightcoral\",\"lightcyan\",\"lightgoldenrodyellow\",\"lightgray\",\"lightgreen\",\"lightgrey\",\"lightpink\",\"lightsalmon\",\"lightseagreen\",\"lightskyblue\",\"lightslategray\",\"lightslategrey\",\"lightsteelblue\",\"lightyellow\",\"lime\",\"limegreen\",\"linen\",\"magenta\",\"maroon\",\"mediumaquamarine\",\"mediumblue\",\"mediumorchid\",\"mediumpurple\",\"mediumseagreen\",\"mediumslateblue\",\"mediumspringgreen\",\"mediumturquoise\",\"mediumvioletred\",\"midnightblue\",\"mintcream\",\"mistyrose\",\"moccasin\",\"navajowhite\",\"navy\",\"oldlace\",\"olive\",\"olivedrab\",\"orange\",\"orangered\",\"orchid\",\"palegoldenrod\",\"palegreen\",\"paleturquoise\",\"palevioletred\",\"papayawhip\",\"peachpuff\",\"peru\",\"pink\",\"plum\",\"powderblue\",\"purple\",\"rebeccapurple\",\"red\",\"rosybrown\",\"royalblue\",\"saddlebrown\",\"salmon\",\"sandybrown\",\"seagreen\",\"seashell\",\"sienna\",\"silver\",\"skyblue\",\"slateblue\",\"slategray\",\"slategrey\",\"snow\",\"springgreen\",\"steelblue\",\"tan\",\"teal\",\"thistle\",\"tomato\",\"turquoise\",\"violet\",\"wheat\",\"white\",\"whitesmoke\",\"yellow\",\"yellowgreen\",// Special color values\n\"transparent\",\"currentcolor\",\"inherit\",\"initial\",\"unset\"]);// Check if it's a standard CSS color name\nif(CSS_COLORS.has(color)){return true;}// If in browser environment, use DOM as fallback\nif(typeof document!==\"undefined\"){const element=document.createElement(\"div\");element.style.color=\"\";element.style.color=strColor;return element.style.color!==\"\";}return false;}/**\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function Shopify_ProductVariantSelector(props){const{product,selectedVariant,selectVariant}=useProduct(props.productID??null,props.config,true);const[selectedOptions,setSelectedOptions]=useState({});const options=product?.options?.filter(item=>item.name!==\"Title\")??[];useEffect(()=>{if(selectedVariant){const opt={};selectedVariant?.selectedOptions.forEach(item=>{opt[item.name]=item.value;});setSelectedOptions(opt);}},[selectedVariant]);useEffect(()=>{if(product){const findedVariant=product.variants.nodes.find(variant=>{let isAllSelected=true;variant.selectedOptions.forEach(i=>{if(!selectedOptions[i.name]||selectedOptions[i.name]!==i.value){isAllSelected=false;}});return isAllSelected;});if(findedVariant){selectVariant(findedVariant,null);}}// eslint-disable-next-line react-hooks/exhaustive-deps\n},[selectedOptions,product]);const isOptionAvailable=(optionName,value)=>{if(!product)return false;return product.variants.nodes.some(variant=>{return variant.selectedOptions.every(opt=>{if(opt.name===optionName){return opt.value===value;}return selectedOptions[opt.name]===opt.value;});});};return /*#__PURE__*/_jsx(ComponentWrapper,{style:cn(styles.container,props.wrapper),name:\"ProductVariantSelector\",hidden:!product||options.length===0,productID:props.productID||\"EMPTY\",config:props.config,children:options.map(option=>/*#__PURE__*/_jsxs(\"div\",{style:styles.optionWrapper,children:[/*#__PURE__*/_jsx(\"span\",{style:cn(props.label),children:option.name}),/*#__PURE__*/_jsx(\"div\",{style:cn(styles.valuesWrapper),children:option.values.map(value=>{const isSelected=selectedOptions[option.name]===value;const isAvailable=isOptionAvailable(option.name,value);if(props.hideUnavailable&&!isAvailable)return null;const animateStyle=isSelected?cn(props.selectedOption):undefined;const unavailableStyle=!isAvailable?{pointerEvents:\"none\",opacity:.8}:{};return /*#__PURE__*/_jsxs(motion.button,{type:\"button\",onClick:()=>{if(!isAvailable)return;setSelectedOptions(state=>({...state,[option.name]:value}));},style:cn(styles.option,props.variantItem,unavailableStyle,isOnCanvas()&&animateStyle),animate:animateStyle?animateStyle:undefined,transition:{duration:.2},children:[props.supportColors&&isValidColor(value.toLowerCase())&&/*#__PURE__*/_jsx(\"div\",{style:cn(props.colorVariant,{width:props.colorVariant.size,height:props.colorVariant.size,background:value})}),value]},value);})})]},option.id))});}Shopify_ProductVariantSelector.displayName=\"Product Variant Selector\";addPropertyControls(Shopify_ProductVariantSelector,{...ConfigControls,...ProductBaseControls,wrapper:{type:ControlType.Object,buttonTitle:\"Style\",controls:{gap:{type:ControlType.Number,defaultValue:16,min:0},flexDirection:{title:\"Direction\",type:ControlType.Enum,options:[\"row\",\"column\"],optionTitles:[\"Row\",\"Column\"],defaultValue:\"column\"}}},label:{type:ControlType.Object,buttonTitle:\"Style\",controls:{display:{title:\"Visibility\",type:ControlType.Enum,options:[\"block\",\"none\"],optionTitles:[\"Visible\",\"Hidden\"],defaultValue:\"column\"},...textProperties(14,\"#919191\")}},variantItem:{title:\"Variant\",type:ControlType.Object,buttonTitle:\"Style\",controls:{...textProperties(16,\"#666666\"),backgroundColor:{type:ControlType.Color,defaultValue:\"#F5F5F5\",optional:true},border:{type:ControlType.Border,defaultValue:{borderWidth:0}},borderRadius:{type:ControlType.BorderRadius,defaultValue:\"10px\"},gap:{type:ControlType.Number,defaultValue:4,min:0},padding:{type:ControlType.Padding,defaultValue:\"10px 16px 10px 16px\"}}},selectedOption:{type:ControlType.Object,buttonTitle:\"Style\",controls:{color:{type:ControlType.Color,defaultValue:\"#fff\",optional:true},backgroundColor:{type:ControlType.Color,defaultValue:\"#000\",optional:true},border:{type:ControlType.Border,defaultValue:{borderWidth:0}}}},supportColors:{type:ControlType.Boolean,description:\"Show colors nested with their color names\",defaultValue:false},colorVariant:{type:ControlType.Object,buttonTitle:\"Style\",hidden:p=>!p.supportColors,controls:{borderRadius:{type:ControlType.BorderRadius,defaultValue:\"12px\"},size:{type:ControlType.Number,defaultValue:12,min:0},border:{type:ControlType.Border,defaultValue:{borderWidth:0}}}},hideUnavailable:{type:ControlType.Boolean,title:\"Unavailable\",description:\"Hide unavailable variant options\",enabledTitle:\"Hide\",disabledTitle:\"Show\",defaultValue:true}});const styles={container:{display:\"flex\",flexWrap:\"wrap\"},option:{display:\"flex\",flexDirection:\"row\",alignItems:\"center\",cursor:\"pointer\"},optionWrapper:{display:\"flex\",flexDirection:\"column\",gap:6},valuesWrapper:{display:\"flex\",gap:8,flexWrap:\"wrap\"}};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Shopify_ProductVariantSelector\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"sYAA4lB,SAAS,EAAa,EAAS,CAC3nB,IAAM,GAAO,GAAU,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,EAAM,MAAO,GAIjE,GAHiB,yBAAyN,KAAK,EAAM,EAA1L,4DAAuM,KAAK,EAAM,EAApI,mFAAkJ,KAAK,EAAM,EACrR,IAAI,IAAI,y/CACgC,CAAC,CAC5C,IAAI,EAAM,CAAE,MAAO,GACjC,GAAG,OAAO,SAAW,IAAY,CAAC,IAAM,EAAQ,SAAS,cAAc,MAAM,CAAqD,MAApD,GAAQ,MAAM,MAAM,GAAG,EAAQ,MAAM,MAAM,EAAgB,EAAQ,MAAM,QAAQ,GAAI,MAAO,GAIvK,SAAwB,EAA+B,EAAM,CAAC,GAAK,CAAC,UAAQ,kBAAgB,iBAAe,EAAW,EAAM,WAAW,KAAK,EAAM,OAAO,GAAK,CAA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