import{m as C,u as h,k as F,o as u,n as s}from"./index-7T7TTikv.js";import{r as K,d as f,u as E,c as p,a as b,b as L,e as Q,f as k,g as w}from"./unitService-DTtkt-Pb.js";const O=()=>{const n=C(),{t:l}=h(),{handleError:r}=F(l),d=(e,t)=>s({queryKey:["unitList",e],queryFn:()=>b(e,t??{}),enabled:!!e,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:!1}),m=e=>s({queryKey:["unit",e],queryFn:()=>L(e),enabled:!!e}),g=e=>s({queryKey:["unitHierarchy",e],queryFn:()=>Q(e),enabled:!!e}),q=e=>s({queryKey:["unitEmployees",e],queryFn:()=>k(e),enabled:!!e}),U=e=>s({queryKey:["unitChildren",e],queryFn:()=>w(e),enabled:!!e,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:!1}),i=u({mutationFn:({payload:e,successCallback:t})=>p(e),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:["unitList"]}),t.successCallback()},onError:e=>{r(e)}}),c=u({mutationFn:({id:e,payload:t,successCallback:a})=>E(e,t),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:["unitList"]}),t.successCallback()},onError:e=>{r(e)}}),o=u({mutationFn:e=>f(e),onSuccess:()=>{n.invalidateQueries({queryKey:["unitList"]})},onError:e=>{r(e)}}),y=u({mutationFn:({payload:e})=>K(e),onSuccess:(e,t)=>{var a;n.invalidateQueries({queryKey:["unitList"]}),n.invalidateQueries({queryKey:["unitChildren"]}),(a=t.successCallback)==null||a.call(t)},onError:e=>{r(e)}});return{getList:d,getById:m,getHierarchy:g,getEmployees:q,getChildren:U,createUnit:i.mutateAsync,isCreating:i.isPending,updateUnit:c.mutateAsync,isUpdating:c.isPending,removeUnit:o.mutateAsync,isDeleting:o.isPending,relateUnit:y.mutateAsync,isRelating:y.isPending}};export{O as u};
