import{l as n,m as u,n as y,o as c,p as l,q as o,t as r}from"./index-Cc987VYg.js";import{t as d}from"./api-utils-SNhvzubv.js";const i={getDepartments:async e=>{const{data:t}=await n.get(u.DEPARTMENTS,{params:d(e)});return t},getDepartment:async e=>{const{data:t}=await n.get(u.DEPARTMENT_DETAIL(e));return t},createDepartment:async e=>{const{data:t}=await n.post(u.DEPARTMENTS,e);return t},updateDepartment:async(e,t)=>{const{data:s}=await n.patch(u.DEPARTMENT_DETAIL(e),t);return s},deleteDepartment:async e=>{await n.delete(u.DEPARTMENT_DETAIL(e))},toggleDepartmentStatus:async(e,t)=>{const{data:s}=await n.patch(u.DEPARTMENT_DETAIL(e),{is_active:t});return s}},a={all:["departments"],lists:()=>[...a.all,"list"],list:e=>[...a.lists(),e],details:()=>[...a.all,"detail"],detail:e=>[...a.details(),e]};function D(e){return y({queryKey:a.list(e),queryFn:()=>i.getDepartments(e)})}function E(e,t=!0){return y({queryKey:a.detail(e),queryFn:()=>i.getDepartment(e),enabled:t&&!!e})}function g(){const e=c();return l({mutationFn:t=>i.createDepartment(t),onSuccess:t=>{e.invalidateQueries({queryKey:a.lists()}),e.invalidateQueries({queryKey:a.all}),r.success(`Department "${t.name}" created successfully`)},onError:t=>{const s=o(t);r.error(s,{duration:5e3})}})}function q(){const e=c();return l({mutationFn:({id:t,data:s})=>i.updateDepartment(t,s),onSuccess:t=>{e.invalidateQueries({queryKey:a.lists()}),e.invalidateQueries({queryKey:a.detail(t.id.toString())}),e.invalidateQueries({queryKey:a.all}),r.success(`Department "${t.name}" updated successfully`)},onError:t=>{const s=o(t);r.error(s,{duration:5e3})}})}function T(){const e=c();return l({mutationFn:t=>i.deleteDepartment(t),onSuccess:()=>{e.invalidateQueries({queryKey:a.lists()}),e.invalidateQueries({queryKey:a.all}),r.success("Department deleted successfully")},onError:t=>{const s=o(t);r.error(s,{duration:5e3})}})}function v(){const e=c();return l({mutationFn:({id:t,isActive:s})=>i.toggleDepartmentStatus(t,s),onSuccess:t=>{e.invalidateQueries({queryKey:a.lists()}),e.invalidateQueries({queryKey:a.detail(t.id.toString())}),e.invalidateQueries({queryKey:a.all}),r.success(`Department ${t.is_active?"activated":"deactivated"} successfully`)},onError:t=>{const s=o(t);r.error(s,{duration:5e3})}})}export{T as a,v as b,g as c,i as d,q as e,E as f,D as u};
