import{template as e,baseAssetURL as i,isLocalEnv as s}from"@gem-sdk/core";import{getDynamicSourceLocales as a,createSettingId as r,getSettingPreloadData as t}from"../../../helpers.js";import p from"../../../text/components/Text.liquid.js";import{createStyle as n,createClass as c,LiquidIf as o,Liquid as d,If as l}from"@gem-sdk/system";import{getWrapperTextClass as u,getContainerClass as g,getProductTagClass as f}from"./common/classes.js";import{getRootClass as m,getWrapperTextStyle as v,getContainerStyle as x}from"./common/styles.js";import{ProductTag as $}from"../../settings/product-discount-tag/configs/translate.js";let y=({setting:y,styles:S,builderProps:P,advanced:V,pageContext:_})=>{let{customContent:h}=y??{},C=y?.moneyWithCurrentFormat?"money_with_currency":"money",j=$?.customContent?.id?a({val:h?.prefix,uid:P?.uid,settingId:r({id:$.customContent.id,suffix:"prefix"}),isLiquid:!0,pageContext:_??{}}):h?.prefix,F=$?.customContent?.id?a({val:h?.suffix,uid:P?.uid,settingId:r({id:$.customContent.id,suffix:"suffix"}),isLiquid:!0,pageContext:_??{}}):h?.suffix,M=n(m(S)),q=n(v(S)),w=n(x(S)),E=c(u(S)),N=c(g()),O=c(f(V)),T=h?.unit==="percentage";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 = ${_?.isPreviewing?JSON.stringify(j):j}
      assign suffixVal = ${_?.isPreviewing?JSON.stringify(F):F}
    %}
    ${o("salePrice == null or price == null",d(`{% assign pricePercentage = prefixVal ${l(T,"| append: ' 0% '",`| ${C} | append: ' '`)} | append: suffixVal %}`),`${l(T,`{% assign salePercent = priceSave | divided_by: salePrice | times: 100  | round %}
          {% assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal %}`,o("priceSave > 0",`{% assign priceSaveMoney = priceSave | ${C} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`,`{% assign priceSaveMoney = 0 | ${C} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`))}`)}

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

  </gp-product-tag>
  ${(()=>{let e=s?"{{ 'gp-product-tag-v7-5.js' | asset_url }}":`${i}/assets-v2/gp-product-tag-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;return`<script ${t('class="gps-link" delay',"src")}="${e}" defer="defer"></script>`})()}
  `};export{y as default};
