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