"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),helpers=require("../../../helpers.js"),system=require("@gem-sdk/system"),styles=require("./common/styles.js"),classes=require("./common/classes.js"),ProductBundleDiscountChildrenItem_liquid=require("./ProductBundleDiscountChildrenItem.liquid.js");const ProductBundleDiscount=({rawChildren:e,setting:t,styles:s,advanced:r,style:d})=>{let a=t?.hasPreSelectItem?t?.selectItemDefault??0:-1,i=e=>a===e,l=(r,d)=>ProductBundleDiscountChildrenItem_liquid.default({index:d,rawChildrenItem:e?.[d],setting:t,styles:s,isSelected:i(d),bundleItem:r}),u=system.createStyle(styles.getSizeSettings(s)?.gap),c=system.createClass(classes.getContainerClasses(t,r?.cssClass)),n=system.createStyle(styles.getContainerStyles(u,s,d)),o=system.createStateOrContext({styles:s,settings:{useProductCompareAtPrice:t?.useProductCompareAtPrice,selectItemDefault:t?.selectItemDefault,hideNoDiscountItem:t?.hideNoDiscountItem,hasPreSelectItem:t?.hasPreSelectItem,iconItemColor:t?.iconItemColor}}),p=()=>core.RenderIf(core.isLocalEnv,`<script ${helpers.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-bundle-discount-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${helpers.getSettingPreloadData('class="gps-link" delay',"src")}="${core.baseAssetURL}/assets-v2/gp-product-bundle-discount-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`);return core.template`
    <gp-product-bundle-discount
      gp-data='${JSON.stringify(o)}'
      style="${n}"
      class="${c}">
      ${system.Liquid(`
        {%- assign gempages_product_bundle = product.metafields.gp_discount.gp_discount_selected_products -%}
        {%  assign productBundleItem = gempages_product_bundle | split: '($1)'  %}
      `)}
      ${e?.map((e,t)=>core.template`
          {% for productBundle in productBundleItem %}
            ${system.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 %}
            `)}
            ${system.LiquidIf(`forloop.index0 == ${t}`,l("{{ parsedAttrs | strip }}",t))}
          {% endfor %}
          `).join("")}
    </gp-product-bundle-discount>

    {% if productBundleItem %}
      ${p()}
    {% endif %}
  `};exports.default=ProductBundleDiscount;
