"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:o,options:n}=e;if(!n?.useProductCompareAtPrice&&o?.discountType===productBundle.DiscountType.NoDiscount||!o||!t?.price)return noDiscount(n?.moneyFormat||"${{amount}}");let u=core.convertDecimalToNumber(t?.price)??0,c=core.convertDecimalToNumber(t?.salePrice)??u,r=Number(o?.quantity),i=calculateBundleFixedDiscount(u,o),a=discountPercentAmount(i,r*u),d=u*r-i,s=c*r;return c<=u&&i<=0?noDiscount(n?.moneyFormat||"${{amount}}"):{discountPercentAmount:n?.useProductCompareAtPrice?calculateDiffPercentPrice(d,s):a,discountAmount:n?.useProductCompareAtPrice?calculateDiffFixedPrice(d,s,n?.moneyFormat):core.formatMoney(i.toString(),n?.moneyFormat)}},calculateDiffPercentPrice=(e,t)=>{let o=(t-e)/t*100;return Math.round(o)},calculateDiffFixedPrice=(e,t,o)=>core.formatMoney((t-e).toString(),o),calculateBundleFixedDiscount=(e,t)=>{let o=parseInt(t?.discountValue);return t?.discountType===productBundle.DiscountType.Percentage?e*t.quantity*o/100:t?.discountType===productBundle.DiscountType.FixedAmount?o:0},discountPercentAmount=(e,t)=>Math.round(e/t*100);exports.applyBundleDiscountAmount=applyBundleDiscountAmount;
