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 useRecurringSubtotal=()=>{let g=e(),a=l(),f=i(r=>r.selectedSellingPlan),{quantity:p}=n(),P=g?.sellingPlanGroups,m=t(g?.price)??0,b=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]),y=JSON.stringify(b?.pricingPolicies),S=JSON.stringify(b?.billingPolicy),d=b?.baseID,G=r(()=>{if(!d||!g||m<=0||!b)return 0;let r=u({variantPrice:m,pricingPolicies:b.pricingPolicies}),e=r*(p||1);return parseFloat(o(e,2))},[y,m,p,d]),J=r(()=>{if(!d||!b)return null;let r=b.deliveryPolicy;return c({deliveryPolicy:r})},[S,d]),N=s(Math.max(G,0),!1),O=r(()=>d&&J?`${N} ${J}`:null,[d,J,N]);return O};export{useRecurringSubtotal};
