import{convertDecimalToNumber as t,formatMoney as o}from"@gem-sdk/core";import{DiscountType as e}from"../components/constants/product-bundle.js";let n=t=>({discountPercentAmount:0,discountAmount:o("0",t)}),r=r=>{let{currentVariant:s,bundleItem:a,options:d}=r;if(!d?.useProductCompareAtPrice&&a?.discountType===e.NoDiscount||!a||!s?.price)return n(d?.moneyFormat||"${{amount}}");let p=t(s?.price)??0,y=t(s?.salePrice)??p,P=Number(a?.quantity),l=m(p,a),A=i(l,P*p),F=p*P-l,g=y*P;return y<=p&&l<=0?n(d?.moneyFormat||"${{amount}}"):{discountPercentAmount:d?.useProductCompareAtPrice?u(F,g):A,discountAmount:d?.useProductCompareAtPrice?c(F,g,d?.moneyFormat):o(l.toString(),d?.moneyFormat)}},u=(t,o)=>Math.round((o-t)/o*100),c=(t,e,n)=>o((e-t).toString(),n),m=(t,o)=>{let n=parseInt(o?.discountValue);return o?.discountType===e.Percentage?t*o.quantity*n/100:o?.discountType===e.FixedAmount?n:0},i=(t,o)=>Math.round(t/o*100);export{r as applyBundleDiscountAmount};
