"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gem-sdk/core"),i=require("../../../helpers.js"),t=require("../../../text/components/Text.liquid.js"),a=require("@gem-sdk/system"),s=require("./common/classes.js"),r=require("./common/styles.js"),n=require("../../settings/product-discount-tag/configs/translate.js");exports.default=({setting:c,styles:p,builderProps:d,advanced:l,pageContext:u})=>{let{customContent:o}=c??{},g=c?.moneyWithCurrentFormat?"money_with_currency":"money",f=n.ProductTag?.customContent?.id?i.getDynamicSourceLocales({val:o?.prefix,uid:d?.uid,settingId:i.createSettingId({id:n.ProductTag.customContent.id,suffix:"prefix"}),isLiquid:!0,pageContext:u??{}}):o?.prefix,y=n.ProductTag?.customContent?.id?i.getDynamicSourceLocales({val:o?.suffix,uid:d?.uid,settingId:i.createSettingId({id:n.ProductTag.customContent.id,suffix:"suffix"}),isLiquid:!0,pageContext:u??{}}):o?.suffix,m=a.createStyle(r.getRootClass(p)),v=a.createStyle(r.getWrapperTextStyle(p)),x=a.createStyle(r.getContainerStyle(p)),S=a.createClass(s.getWrapperTextClass(p)),$=a.createClass(s.getContainerClass()),P=a.createClass(s.getProductTagClass(l)),C=o?.unit==="percentage";return e.template`
    {% liquid
      assign price = variant.price | times: 1.0
      assign salePrice = variant.compare_at_price | times: 1.0
      assign priceSave = salePrice | minus: price
      assign prefixVal = ${u?.isPreviewing?JSON.stringify(f):f}
      assign suffixVal = ${u?.isPreviewing?JSON.stringify(y):y}
    %}
    ${a.LiquidIf("salePrice == null or price == null",a.Liquid(`{% assign pricePercentage = prefixVal ${a.If(C,"| append: ' 0% '",`| ${g} | append: ' '`)} | append: suffixVal %}`),`${a.If(C,`{% assign salePercent = priceSave | divided_by: salePrice | times: 100  | round %}
          {% assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal %}`,a.LiquidIf("priceSave > 0",`{% assign priceSaveMoney = priceSave | ${g} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`,`{% assign priceSaveMoney = 0 | ${g} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`))}`)}

    <gp-product-tag
      class="${P}"
      style="${m}"
      data-id="${d?.uid}"
      data-disabled="${a.LiquidIf(`${a.If(C,"salePercent","priceSave")} > 0`,"false","true")}"
      gp-data='{"setting":${JSON.stringify(c).replaceAll("'","&#039;")}, "id": "${d?.uid}", "locale": "{{shop.locale}}", "currency": "{{shop.currency}}", "moneyFormat": "{{ ${c?.moneyWithCurrentFormat?"shop.money_with_currency_format":"shop.money_format"} | replace: '"', '\\"' | escape }}"}'
      price-save="{{priceSave}}"
    >
      <div class="${$}" style="${x}">
        <div class="${S}" style="${v}">
          ${t.default({styles:p,id:`p-tag-${d?.uid}`,setting:{...c,text:"{{ pricePercentage }}",excludeFlex:!0,isForceValue:!0}})}
        </div>
      </div>

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