import{r as o,A as f,Q as x,u as C,k as S,j as r,N as E,B as l,f as p,T as n,S as y,m as I,U as v,_ as A,V as N,W as j}from"./index-4e7882bc.js";import{l as g,a as m}from"./api-4cc4473e.js";import{C as b}from"./Container-23973070.js";import{D as U}from"./Divider-5402fd42.js";import{A as $}from"./Avatar-518c4563.js";import"./createContainer-bad89460.js";import"./dividerClasses-9982a278.js";const k=`${N}/${j}/Engine?paquete=std.seguridad&clase=Usuarios&metodo=getEmpresasUsuario&data=&parametros=`,P=w=>{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(`${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=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(y,{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(I,{onClick:()=>g(c),variant:"contained",children:"Salir"})]})})):r(E,{to:"/login"})};export{P as default};
