import{r as p}from"./index-DiwDH9aE.js";import{B as f}from"./BaseService-B6zq4ARl.js";import{E as l,b as m}from"./endpoints-BUXROgJ9.js";import{a as E}from"./multiUserApiClient-CKPzIhIr.js";class S extends f{constructor(){super(l.ADMIN.ROLES.BASE)}async toggleStatus(t){try{if(!t)throw new Error("ID es requerido para toggleStatus()");const a=m(l.ADMIN.ROLES.TOGGLE_STATUS,{id:t});return await E.patch(a)}catch(a){throw console.error("[PermissionsService] Error en toggleStatus:",a),a}}async assignPermissions(t,a){try{if(!t)throw new Error("ID es requerido para assignPermissions()");const s=m(l.ADMIN.ROLES.ASSIGN_PERMISSIONS,{id:t});return await E.post(s,a)}catch(s){throw console.error("[PermissionsService] Error en assignPermissions:",s),s}}async removePermissions(t,a){try{if(!t)throw new Error("ID es requerido para removePermissions()");const s=m(l.ADMIN.ROLES.REMOVE_PERMISSIONS,{id:t});return await E.post(s,a)}catch(s){throw console.error("[PermissionsService] Error en removePermissions:",s),s}}async syncPermissions(t,a){try{if(!t)throw new Error("ID es requerido para syncPermissions()");const s=m(l.ADMIN.ROLES.SYNC_PERMISSIONS,{id:t});return await E.post(s,a)}catch(s){throw console.error("[PermissionsService] Error en syncPermissions:",s),s}}}const c=new S,q=()=>{const[y,t]=p.useState(null),[a,s]=p.useState(!1),[i,o]=p.useState(null),u="el Rol",g="los Roles";return{data:y,loading:a,error:i,fetchRoles:async(n={})=>{s(!0),o(null);try{const e=await c.getAll(n);return e.success?(t(e),e):(o(e.message),e)}catch(e){throw o(e.message||`Error al cargar ${g}`),console.error("Error en fetch:",e),e}finally{s(!1)}},getRole:async(n,e={})=>{s(!0),o(null);try{const r=await c.getById(n,e);return r.success?r.data:(o(r.message),null)}catch(r){throw o(r.message||`Error al cargar ${u}`),console.error("Error en get:",r),r}finally{s(!1)}},createRole:async n=>{s(!0),o(null);try{const e=await c.create(n);return console.log(e),e.success||o(e.message),e}catch(e){throw o(e.message||`Error al crear ${u}`),console.error("Error en create:",e),e}finally{s(!1)}},updateRole:async(n,e)=>{s(!0),o(null);try{const r=await c.update(n,e);return r.success||o(r.message),r}catch(r){throw o(r.message||`Error al actualizar ${u}`),console.error("Error en update:",r),r}finally{s(!1)}},deleteRole:async n=>{s(!0),o(null);try{const e=await c.delete(n);return e.success||o(e.message),e}catch(e){throw o(e.message||`Error al eliminar ${u}`),console.error("Error en delete:",e),e}finally{s(!1)}},assignPermissions:async(n,e)=>{s(!0),o(null);try{const r=await c.assignPermissions(n,e);return r.success||o(r.message||"Error al asignar permisos"),r}catch(r){throw console.error("[PermissionsService] Error en assignPermissions:",r),r}finally{s(!1)}},removePermissions:async(n,e)=>{s(!0),o(null);try{const r=await c.removePermissions(n,e);return r.success||o(r.message||"Error al remover permisos"),r}catch(r){throw console.error("[PermissionsService] Error en removePermissions:",r),r}finally{s(!1)}},syncPermissions:async(n,e)=>{s(!0),o(null);try{const r=await c.syncPermissions(n,e);return r.success||o(r.message||"Error al sincronizar permisos"),r}catch(r){throw console.error("[PermissionsService] Error en syncPermissions:",r),r}finally{s(!1)}},clearError:()=>{o(null)},reset:()=>{t(null),s(!1),o(null)}}};export{q as u};
