import{template as e}from"@gem-sdk/core";import{Liquid as s,LiquidIf as i}from"@gem-sdk/system";import{OPTION_VALUES_DELIMITER as n}from"./common/const.js";let renderOptionValuesNewFormatSwatches=t=>{let{renderVariantItem:o,variantPresetsLiquid:r}=t;return e`
    ${s("{%- assign optionRendered = false -%}")}
    ${s("{%- assign swatches = shop.metafields.GEMPAGES.swatchesJSONFormat.value -%}")}

    ${s(`{% for swatch in swatches %}
      {%- assign optionTitle = swatch.optionTitle -%}
      {%- assign optionType = swatch.optionType -%}
      {%- assign labelsString = "" -%}
      {%- assign colorArraysString = "" -%}
      {%- assign imageUrlsString = "" -%}

      {% for optionValue in swatch.optionValues %}
        {%- assign labelsString = labelsString | append: optionValue.label | append: '${n}' -%}
        {%- assign colorsJoined = optionValue.colors | join: '${n}' -%}
        {%- assign colorArraysString = colorArraysString | append: colorsJoined | append: '${n}' -%}
        {%- assign imageUrlsString = imageUrlsString | append: optionValue.imageUrl | append: '${n}' -%}
      {% endfor %}

      {%- assign labels = labelsString | split: '${n}' | slice: 0, labelsString.size -%}
      {%- assign colorStrings = colorArraysString | split: '${n}' | slice: 0, colorArraysString.size -%}
      {%- assign imageUrls = imageUrlsString | split: '${n}' | slice: 0, imageUrlsString.size -%}

      {% if optionTitle == option.name %}
        {%- assign variantPresetString = "${r}" -%}
        {%- assign optionName = option.name | replace: "'", "&apos;" | replace: '"', "&quot;" -%}
        {%- assign items = variantPresetString | split: '($2)' -%}
        {%- assign type = 'dropdown' -%}

        {% for item in items %}
          {%- assign itemPreset = item | split: '($1)' -%}
          {% if itemPreset[0] == optionName %}{%- assign type = itemPreset[1] -%}{% endif %}
          {% if itemPreset[0] == 'base' %}{%- assign type = itemPreset[1] -%}{% endif %}
        {% endfor %}
        {%- assign optionRendered = true -%}

        ${o({showDropdown:!0})}
      {% endif %}
    {% endfor %}`)}

    ${i("optionRendered == false",o({showDropdown:!1,isRenderDefault:!0,typeOfOption:"optionType"}))}
  `};export{renderOptionValuesNewFormatSwatches};
