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