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