"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),helpers=require("../../../helpers.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"),common=require("./utils/common.js"),translate=require("../../settings/product-badge/configs/translate.js");const ProductBadge=e=>{let{styles:t,setting:s,builderProps:a,pageContext:r}=e,i=s?.shape!=="image",n=i&&s?.displayContent?.trim()==="",c=common.checkDiscountContentProductBadge(s?.displayContent),l=system.createClass({...classes.getContainerClasses({isInstant:!1,props:e})}),o=system.createStyle({...styles.getContainerStyle(e,constants.IS_LIQUID)}),d=system.createClass({...classes.getWrapperClasses(e)}),p=system.createClass({...classes.getSubWrapperClass(e)}),u=system.createStyle({...styles.getSubWrapperStyle({props:e})}),y=system.createAttr({...attrs.getSubWrapperAttrs(e)}),g=styles.getContentStyleInternal(e),m=system.createClass({...classes.getTextContainerClasses()}),C=system.createAttr({...attrs.getContainerAttrs(e)}),v=system.createClass({...classes.getTextWrapperClasses()}),$=system.createStyle({...styles.getTextBadgeWrapperStyles({setting:s,styles:t})}),S=system.createClass({...classes.getTextContentClasses(t)}),q=system.createStyle({...styles.getTextContentStyle({setting:s,styles:t})}),I=system.createAttr({...attrs.getTextContentAttrs()}),j=system.createClass({...classes.getImageContainerClasses()}),P=system.createStyle({...styles.getImageContainerStyles({setting:s,styles:t})}),f=system.createClass({...classes.getImageClasses()}),D=system.createAttr({...attrs.getImageAttr({setting:s})}),A=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:L}=s??{},T=helpers.getDynamicSourceLocales({val:L?.trim(),uid:a?.uid,settingId:translate.ProductBadge?.displayContent?.id,isLiquid:!0,pageContext:r});return core.template`
    {% if product %}
      ${generateLiquidContent.generateBadgeContent(T,r?.isPreviewing)}
      ${renderBadgeLiquid.renderBadgeInFirstTime(s?.displayTrigger,!n,c)}
      <gp-product-badge
        ${{...C}}
        gp-data='${core.dataStringify(A)}'
        class="${l} {{ className }}"
        style="${o}"
        data-display-content="${r?.isPreviewing?T:core.sanitizeLiquid(`{{${T}}}`)}"
      >
        <div class="${d}">
          <div
            ${{...y}}
            class="${p}"
            style="${u}"
          >
            <style>${g}</style>
            ${core.RenderIf(i,core.template`
                <div class="${m}">
                  <div
                    class="${v}"
                    style="${$}"
                  >
                    <pre
                      ${{...I}}
                      class="${S}"
                      style="${q}"
                    >{{ content | replace: percentDiscountKey, percentDiscountValue | replace: amountDiscountKey, amountDiscountValue | replace: inventoryQuantityKey, inventoryQuantityValue | replace: minPriceKey, minPriceValue }}</pre>
                  </div>
                </div>`,core.template`<div class="${j}" style="${P}">
                  <img ${{...D}} class="${f}" 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;
