import{r as l}from"./index-DiwDH9aE.js";import{B as E}from"./BaseService-B6zq4ARl.js";import{E as u,b as S}from"./endpoints-BUXROgJ9.js";import{a as p}from"./multiUserApiClient-CKPzIhIr.js";class f extends E{constructor(){super(u.ADMIN.PERMISSIONS.BASE)}async getGroups(){try{return await p.get(u.ADMIN.PERMISSIONS_GROUPS)}catch(o){throw console.error("[PermissionsService] Error en getGroups:",o),o}}async toggleStatus(o){try{if(!o)throw new Error("ID es requerido para toggleStatus()");const a=S(u.ADMIN.PERMISSIONS_TOGGLE_STATUS,{id:o});return await p.patch(a)}catch(a){throw console.error("[PermissionsService] Error en toggleStatus:",a),a}}}const i=new f,O=()=>{const[m,o]=l.useState(null),[a,s]=l.useState(!1),[g,r]=l.useState(null),c=async(t={})=>{s(!0),r(null);try{const e=await i.getAll(t);return e.success?(o(e),e):(r(e.message),e)}catch(e){throw r(e.message||"Error al cargar permisos"),console.error("Error en fetchPermissions:",e),e}finally{s(!1)}};return{data:m,loading:a,error:g,fetchPermissions:c,getPermission:async t=>{s(!0),r(null);try{const e=await i.getById(t);return e.success?e.data:(r(e.message),null)}catch(e){throw r(e.message||"Error al cargar permiso"),console.error("Error en getPermission:",e),e}finally{s(!1)}},createPermission:async t=>{s(!0),r(null);try{const e=await i.create(t);return console.log(e),e.success?(await c(),e):(r(e.message),e)}catch(e){throw r(e.message||"Error al crear permiso"),console.error("Error en createPermission:",e),e}finally{s(!1)}},updatePermission:async(t,e)=>{s(!0),r(null);try{const n=await i.update(t,e);return n.success?(await c(),n):(r(n.message),n)}catch(n){throw r(n.message||"Error al actualizar permiso"),console.error("Error en updatePermission:",n),n}finally{s(!1)}},deletePermission:async t=>{s(!0),r(null);try{const e=await i.delete(t);return e.success?(await c(),e):(r(e.message),e)}catch(e){throw r(e.message||"Error al eliminar permiso"),console.error("Error en deletePermission:",e),e}finally{s(!1)}},clearError:()=>{r(null)},reset:()=>{setPermissions(null),s(!1),r(null)}}};export{O as u};
