import{r as l}from"./sikshya-admin-sikshya-react-E_TY_un4.js";import{g as f,S as d}from"./sikshya-admin.js";let r=null,o=null;async function y(){return r||o||(o=f().get(d.admin.addons).then(e=>(r=e,o=null,e)).catch(e=>{throw o=null,e}),o)}function h(){r=null,o=null}function m(){const[e,n]=l.useState(r),[i,c]=l.useState(!r),[s,a]=l.useState(null),u=l.useCallback(async()=>{c(!0),a(null);try{h();const t=await y();n(t)}catch(t){a(t)}finally{c(!1)}},[]);return l.useEffect(()=>{r||(async()=>{c(!0),a(null);try{const t=await y();n(t)}catch(t){a(t)}finally{c(!1)}})()},[]),{data:e,loading:i,error:s,refetch:u}}function w(e){const{data:n,loading:i,error:c,refetch:s}=m(),a=l.useMemo(()=>{var b;return((b=n==null?void 0:n.addons)==null?void 0:b.find(g=>g.id===e))??null},[n,e]),u=l.useCallback(async()=>{await f().post(d.admin.addonsEnable(e),{}),h(),await s()},[e,s]),t=l.useCallback(async()=>{await f().post(d.admin.addonsDisable(e),{}),h(),await s()},[e,s]);return{enabled:a?!!a.enabled:n?!1:null,licenseOk:a?!!a.licenseOk:n?!1:null,loading:i,error:c,enable:u,disable:t,refetch:s}}export{w as u};
