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