import{r as o,A as f,a2 as x,u as C,x as E,j as r,N as I,B as l,l as p,T as n,a3 as v,z as S,q as u,f as g,a4 as y,K as A,a5 as j,a6 as N}from"./index-91e9700c.js";import{C as b}from"./Container-3bb74340.js";import{D as U}from"./Divider-d0fc16ba.js";import{A as w}from"./Avatar-08f92b60.js";import"./createContainer-1f2487c8.js";const $=`${j}/${N}/Engine?paquete=std.seguridad&clase=Usuarios&metodo=getEmpresasUsuario&data=&parametros=`,P=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),g.post(`${y}`,{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 g.post(`${$}`,{usrId:i.id});e.data.success||u(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(v,{direction:"row",justifyContent:"center",alignItems:"center",divider:r(U,{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(w,{sx:{width:"200px",height:"200px",fontSize:"2rem",bgcolor:t.empColor,textAlign:"center"},children:t.empNombre}),r(n,{children:t.empNombre})]},e))}),r(S,{onClick:()=>u(c),variant:"contained",children:"Salir"})]})})):r(I,{to:"/login"})};export{P as default};
