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