"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gem-sdk/core"),t=require("../../../text/components/Text.liquid.js"),i=require("./components/variants/index.liquid.js"),s=require("./components/dropdown-swatches/Dropdown.liquid.js"),a=require("./components/dropdown-group/DropdownGroup.liquid.js"),o=require("../../../helpers.js"),n=require("./utils/mappingVariantStyles.js"),r=require("@gem-sdk/system"),p=require("./common/main/getAttr.js"),l=require("./common/main/styles.js"),d=require("./common/main/classes.js"),u=require("./common/main/getData.js"),c=require("./common/variants/classes.js"),m=require("../../helpers/function.js"),v=require("./common/variants/styles.js"),f=require("./common/const.js"),g=require("./OptionVariantsNewFormat.liquid.js"),_=require("./OptionVariantsOldFormat.liquid.js");const $={desktop:!0,tablet:!0,mobile:!0};exports.default=q=>{let{builderProps:y,styles:h,setting:j,advanced:S}=q,{align:L,swatchItemWidth:O,dropdownItemWidth:w,swatchSpacing:V,optionTypo:b,marginBottom:P}=h??{},{label:D,optionType:I,showAsSwatches:N,layout:x,hasPreSelected:A}=j??{},C=S?.d??$,{uid:E}=y??{},T=()=>{let t={};return e.DEVICES.forEach(i=>{let s=e.getResponsiveValueByScreen(O,i);t[i]="auto"===s}),t},F=()=>{let t={};return e.DEVICES.forEach(e=>{t[e]=w?.[e]==="fill"}),t},G=j?.variantPresets?n.mappingVariantStyles(j?.variantPresets,h):[],k=G?.map(e=>(e.presets={[e.optionType]:e.presets[e.optionType]},e)),W={...j,variantPresets:k},z=e=>{let t={"'":"&apos;",'"':"&quot;"},i=e;for(let s in t)e.indexOf(s)>=0&&(i=i.replaceAll(s,t[s]));return i},M=({showDropdown:t,isRenderDefault:a,typeOfOption:o})=>e.template`
    ${r.LiquidFor("value in values",i.default({id:"{{option.name | escape | handleize}}-{{value | escape | handleize}}",variantKey:"{{option.name | escape}}-{{option.position}}-{{ forloop.index }}",showAsSwatches:N,uid:E,name:"{{option.name | escape}}",value:{label:"{{value | escape}}"},checked:A?"{%- if option.selected_value == value -%}true{% else %}false{%- endif -%}":"false",optionPosition:"rootForloop",typeOfOption:o,activeClass:A?"{%- if option.selected_value == value -%}option-item-active{%- endif -%}":"",...h,...W,swatchAutoWidth:T(),optionTypo:b,isRenderDefault:a}))}
      ${r.LiquidIf(t?'type == "dropdown"':"false",s.default({...h,...W,swatchAutoWidth:F(),optionTypo:b}))}`,R=j?.variantPresets?.map(e=>({name:z(e.optionName),type:e.optionType})).map(e=>`${e.name}($1)${e.type}`).join("($2)").toString(),J={renderVariantItem:M,variantPresetsLiquid:R??""},U=r.createClass(d.getVariantOptionGroupClass(L)),B=r.createStyle(l.getVariantOptionGroupStyle(V,V)),H=u.getTextVariantTitleData(q,"Liquid"),K=r.createClass(c.getWrapVariantOptionClass(x,L)),Q=r.createClass(d.getWrapDropdownClass(L)),Y=u.getDropdownGroupData(q),X=r.createAttr(p.getAttrs({uid:E,hasPreSelected:A,cssClass:S?.cssClass})),Z=r.createStyle(l.getWrapperStyle(q)),ee=r.createClass({"gp-flex gp-flex-col !gp-ml-0":!0});return e.template`
    ${r.Liquid("{%- assign total_combinations = 1 -%}")}
    ${r.LiquidFor("option in product.options_with_values","{%- assign total_combinations = total_combinations | times: option.values.size -%}")}
    <gp-product-variants
      ${X}
      gp-data='{
        "setting":${JSON.stringify(W)?.replaceAll("'","&#039;")},
        "styles":${JSON.stringify(h)},
        "variants":{{product.variants | json | escape}},
        "optionsWithValues": {{product.options_with_values | json | escape}},
        "variantSelected": {{ variant | json | escape }},
        "variantInventoryQuantity": {{product.variants | map: 'inventory_quantity' | json | escape}},
        "variantInventoryPolicy": {{product.variants | map: 'inventory_policy' | json | escape}},
        "moneyFormat": {{shop.money_format | json | escape}},
        "productId": {{product.id | json | escape}},
        "productUrl": {{product.url | json | escape}},
        "productHandle": {{product.handle | json | escape}},
        "displayState": ${JSON.stringify(C)},
        "totalVariantCombinations": {{total_combinations}},
        "firstAvailableVariant": {{product.selected_or_first_available_variant | json | escape}}
      }
    '>
      <div class="gp-hidden" style="--hvr-shadow: none; --hvr-shadow-tablet: none; --hvr-shadow-mobile: none"></div>
      ${r.Liquid("{%- assign options = product.options_with_values -%}")}
      ${r.Liquid("{%- assign variants = product.variants -%}")}
      ${r.LiquidIf("options.size == 0 or options.size == 1 and variants.size == 1 and variants[0].title == 'Default Title' and variants[0].option1 == 'Default Title'","<div></div>",e.template`<div
            class="${ee}"
            style="${Z}"
          >
          ${r.If("groupOption"===I,`
      <div className="${Q}">
        ${a.default(Y)}
      </div>
    `,e.template`
      ${r.Liquid(`{%- assign presets = "${j?.variantPresets?.map(e=>`${z(e.optionName)}($2)${e.optionType}`).join("($1)")}" | split: '($1)' -%}`)}
      ${r.Liquid(`{% assign hiddenPresetOptions = "${j?.variantPresets?.filter(e=>!!e?.hide)?.map(e=>e.optionName).join(",")}" | split: ',' %}`)}
      
      ${r.Liquid(`{% assign all_option_names = options | map: 'name' %}
      {% assign filtered_options_string = '' %}
      {% assign delimiter = '||' %}
      
      {% for item_name in all_option_names %}
        {% assign is_excluded = false %}
        {% for exclude_name in hiddenPresetOptions %}
          {% if item_name == exclude_name %}
            {% assign is_excluded = true %}
          {% endif %}
        {% endfor %}
        
        {% unless is_excluded %}
          {% if filtered_options_string == '' %}
            {% assign filtered_options_string = item_name %}
          {% else %}
            {% assign filtered_options_string = filtered_options_string | append: delimiter | append: item_name %}
          {% endif %}
        {% endunless %}
      {% endfor %}
      
      {% assign filtered_options_array = filtered_options_string | split: delimiter %}`)}
      
      ${r.Liquid("{% assign last_option_name = filtered_options_array | last %}")}
      
      ${r.LiquidFor("option in options",`
        <div
        option-name="{{option.name | escape}}"
        class="${K} ${r.LiquidIf("hiddenPresetOptions contains option.name","gp-hidden")}"
        style="${m.getStyleOfObject(v.getMarginBottomStyle(P))}${f.PRODUCT_VARIANT_OPTION_MINW_STYLE}${r.Liquid("{% if forloop.last or option.name == last_option_name %}--mb:0;--mb-mobile:0;--mb-tablet:0;{% endif %}")}"
        >
          ${r.Liquid("{%- assign showVariantClass = 'variant-display' -%}")}
          ${r.Liquid("{%- assign optionName = option.name  -%}")}
          ${r.LiquidFor("preset in presets",`
            ${r.Liquid("{%- assign presetDetail = preset | split: '($2)' -%}")}
            ${r.LiquidIf("presetDetail[1] == 'dropdown' and presetDetail[0] == optionName",`${r.Liquid("{%- assign showVariantClass = '' -%}")} ${r.Liquid("{%- break -%}")}`)}
          `)}
          ${r.If(D,t.default(H)," ")}
          <div
              variant-option-name="{{option.name | escape}}"
              class="${U}"
              style="${m.getStyleOfObject(B)}"
            >
              ${r.Liquid("{%- assign values = option.values -%}")}
              ${r.Liquid("{%- assign rootForloop = forloop.index0 -%}")}
              ${r.Liquid(`
                {%- if option.position == 1 -%}
                  {%- assign selectedValue = variant.option1 -%}
                {%- elsif option.position == 2 -%}
                  {%- assign selectedValue = variant.option2 -%}
                {%- else -%}
                  {%- assign selectedValue = variant.option3 -%}
                {%- endif -%}
              `)}
              ${r.If(!A,r.Liquid("{%- assign selectedValue = null -%}"),"")}
              ${r.If(N,e.template`
      ${r.LiquidIf("shop.metafields.GEMPAGES.swatchesJSONFormat and shop.metafields.GEMPAGES.swatchesJSONFormat != blank",g.renderOptionValuesNewFormatSwatches(J),_.renderOptionValuesOld(J))}
      `,M({showDropdown:!1,isRenderDefault:!0,typeOfOption:"optionType"}))}
          </div>
      </div>`)}
    `)}
        </div>`)}
    </gp-product-variants>

    ${(()=>{let t=e.isLocalEnv?"{{ 'gp-product-variant-v7-5.js' | asset_url }}":`${e.baseAssetURL}/assets-v2/gp-product-variant-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;return`<script ${o.getSettingPreloadData('class="gps-link" delay',"src")}="${t}" defer="defer"></script>`})()}
  `};
