import{template as t,RenderIf as e,isLocalEnv as s,baseAssetURL as r}from"@gem-sdk/core";import{getSettingPreloadData as d}from"../../../helpers.js";import{createStyle as a,createClass as o,createStateOrContext as i,Liquid as p,LiquidIf as n}from"@gem-sdk/system";import{getSizeSettings as l,getContainerStyles as u}from"./common/styles.js";import{getContainerClasses as c}from"./common/classes.js";import m from"./ProductBundleDiscountChildrenItem.liquid.js";let f=({rawChildren:f,setting:g,styles:I,advanced:$,style:P})=>{let y=g?.hasPreSelectItem?g?.selectItemDefault??0:-1,S=t=>y===t,_=(t,e)=>m({rawChildrenItem:f?.[e],setting:g,styles:I,isSelected:S(e),bundleItem:t}),h=a(l(I)?.gap),B=o(c(g,$?.cssClass)),A=a(u(h,I,P)),j=i({styles:I,settings:{useProductCompareAtPrice:g?.useProductCompareAtPrice,selectItemDefault:g?.selectItemDefault,hideNoDiscountItem:g?.hideNoDiscountItem,hasPreSelectItem:g?.hasPreSelectItem,iconItemColor:g?.iconItemColor,applyToInBetweenQuantities:g?.applyToInBetweenQuantities}});return t`
    <gp-product-bundle-discount
      gp-data='${JSON.stringify(j)}'
      style="${A}"
      class="${B}">
      ${p(`
        {%- assign gempages_product_bundle = product.metafields.gp_discount.gp_discount_selected_products -%}
        {%  assign productBundleItem = gempages_product_bundle | split: '($1)'  %}
      `)}
      ${f?.map((e,s)=>t`
          {% for productBundle in productBundleItem %}
            ${p(`
              {% assign attrs = productBundle | split: '($3)' %}
              {% assign parsedAttrs = '' %}
              {% for attr in attrs %}
                {% assign attrParts = attr | split: '($:)' %}
                {% assign attrKey = attrParts[0] %}
                {% assign attrValue = attrParts[2] | strip %}

                {% if attrValue != '' %}
                  {% assign parsedAttrs = parsedAttrs | append: attrKey | append: '=' | append: attrValue | append: ' ' %}
                {% endif %}
              {% endfor %}
            `)}
            ${n(`forloop.index0 == ${s}`,_("{{ parsedAttrs | strip }}",s))}
          {% endfor %}
          `).join("")}
    </gp-product-bundle-discount>

    {% if productBundleItem %}
      ${e(s,`<script ${d('class="gps-link" delay',"src")}="{{ 'gp-product-bundle-discount-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${d('class="gps-link" delay',"src")}="${r}/assets-v2/gp-product-bundle-discount-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
    {% endif %}
  `};export{f as default};
