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 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";import{ProductBadge as _}from"../../settings/product-badge/configs/translate.js";let h=h=>{let{styles:B,setting:L,builderProps:O,pageContext:Q}=h,w=L?.shape!=="image",G=w&&L?.displayContent?.trim()==="",J=N(L?.displayContent),x=d({...D({isInstant:!1,props:h})}),M=l({...y(h,g)}),R=d({...V(h)}),Y=d({...S(h)}),z=l({...$({props:h})}),F=u({...q(h)}),H=v(h),U=d({...b()}),W=u({...A(h)}),X=d({...C()}),Z=l({...f({setting:L,styles:B})}),ee=d({...I(B)}),et=l({...j({setting:L,styles:B})}),es=u({...E()}),ei=d({...T()}),er=l({...P({setting:L,styles:B})}),ea=d({...k()}),eo=u({...K({setting:L})}),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(L?.displayTrigger).replaceAll("'","&#039;")),uid:h.builderProps?.uid,productCreatedAt:'{{product.created_at | date: "%Y-%m-%d" }}',productTags:"{{ product.tags | join: \",\" | replace: '\"', '\\\"' | escape }}",isTextBadge:w}),{displayContent:en}=L??{},ep=o({val:en?.trim(),uid:O?.uid,settingId:_?.displayContent?.id,isLiquid:!0,pageContext:Q});return i`
    {% if product %}
      ${n(ep,Q?.isPreviewing)}
      ${p(L?.displayTrigger,!G,J)}
      <gp-product-badge
        ${{...W}}
        gp-data='${e(ec)}'
        class="${x} {{ className }}"
        style="${M}"
        data-display-content="${Q?.isPreviewing?ep:t(`{{${ep}}}`)}"
      >
        <div class="${R}">
          <div
            ${{...F}}
            class="${Y}"
            style="${z}"
          >
            <style>${H}</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{h as default};
