import{template as e,isLocalEnv as i,baseAssetURL as a}from"@gem-sdk/core";import{getDynamicSourceLocales as s,getSettingPreloadData as r}from"../../../helpers.js";import p from"../../../text/components/Text.liquid.js";import{createStyle as t,createClass as n,LiquidIf as c,Liquid as d,If as l}from"@gem-sdk/system";import{getWrapperTextClass as o,getContainerClass as u,getProductTagClass as g}from"./common/classes.js";import{getRootClass as m,getWrapperTextStyle as f,getContainerStyle as v}from"./common/styles.js";let ProductTag=({setting:$,styles:y,builderProps:x,advanced:S,pageContext:P})=>{let{customContent:_,translate:V}=$??{},h=$?.moneyWithCurrentFormat?"money_with_currency":"money",j=s({val:_?.prefix,uid:x?.uid,settingId:"customContent_prefix",isLiquid:!0,pageContext:P,translate:V}),M=s({val:_?.suffix,uid:x?.uid,settingId:"customContent_suffix",isLiquid:!0,pageContext:P,translate:V}),q=t(m(y)),w=t(f(y)),C=t(v(y)),E=n(o(y)),F=n(u()),N=n(g(S)),O=_?.unit==="percentage",T=()=>{let e=i?"{{ 'gp-product-tag-v7-5.js' | asset_url }}":`${a}/assets-v2/gp-product-tag-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;return`<script ${r('class="gps-link" delay',"src")}="${e}" defer="defer"></script>`};return e`
    {% liquid
      assign price = variant.price | times: 1.0
      assign salePrice = variant.compare_at_price | times: 1.0
      assign priceSave = salePrice | minus: price
      assign prefixVal = ${P?.isPreviewing?JSON.stringify(j):j}
      assign suffixVal = ${P?.isPreviewing?JSON.stringify(M):M}
    %}
    ${c("salePrice == null or price == null",d(`{% assign pricePercentage = prefixVal ${l(O,"| append: ' 0% '",`| ${h} | append: ' '`)} | append: suffixVal %}`),`${l(O,`{% assign salePercent = priceSave | divided_by: salePrice | times: 100  | round %}
          {% assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal %}`,c("priceSave > 0",`{% assign priceSaveMoney = priceSave | ${h} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`,`{% assign priceSaveMoney = 0 | ${h} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`))}`)}

    <gp-product-tag
      class="${N}"
      style="${q}"
      data-id="${x?.uid}"
      data-disabled="${c(`${l(O,"salePercent","priceSave")} > 0`,"false","true")}"
      gp-data='{"setting":${JSON.stringify($).replaceAll("'","&#039;")}, "id": "${x?.uid}", "locale": "{{shop.locale}}", "currency": "{{shop.currency}}", "moneyFormat": "{{ ${$?.moneyWithCurrentFormat?"shop.money_with_currency_format":"shop.money_format"} | replace: '"', '\\"' | escape }}"}'
      price-save="{{priceSave}}"
    >
      <div class="${F}" style="${C}">
        <div class="${E}" style="${w}">
          ${p({styles:y,id:`p-tag-${x?.uid}`,setting:{...$,translate:"",text:"{{ pricePercentage }}",excludeFlex:!0}})}
        </div>
      </div>

  </gp-product-tag>
  ${T()}
  `};export{ProductTag as default};
