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