import{useMemo as e,useEffect as i}from"react";import{useProductStore as l,useProduct as o}from"@gem-sdk/core";import{SubscriptionEnum as s}from"../../../constants/index.js";import{useProductOfferSubscriptionPresence as r}from"../../product-offer/context/PrdOfferSubscriptionPresenceContext.js";import{useSellingPlanOptions as t}from"./useSellingPlanOptions.js";import{useSubscriptionSellingType as n}from"../../../hooks/useSubscriptionSellingType.js";let p=({setting:p})=>{let S=l(e=>e.setSubscriptionSellingType),{isOneTime:T,subscriptionSellingType:m}=n(),O=t(p),c=o(),u=r(),I=O&&O.length>0,g=u.hasBoth,f=e(()=>c?.requiresSellingPlan,[c?.requiresSellingPlan]),E=e(()=>T?s.ONE_TIME:s.SUBSCRIPTION,[T]);i(()=>{m||(p?.sellingType===s.ONE_TIME?S(s.ONE_TIME):S(p?.sellingType??s.SUBSCRIPTION))},[S,p?.sellingType,m]);let a=!!u.hasSubscriptionBlock&&!u.hasOneTimeBlock&&m===s.ONE_TIME;i(()=>{a&&S(s.SUBSCRIPTION)},[S,a]);let y=p?.sellingType===s.SUBSCRIPTION&&!I,N=p?.sellingType===s.ONE_TIME&&f;return{selectedType:E,shouldShowRadio:!f&&I&&g,isOneTimeHidden:N,requiresSellingPlan:f,isOnetimeOnly:!I&&!f,hasNoSellingPlanOptions:y,setSubscriptionSellingType:S}};export{p as useSubscriptionVisibility};
