import{r as o,A as f,a2 as x,u as C,x as E,j as r,N as S,B as l,l as p,T as n,a3 as y,z as I,q as g,f as u,a4 as v,_ as A,a5 as N,a6 as j}from"./index-cc84e56a.js";import{C as b}from"./Container-56e8d2d4.js";import{D as $}from"./Divider-b784899a.js";import{A as U}from"./Avatar-74796535.js";import"./createContainer-a5dd8c1d.js";const w=`${N}/${j}/Engine?paquete=std.seguridad&clase=Usuarios&metodo=getEmpresasUsuario&data=&parametros=`,B=k=>{const{empresasPertenecientes:a,setEmpresaActual:m,setempresasPertenecientes:d}=o.useContext(f),{user:i}=o.useContext(x),{logout:c}=C();function s(t){localStorage.setItem("empresaStorage",JSON.stringify(t)),m(t),u.get(`${v}${JSON.stringify({empId:t.empId,cuentaTwilioId:t.EmpCuentaTwilioId})}`).then(e=>h("/dashboard/home")).catch(e=>{console.error(e),A.error("Error al seleccionar empresa por defecto")})}const h=E();return i?(a.length===1&&s(a[0]),o.useEffect(()=>{(async()=>{if(localStorage.getItem("empresaStorage")!==null){const e=localStorage.getItem("empresaStorage");s(JSON.parse(e))}else try{const e=await u.get(`${w}${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(y,{direction:"row",justifyContent:"center",alignItems:"center",divider:r($,{orientation:"vertical",flexItem:!0}),spacing:3,children:a.length===0?r(n,{children:"No perteneces a ninguna empresa"}):a.map((t,e)=>p(l,{display:"flex",justifyContent:"center",flexDirection:"column",alignItems:"center",gap:2,onClick:()=>{s(t)},sx:{cursor:"pointer"},children:[r(U,{sx:{width:"200px",height:"200px",fontSize:"2rem",bgcolor:t.empColor,textAlign:"center"},children:t.empNombre}),r(n,{children:t.empNombre})]},e))}),r(I,{onClick:()=>g(c),variant:"contained",children:"Salir"})]})})):r(S,{to:"/login"})};export{B as default};
