'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),core=require("@gem-sdk/core"),Text=require("../../../text/components/Text.js"),index=require("./components/variants/index.js"),Dropdown=require("./components/dropdown-swatches/Dropdown.js"),DropdownGroup=require("./components/dropdown-group/DropdownGroup.js"),NoDataState=require("../../../common/components/NoDataState.js"),system=require("@gem-sdk/system"),styles=require("./common/main/styles.js"),getAttr=require("./common/main/getAttr.js"),classes=require("./common/main/classes.js"),getData=require("./common/main/getData.js"),useGpVariants=require("./hooks/useGpVariants.js"),classes$1=require("./common/variants/classes.js"),styles$1=require("./common/variants/styles.js");const ProductVariants=e=>{let{t}=core.useI18nStore(),{builderProps:s,styles:a,setting:r}=e,{align:o,optionTypo:n,swatchItemWidth:i,dropdownItemWidth:l,swatchSpacing:c,marginBottom:p}=a??{},{label:u,showAsSwatches:m,layout:d,hasPreSelected:y}=r??{},{uid:x}=s??{},j=core.useVariants(),{mode:g,options:f,variantId:h,elementRef:w,variantGroup:D,isChangeVariant:S,selectedOptions:v,isDefaultVariant:V,getVariantConfiguration:q,redirectProductShopifyLink:R}=useGpVariants.useGpVariants(e,j),C=()=>{let e={};return core.DEVICES.forEach(t=>{let s=core.getResponsiveValueByScreen(i,t);e[t]="auto"===s}),e},N=()=>{let e={};return core.DEVICES.forEach(t=>{e[t]=l?.[t]==="fill"}),e},T=()=>{let t=f?.filter(e=>{let t=q(e.name);return!t?.hide});return t?.map((s,i)=>{let l=q(s.name),g=l?l.optionType:s.optionType,w=l?l.presets[l.optionType||"rectangle_list"]?.spacing:c,D=(y||h)&&s.name?v?.[s.name]:void 0,V=system.createClass(classes.getVariantOptionGroupClass(o)),R=system.createStyle(styles.getVariantOptionGroupStyle(c,w)),T=getData.getTextVariantTitleData(e,"React",{optionName:s.name,hasPreSelected:y,selectedOptions:v,styleOptionSelected:g}),A=system.createClass(classes$1.getWrapVariantOptionClass(d,o)),G=i===t.length-1;return jsxRuntime.jsxs("div",{className:A,style:system.createStyle(styles$1.getMarginBottomStyle(p,G)),children:[system.If(u,jsxRuntime.jsx(Text.default,{...T})),jsxRuntime.jsxs("div",{className:V,style:R,children:[m&&core.OptionSpecialStyle.includes(`${g}`)&&s.values.map(e=>{let t=(!!y||!!S||!!h)&&!!s.name&&v?.[s.name]===e.label;return jsxRuntime.jsx(index.default,{variantKey:`${s.id}-${e.id}`,showAsSwatches:m,uid:x,optionName:s.name??"",optionValue:e.label??"",name:s.name,value:e,optionNumber:f.length,optionPosition:i,...a,...r,presetConfiguration:q(s.name),checked:t,typeOfOption:g||"dropdown",swatchAutoWidth:C(),optionTypo:n},e.id)}),system.If(("dropdown"===g||m&&!core.OptionSpecialStyle.includes(`${g}`))&&"radio_buttons"!==g,jsxRuntime.jsx(Dropdown.default,{...a,...r,variants:j,option:s,initValue:D,presetConfiguration:q(s.name),swatchAutoWidth:N(),optionTypo:n,optionPosition:i,optionNumber:f.length}))]})]},s.id)})},A=system.createClass(classes.getWrapDropdownClass(o)),G=getData.getDropdownGroupData(e),b=()=>jsxRuntime.jsx("div",{className:A,children:jsxRuntime.jsx(DropdownGroup.default,{...G})});if(V&&"edit"===g)return jsxRuntime.jsx(NoDataState.default,{elementType:"secondary",description:t("Setup options like colors, sizes with product variant."),descriptionActions:[{text:t("Add new variant"),callback:R},{text:t("sync data"),callback:"syncProduct"}]});if(V)return;let O=system.createAttr(getAttr.getAttrs({uid:x,hasPreSelected:y})),$=system.createStyle(styles.getWrapperStyle(e)),k=system.createClass({"gp-flex gp-flex-col !gp-ml-0":!0});return jsxRuntime.jsx("div",{ref:w,...O,className:k,style:$,children:system.If(D,b(),T())})};exports.default=ProductVariants;
