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