import{r as o,A as S,ae as y,u as I,K as v,k as g,af as b,Y as m,ag as A,j as r,N as j,y as c,B as h,o as f,ah as N,ai as k,ab as U,M as w,E as x,aj as $,ak as q}from"./index-e47c07e2.js";import{A as B}from"./Avatar-fd463fc7.js";const D=`${$}/${q}/Engine?paquete=std.seguridad&clase=Usuarios&metodo=getEmpresasUsuario&data=&parametros=`,P=F=>{const{empresasPertenecientes:t,setEmpresaActual:d,setempresasPertenecientes:l}=o.useContext(S),{user:i}=o.useContext(y),{logout:p}=I(),[E,C]=o.useState(!0),u=v(),n=o.useCallback(e=>{localStorage.setItem("empresaStorage",JSON.stringify(e)),d(e),g.post(`${b}`,{empId:e.empId,cuentaTwilioId:e.EmpCuentaTwilioId}).then(()=>{u("/dashboard/home")}).catch(s=>{console.error(s),m.error("Error al seleccionar la empresa por defecto")})},[u,d]);return o.useEffect(()=>{if(!i)return;(async()=>{const s=localStorage.getItem("empresaStorage");if(s)try{const a=JSON.parse(s);n(a);return}catch(a){console.error("Error al parsear empresa de localStorage",a),localStorage.removeItem("empresaStorage")}try{const a=await g.post(`${D}`,{usrId:i.id});a.data.success?l(a.data.data):(l([]),x(p))}catch(a){console.error("Error en la petición para obtener empresas:",a),m.error("Ocurrió un error de red al cargar tus datos.")}finally{C(!1)}})()},[i,p,l,n]),o.useEffect(()=>{A.isUndefined(t)||t.length===1&&n(t[0])},[t,n]),i?E?r(c,{children:"Cargando empresas..."}):r(h,{sx:{height:"100dvh",backgroundColor:"#F4F5FA"},children:f(N,{sx:{height:"100%",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",gap:"4rem"},children:[r(c,{variant:"h4",fontWeight:700,children:"¿A que bandeja quieres ingresar?"}),r(k,{direction:"row",justifyContent:"center",alignItems:"center",divider:r(U,{orientation:"vertical",flexItem:!0}),spacing:3,children:t.length===0?r(c,{children:"No perteneces a ninguna empresa"}):t.map((e,s)=>f(h,{display:"flex",justifyContent:"center",flexDirection:"column",alignItems:"center",gap:2,onClick:()=>{n(e)},sx:{cursor:"pointer"},children:[r(B,{sx:{width:"200px",height:"200px",fontSize:"2rem",bgcolor:e.empColor,textAlign:"center"},children:e.empNombre}),r(c,{children:e.empNombre})]},s))}),r(w,{onClick:()=>x(p),variant:"contained",children:"Salir"})]})}):r(j,{to:"/login"})};export{P as default};
