'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),React=require("react"),common=require("../../common/common.js"),system=require("@gem-sdk/system"),classes=require("../../common/base/classes.js"),attrs=require("../../common/base/attrs.js"),styles=require("../../common/base/styles.js");const BaseVariant=e=>{let{value:s,checked:t,optionTypography:r,optionTypo:a,swatchesImage:l,swatchesColor:m,preset:c,typeOfOption:i,available:o,variantKey:n,soldOutMarkLine:y}=e,x=React.useMemo(()=>"color"===i,[i]),u=c?.optionBgColor,j=c?.optionBorder,g=c?.optionRounded,p=React.useMemo(()=>"image"===i||"image_shopify"===i,[i]),d=React.useMemo(()=>t?common.isColorDark(u?.active)?"#fff":"#121212":common.isColorDark(u?.normal)?"#fff":"#121212",[u?.active,u?.normal,t]),C=e=>common.isColorDark(e)?"#fff":"#121212",f=()=>system.If(y,jsxRuntime.jsx("style",{children:`
        .${n}:before {
          width: ${x&&m?.length?`calc(${c?.height} - 12px) !important`:"200px !important"};
          border-color: ${x?"#121212":d};
        }
        `})," "),h=system.createClass(classes.getColorClass({soldOutMarkLine:y,available:o})),R=()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:m?.map(e=>{let s=e,r=e.startsWith("linear-gradient");r&&(s=e.match(/#(([\da-fA-F]{2}){3,4}|([\da-fA-F]){3,4})/g)?.[0]);let a=system.createStyle(styles.getColorStyle({optionRounded:g,optionBorder:j,isActive:t,color:e}));return jsxRuntime.jsxs(React.Fragment,{children:[jsxRuntime.jsx("style",{children:`
                .${n} .color:before {
                  border-color: ${C(s)} !important;
                }
                `}),jsxRuntime.jsx("div",{className:h,style:a},e)]},e)})}),v=system.createClass(classes.getWrapperTextClass(p,x)),b=system.createStyle(styles.getWrapperTextStyle(e)),S=system.createClass(classes.getTextClass({optionTypo:a,optionTypography:r,isColorType:x,isUploadImageType:p})),w=system.createStyle(styles.getTextStyle({optionTypo:a,optionTypography:r})),D=()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:v,style:b,children:[f(),system.If(p,jsxRuntime.jsxs("svg",{width:"15",height:"12",viewBox:"0 0 15 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("circle",{cx:"2",cy:"2",r:"2",fill:"#D6D6D6"}),jsxRuntime.jsx("path",{d:"M0.196854 10.6453L2.40968 8.05946C2.4846 7.97175 2.57719 7.9008 2.68141 7.85124C2.78562 7.80168 2.89913 7.77461 3.01452 7.77181C3.12991 7.76902 3.2446 7.79055 3.3511 7.835C3.45761 7.87945 3.55353 7.94583 3.63262 8.02981L4.66733 9.12714L8.71205 4.29464C8.79123 4.19995 8.89077 4.1243 9.00325 4.07333C9.11573 4.02236 9.23827 3.99737 9.36176 4.00022C9.48524 4.00307 9.6065 4.03369 9.71651 4.08979C9.82651 4.1459 9.92245 4.22605 9.99717 4.32429L14.8329 10.6772C14.9254 10.7989 14.982 10.9441 14.9964 11.0962C15.0107 11.2484 14.9823 11.4016 14.9144 11.5385C14.8464 11.6754 14.7415 11.7907 14.6115 11.8713C14.4815 11.952 14.3316 11.9948 14.1786 11.995L0.822048 12C0.664945 11.9999 0.511148 11.9549 0.378853 11.8703C0.246557 11.7857 0.141299 11.6649 0.0755311 11.5224C0.00976323 11.3799 -0.013762 11.2216 0.00773837 11.0661C0.0292388 10.9107 0.0948652 10.7646 0.196854 10.6453Z",fill:"#D6D6D6"})]})),jsxRuntime.jsx("span",{className:S,style:w,children:s?.label})]})}),q=()=>jsxRuntime.jsx("img",{className:"gp-h-full gp-w-full gp-object-cover",src:l,alt:""}),A=()=>{switch(i){case"color":return system.If(m&&m.length>0,R(),D());case"image":case"image_shopify":return system.If(!!l,q(),D());default:return D()}},W=system.createClass(classes.getWrapperClass(e)),N=system.createAttr(attrs.getWrapperAttr(e)),$=system.createStyle(styles.getWrapperStyleActive(e)),k=system.createStyle(styles.getWrapperStyleNormalAndHover(e)),B=t?$:k;return jsxRuntime.jsxs("div",{...N,className:W,style:B,children:[f(),A()]})};exports.default=BaseVariant;
