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