"use strict";var core=require("@gem-sdk/core"),productBundle=require("../components/constants/product-bundle.js");const noDiscount=e=>({discountPercentAmount:0,discountAmount:core.formatMoney("0",e)}),applyBundleDiscountAmount=e=>{let{currentVariant:t,bundleItem:n,options:o}=e;if(!o?.useProductCompareAtPrice&&n?.discountType===productBundle.DiscountType.NoDiscount||!n||!t?.price)return noDiscount(o?.moneyFormat||"${{amount}}");let u=Number(t?.price),c=Number(t?.salePrice)||u,r=Number(n?.quantity),i=calculateBundleFixedDiscount(u,n),a=discountPercentAmount(i,r*u),d=u*r-i,s=c*r;return c<=u&&i<=0?noDiscount(o?.moneyFormat||"${{amount}}"):{discountPercentAmount:o?.useProductCompareAtPrice?calculateDiffPercentPrice(d,s):a,discountAmount:o?.useProductCompareAtPrice?calculateDiffFixedPrice(d,s,o?.moneyFormat):core.formatMoney(i.toString(),o?.moneyFormat)}},calculateDiffPercentPrice=(e,t)=>{let n=(t-e)/t*100;return Math.round(n)},calculateDiffFixedPrice=(e,t,n)=>core.formatMoney((t-e).toString(),n),calculateBundleFixedDiscount=(e,t)=>{let n=parseInt(t?.discountValue);return t?.discountType===productBundle.DiscountType.Percentage?e*t.quantity*n/100:t?.discountType===productBundle.DiscountType.FixedAmount?n:0},discountPercentAmount=(e,t)=>Math.round(e/t*100);exports.applyBundleDiscountAmount=applyBundleDiscountAmount;
