import{l as s,w as i,m as p,u as B,k as C,n as U,o as d,t as r,aT as v}from"./index-7T7TTikv.js";const w=async t=>s.get("/organizations/org-admins",{headers:i(),params:t}),F=async(t,e)=>s.get(`/organizations/org-admins/${t}`,{headers:i(),params:e}),q=async(t,e)=>s.get(`/units/unit-admins/${t}`,{headers:i(),params:e}),E=async(t,e)=>s.get(`/organizations/all-admins/${t}`,{headers:i(),params:e}),b=async t=>s.post("/organizations/org-admin",t,{headers:i()}),k=async t=>s.post("/units/unit-admin",t,{headers:i()}),O=async(t,e)=>s.put(`/organizations/org-admin/${t}`,e,{headers:i()}),T=t=>{const e=p(),{t:u}=B(),{handleError:o}=C(u),{data:m,isLoading:l,isError:y,refetch:g}=U({queryKey:["organizationAdmins",t],queryFn:async()=>{const{data:n}=await w(t);return{count:n,items:n}},staleTime:300*1e3,retry:!1,enabled:!1}),{mutate:A,isPending:h}=d({mutationFn:async({payload:n,successCallback:a})=>b(n),onSuccess:(n,a)=>{r.success("Admin assigned successfully"),e.invalidateQueries({queryKey:["organizationAdmins"]}),a.successCallback()},onError:n=>{o(n)}}),{mutate:z,isPending:Q}=d({mutationFn:async({payload:n,successCallback:a})=>k(n),onSuccess:(n,a)=>{r.success("Admin assigned successfully"),e.invalidateQueries({queryKey:["organizationAdmins"]}),a.successCallback()},onError:n=>{o(n)}}),{mutate:f,isPending:I}=d({mutationFn:({id:n,data:a})=>O(n,a),onSuccess:()=>{r.success("Admin updated successfully"),e.invalidateQueries({queryKey:["organizationAdmins"]})},onError:n=>{o(n)}});return{adminsResponse:m,createAdmin:A,createUnitAdmin:z,updateAdmin:f,getAdminById:async n=>{try{return await F(n)}catch{r.error("Failed to fetch admin details");return}},getUnitAdminById:async n=>{try{return await q(n)}catch{r.error("Failed to fetch unit admin details");return}},resendInvitation:async({email:n,phoneNumber:a})=>{try{await v({email:n,phoneNumber:a})}catch(c){throw c}},getAllAdminById:async(n,a)=>{try{return await E(n,a)}catch{r.error("Failed to fetch all admin details");return}},isCreating:h,isUpdating:I,isLoading:l,isError:y,refetch:g}};export{T as u};
