"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),helpers=require("../../../helpers.js"),Text_liquid=require("../../../text/components/Text.liquid.js"),system=require("@gem-sdk/system"),classes=require("./common/classes.js"),styles=require("./common/styles.js"),translate=require("../../settings/product-discount-tag/configs/translate.js");const ProductTag=({setting:e,styles:s,builderProps:t,advanced:a,pageContext:i})=>{let{customContent:r}=e??{},n=e?.moneyWithCurrentFormat?"money_with_currency":"money",c=translate.ProductTag?.customContent?.id?helpers.getDynamicSourceLocales({val:r?.prefix,uid:t?.uid,settingId:helpers.createSettingId({id:translate.ProductTag.customContent.id,suffix:"prefix"}),isLiquid:!0,pageContext:i??{}}):r?.prefix,p=translate.ProductTag?.customContent?.id?helpers.getDynamicSourceLocales({val:r?.suffix,uid:t?.uid,settingId:helpers.createSettingId({id:translate.ProductTag.customContent.id,suffix:"suffix"}),isLiquid:!0,pageContext:i??{}}):r?.suffix,l=system.createStyle(styles.getRootClass(s)),d=system.createStyle(styles.getWrapperTextStyle(s)),o=system.createStyle(styles.getContainerStyle(s)),u=system.createClass(classes.getWrapperTextClass(s)),g=system.createClass(classes.getContainerClass()),y=system.createClass(classes.getProductTagClass(a)),f=r?.unit==="percentage",m=()=>{let e=core.isLocalEnv?"{{ 'gp-product-tag-v7-5.js' | asset_url }}":`${core.baseAssetURL}/assets-v2/gp-product-tag-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;return`<script ${helpers.getSettingPreloadData('class="gps-link" delay',"src")}="${e}" defer="defer"></script>`};return core.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 = ${i?.isPreviewing?JSON.stringify(c):c}
      assign suffixVal = ${i?.isPreviewing?JSON.stringify(p):p}
    %}
    ${system.LiquidIf("salePrice == null or price == null",system.Liquid(`{% assign pricePercentage = prefixVal ${system.If(f,"| append: ' 0% '",`| ${n} | append: ' '`)} | append: suffixVal %}`),`${system.If(f,`{% assign salePercent = priceSave | divided_by: salePrice | times: 100  | round %}
          {% assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal %}`,system.LiquidIf("priceSave > 0",`{% assign priceSaveMoney = priceSave | ${n} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`,`{% assign priceSaveMoney = 0 | ${n} %}
           {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`))}`)}

    <gp-product-tag
      class="${y}"
      style="${l}"
      data-id="${t?.uid}"
      data-disabled="${system.LiquidIf(`${system.If(f,"salePercent","priceSave")} > 0`,"false","true")}"
      gp-data='{"setting":${JSON.stringify(e).replaceAll("'","&#039;")}, "id": "${t?.uid}", "locale": "{{shop.locale}}", "currency": "{{shop.currency}}", "moneyFormat": "{{ ${e?.moneyWithCurrentFormat?"shop.money_with_currency_format":"shop.money_format"} | replace: '"', '\\"' | escape }}"}'
      price-save="{{priceSave}}"
    >
      <div class="${g}" style="${o}">
        <div class="${u}" style="${d}">
          ${Text_liquid.default({styles:s,id:`p-tag-${t?.uid}`,setting:{...e,text:"{{ pricePercentage }}",excludeFlex:!0,isForceValue:!0}})}
        </div>
      </div>

  </gp-product-tag>
  ${m()}
  `};exports.default=ProductTag;
