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