import{template as e,baseAssetURL as t,isLocalEnv as o,DEVICES as i,getResponsiveValueByScreen as s}from"@gem-sdk/core";import a from"../../../text/components/Text.liquid.js";import n from"./components/variants/index.liquid.js";import r from"./components/dropdown-swatches/Dropdown.liquid.js";import p from"./components/dropdown-group/DropdownGroup.liquid.js";import{getSettingPreloadData as l}from"../../../helpers.js";import{mappingVariantStyles as d}from"./utils/mappingVariantStyles.js";import{createClass as m,createStyle as c,createAttr as u,Liquid as v,LiquidFor as f,LiquidIf as $,If as g}from"@gem-sdk/system";import{getAttrs as _}from"./common/main/getAttr.js";import{getVariantOptionGroupStyle as h,getWrapperStyle as y}from"./common/main/styles.js";import{getVariantOptionGroupClass as j,getWrapDropdownClass as w}from"./common/main/classes.js";import{getTextVariantTitleData as b,getDropdownGroupData as S}from"./common/main/getData.js";import{getWrapVariantOptionClass as P}from"./common/variants/classes.js";import{getStyleOfObject as O}from"../../helpers/function.js";import{getMarginBottomStyle as x}from"./common/variants/styles.js";import{PRODUCT_VARIANT_OPTION_MINW_STYLE as V}from"./common/const.js";import{renderOptionValuesNewFormatSwatches as N}from"./OptionVariantsNewFormat.liquid.js";import{renderOptionValuesOld as A}from"./OptionVariantsOldFormat.liquid.js";let q={desktop:!0,tablet:!0,mobile:!0},D=D=>{let{builderProps:E,styles:T,setting:k,advanced:F}=D,{align:G,swatchItemWidth:z,dropdownItemWidth:C,swatchSpacing:J,optionTypo:I,marginBottom:M}=T??{},{label:W,optionType:L,showAsSwatches:R,layout:H,hasPreSelected:K}=k??{},Q=F?.d??q,{uid:U}=E??{},B=()=>{let e={};return i.forEach(t=>{let o=s(z,t);e[t]="auto"===o}),e},X=()=>{let e={};return i.forEach(t=>{e[t]=C?.[t]==="fill"}),e},Y=k?.variantPresets?d(k?.variantPresets,T):[],Z=Y?.map(e=>(e.presets={[e.optionType]:e.presets[e.optionType]},e)),ee={...k,variantPresets:Z},et=e=>{let t={"'":"&apos;",'"':"&quot;"},o=e;for(let i in t)e.indexOf(i)>=0&&(o=o.replaceAll(i,t[i]));return o},eo=({showDropdown:t,isRenderDefault:o,typeOfOption:i})=>e`
    ${f("value in values",n({id:"{{option.name | escape | handleize}}-{{value | escape | handleize}}",variantKey:"{{option.name | escape}}-{{option.position}}-{{ forloop.index }}",showAsSwatches:R,uid:U,name:"{{option.name | escape}}",value:{label:"{{value | escape}}"},checked:K?"{%- if option.selected_value == value -%}true{% else %}false{%- endif -%}":"false",optionPosition:"rootForloop",typeOfOption:i,activeClass:K?"{%- if option.selected_value == value -%}option-item-active{%- endif -%}":"",...T,...ee,swatchAutoWidth:B(),optionTypo:I,isRenderDefault:o}))}
      ${$(t?'type == "dropdown"':"false",r({...T,...ee,swatchAutoWidth:X(),optionTypo:I}))}`,ei=k?.variantPresets?.map(e=>({name:et(e.optionName),type:e.optionType})).map(e=>`${e.name}($1)${e.type}`).join("($2)").toString(),es={renderVariantItem:eo,variantPresetsLiquid:ei??""},ea=m(j(G)),en=c(h(J,J)),er=b(D,"Liquid"),ep=m(P(H,G)),el=m(w(G)),ed=S(D),em=u(_({uid:U,hasPreSelected:K,cssClass:F?.cssClass})),ec=c(y(D)),eu=m({"gp-flex gp-flex-col !gp-ml-0":!0});return e`
    ${v("{%- assign total_combinations = 1 -%}")}
    ${f("option in product.options_with_values","{%- assign total_combinations = total_combinations | times: option.values.size -%}")}
    <gp-product-variants
      ${em}
      gp-data='{
        "setting":${JSON.stringify(ee)?.replaceAll("'","&#039;")},
        "styles":${JSON.stringify(T)},
        "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(Q)},
        "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>
      ${v("{%- assign options = product.options_with_values -%}")}
      ${v("{%- assign variants = product.variants -%}")}
      ${$("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`<div
            class="${eu}"
            style="${ec}"
          >
          ${g("groupOption"===L,`
      <div className="${el}">
        ${p(ed)}
      </div>
    `,e`
      ${v(`{%- assign presets = "${k?.variantPresets?.map(e=>`${et(e.optionName)}($2)${e.optionType}`).join("($1)")}" | split: '($1)' -%}`)}
      ${v(`{% assign hiddenPresetOptions = "${k?.variantPresets?.filter(e=>!!e?.hide)?.map(e=>e.optionName).join(",")}" | split: ',' %}`)}
      
      ${v(`{% 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 %}`)}
      
      ${v("{% assign last_option_name = filtered_options_array | last %}")}
      
      ${f("option in options",`
        <div
        option-name="{{option.name | escape}}"
        class="${ep} ${$("hiddenPresetOptions contains option.name","gp-hidden")}"
        style="${O(x(M))}${V}${v("{% if forloop.last or option.name == last_option_name %}--mb:0;--mb-mobile:0;--mb-tablet:0;{% endif %}")}"
        >
          ${v("{%- assign showVariantClass = 'variant-display' -%}")}
          ${v("{%- assign optionName = option.name  -%}")}
          ${f("preset in presets",`
            ${v("{%- assign presetDetail = preset | split: '($2)' -%}")}
            ${$("presetDetail[1] == 'dropdown' and presetDetail[0] == optionName",`${v("{%- assign showVariantClass = '' -%}")} ${v("{%- break -%}")}`)}
          `)}
          ${g(W,a(er)," ")}
          <div
              variant-option-name="{{option.name | escape}}"
              class="${ea}"
              style="${O(en)}"
            >
              ${v("{%- assign values = option.values -%}")}
              ${v("{%- assign rootForloop = forloop.index0 -%}")}
              ${v(`
                {%- if option.position == 1 -%}
                  {%- assign selectedValue = variant.option1 -%}
                {%- elsif option.position == 2 -%}
                  {%- assign selectedValue = variant.option2 -%}
                {%- else -%}
                  {%- assign selectedValue = variant.option3 -%}
                {%- endif -%}
              `)}
              ${g(!K,v("{%- assign selectedValue = null -%}"),"")}
              ${g(R,e`
      ${$("shop.metafields.GEMPAGES.swatchesJSONFormat and shop.metafields.GEMPAGES.swatchesJSONFormat != blank",N(es),A(es))}
      `,eo({showDropdown:!1,isRenderDefault:!0,typeOfOption:"optionType"}))}
          </div>
      </div>`)}
    `)}
        </div>`)}
    </gp-product-variants>

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