"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gem-sdk/core"),t=require("../../../helpers.js"),s=require("@gem-sdk/system"),r=require("./common/styles.js"),a=require("./common/classes.js"),i=require("./ProductBundleDiscountChildrenItem.liquid.js");exports.default=({rawChildren:d,setting:l,styles:n,advanced:u,style:o})=>{let p=l?.hasPreSelectItem?l?.selectItemDefault??0:-1,c=e=>p===e,g=(e,t)=>i.default({rawChildrenItem:d?.[t],setting:l,styles:n,isSelected:c(t),bundleItem:e}),m=s.createStyle(r.getSizeSettings(n)?.gap),f=s.createClass(a.getContainerClasses(l,u?.cssClass)),I=s.createStyle(r.getContainerStyles(m,n,o)),S=s.createStateOrContext({styles:n,settings:{useProductCompareAtPrice:l?.useProductCompareAtPrice,selectItemDefault:l?.selectItemDefault,hideNoDiscountItem:l?.hideNoDiscountItem,hasPreSelectItem:l?.hasPreSelectItem,iconItemColor:l?.iconItemColor,applyToInBetweenQuantities:l?.applyToInBetweenQuantities}});return e.template`
    <gp-product-bundle-discount
      gp-data='${JSON.stringify(S)}'
      style="${I}"
      class="${f}">
      ${s.Liquid(`
        {%- assign gempages_product_bundle = product.metafields.gp_discount.gp_discount_selected_products -%}
        {%  assign productBundleItem = gempages_product_bundle | split: '($1)'  %}
      `)}
      ${d?.map((t,r)=>e.template`
          {% for productBundle in productBundleItem %}
            ${s.Liquid(`
              {% 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 %}
            `)}
            ${s.LiquidIf(`forloop.index0 == ${r}`,g("{{ parsedAttrs | strip }}",r))}
          {% endfor %}
          `).join("")}
    </gp-product-bundle-discount>

    {% if productBundleItem %}
      ${e.RenderIf(e.isLocalEnv,`<script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-bundle-discount-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${t.getSettingPreloadData('class="gps-link" delay',"src")}="${e.baseAssetURL}/assets-v2/gp-product-bundle-discount-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
    {% endif %}
  `};
