"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js"),useSubscriptionSellingType=require("./useSubscriptionSellingType.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),i=core.useProduct(),o=core.useProductStore(e=>e.selectedSellingPlan),{isOneTime:c}=useSubscriptionSellingType.useSubscriptionSellingType(),{quantity:t}=core.useQuantity(),n=React.useMemo(()=>{if(!o||c)return null;let e=r?.sellingPlanGroups??i?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===o);if(e)return e}return null},[r,i,o,c]),u=core.convertDecimalToNumber(r?.price)??0,s=React.useMemo(()=>!n||u<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:u,pricingPolicies:n.pricingPolicies}),[n,u]),{isPrepaidSubscription:l,prepaidMultiple:a}=React.useMemo(()=>{let e=n?.billingPolicy?.intervalCount,r=n?.deliveryPolicy?.intervalCount;return e&&r?{isPrepaidSubscription:e>r,prepaidMultiple:e/r}:{isPrepaidSubscription:!1,prepaidMultiple:1}},[n]),p=React.useMemo(()=>n&&l?(t||1)*a:t,[l,a,t,n]),P=Math.max(0,parseFloat(core.shopifyPriceRounding(u-s,2))),d=Math.max(0,parseFloat(core.shopifyPriceRounding(P*(p||1),2))),g=core.useFormatMoney(d,!1),y=e*(t||1),f=parseFloat(core.shopifyPriceRounding(y,2)),S=core.useFormatMoney(f,!1),m=core.shopifyPriceRounding(f,2),M=parseFloat(core.shopifyPriceRounding(d-parseFloat(m),2)),b=core.useFormatMoney(M>0?M:0,!1);return{price:u,sellingPlanDiscountPerUnit:s,priceAfterSellingPlanDiscount:P,subTotal:d,subTotalMoneyFormatted:g,offerDiscountTotal:y,discountWithQuantity:f,discountMoneyFormatted:S,totalMoneyFormatted:b}};exports.useProductPriceBreakdown=useProductPriceBreakdown;
