import{r as o,A as f,O as x,u as C,k as S,j as r,N as y,B as l,f as p,T as n,S as E,m as v,Q as A,_ as I,U as N,V as j}from"./index-ca24af84.js";import{l as g,a as m}from"./api-2d3a9910.js";import{C as b}from"./Container-30ca10cd.js";import{D as U}from"./Divider-21330109.js";import{A as $}from"./Avatar-aaf77463.js";import"./createContainer-b0287129.js";import"./dividerClasses-fa4eeeba.js";const k=`${N}/${j}/Engine?paquete=std.seguridad&clase=Usuarios&metodo=getEmpresasUsuario&data=&parametros=`,T=O=>{const{empresasPertenecientes:s,setEmpresaActual:u,setempresasPertenecientes:d}=o.useContext(f),{user:i}=o.useContext(x),{logout:c}=C();function a(t){localStorage.setItem("empresaStorage",JSON.stringify(t)),u(t),m.get(`${A}${JSON.stringify({empId:t.empId})}`).then(e=>h("/dashboard/home")).catch(e=>{console.error(e),I.error("Error al seleccionar empresa por defecto")})}const h=S();return i?(s.length===1&&a(s[0]),o.useEffect(()=>{(async()=>{if(localStorage.getItem("empresaStorage")!==null){const e=localStorage.getItem("empresaStorage");a(JSON.parse(e))}else try{const e=await m.get(`${k}${JSON.stringify({usrId:i.id})}`);e.data.success||g(c),e.data.success&&d(e.data.data)}catch{}})()},[]),r(l,{sx:{height:"100dvh",backgroundColor:"#F4F5FA"},children:p(b,{sx:{height:"100%",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",gap:"4rem"},children:[r(n,{variant:"h4",fontWeight:700,children:"¿A que bandeja quieres ingresar?"}),r(E,{direction:"row",justifyContent:"center",alignItems:"center",divider:r(U,{orientation:"vertical",flexItem:!0}),spacing:3,children:s.length===0?r(n,{children:"No perteneces a ninguna empresa"}):s.map((t,e)=>p(l,{display:"flex",justifyContent:"center",flexDirection:"column",alignItems:"center",gap:2,onClick:()=>{a(t)},sx:{cursor:"pointer"},children:[r($,{sx:{width:"200px",height:"200px",fontSize:"2rem",bgcolor:t.empColor,textAlign:"center"},children:t.empNombre}),r(n,{children:t.empNombre})]},e))}),r(v,{onClick:()=>g(c),variant:"contained",children:"Salir"})]})})):r(y,{to:"/login"})};export{T as default};
