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