import{m as k,f as B,u as j,k as x,n as u,o as s,t as o}from"./index-7T7TTikv.js";import{f as H,u as I,h as N,i as W,j as G,k as d,l as g}from"./organizationsService-DIFVjoLn.js";const X=(c,i)=>{const n=k(),e=B(),{t:z}=j(),{handleError:r}=x(z),{data:l,isLoading:y,isError:m,refetch:O}=u({queryKey:["organizations",i],queryFn:async()=>{const{data:a}=await g(i);return{count:a.count,items:a.items}},staleTime:300*1e3,retry:!1,enabled:c==="Org"}),{data:E,isLoading:v,isError:f,refetch:q}=u({queryKey:["organizationAdmins",i],queryFn:async()=>{const{data:a}=await g(i);return{count:a.count,items:a.items}},staleTime:300*1e3,retry:!1,enabled:c==="Admin"}),{mutate:A,isPending:F,isError:p,status:J}=s({mutationFn:async a=>{const{data:t}=await H(a);return t},onSuccess:()=>{o.success("Organization created successfully!",{description:"Redirecting..."}),e("/user-management/organizations"),n.invalidateQueries({queryKey:["organizations"]})},onError:a=>{r(a)}}),{mutate:w,isPending:D,isError:S,status:K}=s({mutationFn:async({id:a,payload:t})=>{const{data:b}=await I(a,t);return b},onSuccess:()=>{o.success("Organization created successfully!",{description:"Redirecting..."}),e("/user-management/organizations"),n.invalidateQueries({queryKey:["organizations"]})},onError:a=>{r(a)}}),{mutate:R,isPending:h}=s({mutationFn:async({id:a})=>{const{data:t}=await N(a);return t},onSuccess:()=>{o.success("Organization Activated successfully!",{description:"Redirecting..."}),e("/user-management/organizations"),n.invalidateQueries({queryKey:["organizations"]})},onError:a=>{r(a)}}),{mutate:Q,isPending:C}=s({mutationFn:async({id:a})=>{const{data:t}=await W(a);return t},onSuccess:()=>{o.success("Organization De-Activated successfully!",{description:"Redirecting..."}),e("/user-management/organizations"),n.invalidateQueries({queryKey:["organizations"]})},onError:a=>{r(a)}}),{mutate:M,isPending:P}=s({mutationFn:async({id:a})=>{const{data:t}=await G(a);return t},onSuccess:()=>{o.success("Organization Deleted successfully!",{description:"Redirecting..."}),e("/user-management/organizations"),n.invalidateQueries({queryKey:["organizations"]})},onError:a=>{r(a)}}),{mutate:L,isPending:T}=s({mutationFn:async a=>{const{data:t}=await d(a);return t},onSuccess:a=>a});return{organizationsResponse:l,isLoading:y,isError:m,refetch:O,createOrganization:A,editOrganization:w,isCreating:F,isEditing:D,editStatus:K,organizationCreationError:p,organizationEditError:S,getOrganizationByDetails:L,isFetchingOrganization:T,activateOrganization:R,isOrganizationActivating:h,deactivateOrganization:Q,isOrganizationDeactivating:C,deleteOrganization:M,isOrganizationDeleting:P,organizationsAdminsResponse:E,isLoadingAdmins:v,isErrorAdmins:f,refetchAdmins:q}};function Y(c,i){const n=u({queryKey:["organization-detail",i],queryFn:async()=>{const{data:e}=await d(i);return{items:e}},staleTime:3e5,retry:!1,enabled:!!i});return{organizationsDetailResponse:n.data,isDetailLoading:n.isLoading,isDetailError:n.isError}}export{Y as a,X as u};
