import React, { type ReactNode, useState, useEffect } from 'react'; import { Box, AppBar, Toolbar, Typography, Button, Tabs, Tab, Paper } from '@mui/material'; import { useAuth } from '../contexts/AuthContext'; import ChangePasswordModal from '../components/Modals/Usuarios/ChangePasswordModal'; import { useNavigate, useLocation } from 'react-router-dom'; // Para manejar la navegación y la ruta actual interface MainLayoutProps { children: ReactNode; } const modules = [ { label: 'Inicio', path: '/' }, { label: 'Distribución', path: '/distribucion' }, { label: 'Contables', path: '/contables' }, { label: 'Impresión', path: '/impresion' }, { label: 'Reportes', path: '/reportes' }, { label: 'Radios', path: '/radios' }, { label: 'Usuarios', path: '/usuarios' }, ]; const MainLayout: React.FC = ({ children }) => { const { user, logout, // ... (resto de las props de useAuth) ... isAuthenticated, isPasswordChangeForced, showForcedPasswordChangeModal, setShowForcedPasswordChangeModal, passwordChangeCompleted } = useAuth(); const navigate = useNavigate(); const location = useLocation(); // Para obtener la ruta actual const [selectedTab, setSelectedTab] = useState(false); useEffect(() => { const currentModulePath = modules.findIndex(module => location.pathname === module.path || (module.path !== '/' && location.pathname.startsWith(module.path + '/')) ); if (currentModulePath !== -1) { setSelectedTab(currentModulePath); } else if (location.pathname === '/') { setSelectedTab(0); } else { setSelectedTab(false); } }, [location.pathname]); const handleModalClose = (passwordChangedSuccessfully: boolean) => { if (passwordChangedSuccessfully) { passwordChangeCompleted(); } else { if (isPasswordChangeForced) { logout(); } else { setShowForcedPasswordChangeModal(false); } } }; const handleTabChange = (_event: React.SyntheticEvent, newValue: number) => { setSelectedTab(newValue); navigate(modules[newValue].path); }; // Determinar si el módulo actual es el de Reportes const isReportesModule = location.pathname.startsWith('/reportes'); if (showForcedPasswordChangeModal && isPasswordChangeForced) { // ... (lógica del modal forzado sin cambios) ... return ( ); } return ( {/* ... (Toolbar y Tabs sin cambios) ... */} Sistema de Gestión - El Día {user && Hola, {user.nombreCompleto}} {isAuthenticated && !isPasswordChangeForced && ( )} {modules.map((module) => ( ))} {/* Contenido del Módulo */} {children} Usuario: {user?.username} | Acceso: {user?.esSuperAdmin ? 'Super Admin' : `Perfil ID ${user?.userId}`} | Versión: {/* TODO: Obtener versión */} ); }; export default MainLayout;