import{l as i,m as r,n as l,o as c,p as o,q as y,t as n}from"./index-Cc987VYg.js";import{t as E}from"./api-utils-SNhvzubv.js";const u={getEntities:async e=>{const{data:t}=await i.get(r.ENTITIES,{params:E(e)});return t.data||t},getEntity:async e=>{const{data:t}=await i.get(r.ENTITY_DETAIL(e));return t},createEntity:async e=>{const{data:t}=await i.post(r.ENTITIES,e);return t},updateEntity:async(e,t)=>{const{data:s}=await i.patch(r.ENTITY_DETAIL(e),t);return s},deleteEntity:async e=>{await i.delete(r.ENTITY_DETAIL(e))},toggleEntityStatus:async(e,t)=>{const{data:s}=await i.patch(r.ENTITY_DETAIL(e),{is_active:t});return s}},a={all:["entities"],lists:()=>[...a.all,"list"],list:e=>[...a.lists(),e],details:()=>[...a.all,"detail"],detail:e=>[...a.details(),e]};function m(e){return l({queryKey:a.list(e),queryFn:()=>u.getEntities(e)})}function T(e,t=!0){return l({queryKey:a.detail(e),queryFn:()=>u.getEntity(e),enabled:t&&!!e})}function q(){const e=c();return o({mutationFn:t=>u.createEntity(t),onSuccess:t=>{e.invalidateQueries({queryKey:a.lists()}),n.success(`Entity "${t.name}" created successfully`)},onError:t=>{const s=y(t);n.error(s,{duration:5e3})}})}function I(){const e=c();return o({mutationFn:({id:t,data:s})=>u.updateEntity(t,s),onSuccess:async t=>{e.setQueryData(a.detail(t.id.toString()),t),await e.invalidateQueries({queryKey:a.lists()}),n.success(`Entity "${t.name}" updated successfully`)},onError:t=>{const s=y(t);n.error(s,{duration:5e3})}})}function f(){const e=c();return o({mutationFn:t=>u.deleteEntity(t),onSuccess:()=>{e.invalidateQueries({queryKey:a.lists()}),n.success("Entity deleted successfully")},onError:t=>{const s=y(t);n.error(s,{duration:5e3})}})}function S(){const e=c();return o({mutationFn:({id:t,isActive:s})=>u.toggleEntityStatus(t,s),onSuccess:t=>{e.invalidateQueries({queryKey:a.lists()}),e.invalidateQueries({queryKey:a.detail(t.id.toString())}),n.success(`Entity ${t.is_active?"activated":"deactivated"} successfully`)},onError:t=>{const s=y(t);n.error(s,{duration:5e3})}})}export{f as a,S as b,q as c,I as d,u as e,T as f,m as u};
