import{r as g,a as d,t as u}from"./index-DiwDH9aE.js";import{a as o}from"./authService-7ekyJsWC.js";const A=()=>{const[m,n]=g.useState(!1),[f,l]=g.useState("Cargando"),h=d(e=>e.login),i=d(e=>e.logout),a=async(e,t)=>{try{n(!0),l("Iniciando sesión...");const s={admin:o.loginAdmin,teacher:o.loginTeacher,student:o.loginStudent}[e],r=await s(t);return r.success?(h(r),{success:!0,data:r.data,message:r.message}):{success:!1,error:r.message||"Error al iniciar sesión",fieldErrors:r.errors||null}}catch(s){return{success:!1,error:s.message||"Error de conexión"}}finally{n(!1)}},c=async e=>{try{n(!0),l("Cerrando sesión...");const t={admin:o.logoutAdmin,teacher:o.logoutTeacher,student:o.logoutStudent}[e],s=await t();return s?.success?(i(),u.success("Sesión cerrada"),{success:!0,message:s.message}):(i(),u.warning("Sesión cerrada localmente"),{success:!1,message:s.message})}catch(t){console.error("Error en logout:",t),i(),u.error("Error de conexión, sesión cerrada localmente")}finally{n(!1)}};return{loading:m,message:f,loginAdmin:e=>a("admin",e),loginTeacher:e=>a("teacher",e),loginStudent:e=>a("student",e),logoutAdmin:()=>c("admin"),logoutTeacher:()=>c("teacher"),logoutStudent:()=>c("student"),login:a,logout:c}};export{A as u};
