"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),helpers=require("../../../helpers.js"),common=require("./utils/common.js"),generateLiquidContent=require("./utils/generateLiquidContent.js"),renderBadgeLiquid=require("./utils/renderBadgeLiquid.js"),system=require("@gem-sdk/system"),constants=require("./constants.js"),styles=require("./common/styles.js"),classes=require("./common/classes.js"),attrs=require("./common/attrs.js");const ProductBadge=e=>{let{styles:t,setting:s,builderProps:r,pageContext:a}=e,i=s?.shape!=="image",c=common.checkDiscountContentProductBadge(s?.displayContent),n=system.createStyle({...styles.getContainerStyle(e,constants.IS_LIQUID)}),l=system.createClass({...classes.getWrapperClasses(e)}),o=system.createClass({...classes.getSubWrapperClass(e)}),d=system.createStyle({...styles.getSubWrapperStyle(e)}),p=system.createAttr({...attrs.getSubWrapperAttrs(e)}),u=styles.getContentStyleInternal(e),y=system.createClass({...classes.getTextContainerClasses()}),g=system.createAttr({...attrs.getContainerAttrs(e)}),m=system.createClass({...classes.getTextWrapperClasses()}),C=system.createStyle({...styles.getTextBadgeWrapperStyles({setting:s,styles:t})}),v=system.createClass({...classes.getTextContentClasses(t)}),S=system.createStyle({...styles.getTextContentStyle({setting:s,styles:t})}),$=system.createAttr({...attrs.getTextContentAttrs()}),q=system.createClass({...classes.getImageContainerClasses()}),I=system.createStyle({...styles.getImageContainerStyles({setting:s,styles:t})}),j=system.createClass({...classes.getImageClasses()}),D=system.createAttr({...attrs.getImageAttr({setting:s})}),P=system.createStateOrContext({minPrice:"{{ minPriceValue | replace: '\"', '\\\"' | escape }}",variantIDs:'{{  product.variants | map: "id" | json | escape }}',variantInventoryQuantities:'{{ product.variants | map: "inventory_quantity" | json | escape }}',amountDiscount:"{{amountDiscountValue | replace: '\"', '\\\"' | escape }}",percentDiscount:"{{percentDiscountValue}}",price:"{{price}}",displayTrigger:JSON.parse(JSON.stringify(s?.displayTrigger).replaceAll("'","&#039;")),uid:e.builderProps?.uid,productCreatedAt:'{{product.created_at | date: "%Y-%m-%d" }}',productTags:"{{ product.tags | join: \",\" | replace: '\"', '\\\"' | escape }}",isTextBadge:i}),{displayContent:f,translate:A}=s??{},L=helpers.getDynamicSourceLocales({val:f?.trim(),uid:r?.uid,settingId:"displayContent",isLiquid:!0,pageContext:a,translate:A});return core.template`
    {% if product %}
      ${generateLiquidContent.generateBadgeContent(L,a?.isPreviewing)}
      ${renderBadgeLiquid.renderBadgeInFirstTime(s?.displayTrigger,c,i)}
      <gp-product-badge
        ${{...g}}
        gp-data='${core.dataStringify(P)}'
        class="containerClass {{className}}"
        style="${n}"
        data-display-content="${a?.isPreviewing?L:core.sanitizeLiquid(`{{${L}}}`)}"
      >
        <div class="${l}">
          <div
            ${{...p}}
            class="${o}"
            style="${d}"
          >
            <style>${u}</style>
            ${core.RenderIf(i,core.template`
                <div class="${y}">
                  <div
                    class="${m}"
                    style="${C}"
                  >
                    <pre
                      ${{...$}}
                      class="${v}"
                      style="${S}"
                    >{{ content | replace: percentDiscountKey, percentDiscountValue | replace: amountDiscountKey, amountDiscountValue | replace: inventoryQuantityKey, inventoryQuantityValue | replace: minPriceKey, minPriceValue }}</pre>
                  </div>
                </div>`,core.template`<div class="${q}" style="${I}">
                  <img ${{...D}} class="${j}" alt="" />
                </div>`)}
          </div>
        </div>
      </gp-product-badge>
       ${core.RenderIf(core.isLocalEnv,`<script ${helpers.getSettingPreloadData('class="gps-link" delay',"src")}="{{ 'gp-product-badge-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${helpers.getSettingPreloadData('class="gps-link" delay',"src")}="${core.baseAssetURL}/assets-v2/gp-product-badge-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
    {% endif %}
  `};exports.default=ProductBadge;
