import{useMemo as r}from"react";import{useCurrentVariant as e,useProduct as l,useProductStore as i,useQuantity as n,convertDecimalToNumber as t,shopifyPriceRounding as o,useFormatMoney as s}from"@gem-sdk/core";import{calculateRecurringPrice as u,formatInterval as c}from"../helpers/product-price-breakdown/getPrice.js";let g=()=>{let g=e(),a=l(),f=i(r=>r.selectedSellingPlan),{quantity:p}=n(),P=g?.sellingPlanGroups,m=t(g?.price)??0,y=r(()=>{if(!f)return null;let r=g?.sellingPlanGroups??a?.sellingPlanGroups??[];for(let e of r)if(e?.sellingPlans){for(let r of e.sellingPlans)if(r?.baseID===f)return r}return null},[JSON.stringify(P),f]),b=JSON.stringify(y?.pricingPolicies),d=JSON.stringify(y?.billingPolicy),S=y?.baseID,G=r(()=>{if(!S||!g||m<=0||!y)return 0;let r=u({variantPrice:m,pricingPolicies:y.pricingPolicies}),e=r*(p||1);return parseFloat(o(e,2))},[b,m,p,S]),J=r(()=>{if(!S||!y)return null;let r=y.deliveryPolicy;return c({deliveryPolicy:r})},[d,S]),N=s(Math.max(G,0),!1),O=r(()=>S&&J?`${N} ${J}`:null,[S,J,N]);return O};export{g as useRecurringSubtotal};
