import{l as y,bZ as O,r as l,d as I,n as m,t as x}from"./index-7T7TTikv.js";import{p as z,b as F,c as M}from"./organizationsService-DIFVjoLn.js";const A=async r=>{try{return await y.get(`/organizations/${r}/report`)}catch(a){throw a instanceof O&&a.response,a}},K=async r=>y.get(`/organizations/${r}/employees/count`),T=async r=>y.get(`/organizations/${r}/departments/count`),k=async r=>y.get(`/organizations/${r}/units/count`),Q=r=>{var w,f;const{user:a}=I(),[n,c]=l.useState(!1),e=r||((f=(w=a==null?void 0:a.employee)==null?void 0:w[0])==null?void 0:f.organizationId),{data:g,isLoading:D,isError:q,error:d,refetch:u}=m({queryKey:["organizationReport",e],queryFn:async()=>{if(!e)throw new Error("Organization ID is required");try{return(await A(e)).data}catch(t){throw c(!0),t}},enabled:!!e&&!n,staleTime:300*1e3}),{data:i,isLoading:o}=m({queryKey:["organizationEmployees",e],queryFn:async()=>{if(!e)throw new Error("Organization ID is required");const{data:t}=await K(e);return t.total},enabled:!!e&&n,staleTime:300*1e3}),{data:s,isLoading:p}=m({queryKey:["organizationDepartments",e],queryFn:async()=>{if(!e)throw new Error("Organization ID is required");const{data:t}=await T(e);return t.total},enabled:!!e&&n,staleTime:300*1e3}),{data:h,isLoading:E}=m({queryKey:["documentRequirement"],queryFn:async()=>{const t=await M();return{count:t.data.count,items:t.data.items}},staleTime:300*1e3}),{data:L,isLoading:R}=m({queryKey:["organizationUnits",e],queryFn:async()=>{if(!e)throw new Error("Organization ID is required");const{data:t}=await k(e);return t.total},enabled:!!e&&n,staleTime:300*1e3});return{report:n?n?{employeesCount:i||0,positionsCount:0,unitsCount:L||0,totalDocuments:0,recentActivities:[]}:void 0:g,isLoading:n?o||p||R:D,isError:q&&n,error:d,refetch:u,isDocumentRequirementLoading:E,documentRequirementData:h,createDocumentRequirements:async t=>{try{return(await z(t)).data}catch{x.error("Error in Creating Document Requirements")}}}},Z=()=>{const[r,a]=l.useState(!1),[n,c]=l.useState(null),[e,g]=l.useState(null);return{mutate:async({id:d,data:u})=>{var i,o;a(!0),c(null);try{const s=await F(d,u);return g(s.data),s}catch(s){const p=((o=(i=s.response)==null?void 0:i.data)==null?void 0:o.message)||"An unexpected error occurred";throw c(p),s}finally{a(!1)}},isLoading:r,error:n,data:e,mutateDocumetary:async d=>{var u,i;a(!0),c(null);try{const o=await z(d);return g(o.data),o}catch(o){const s=((i=(u=o.response)==null?void 0:u.data)==null?void 0:i.message)||"An unexpected error occurred";throw c(s),o}finally{a(!1)}}}};export{Z as a,Q as u};
