// src/routes/AppRoutes.tsx
import React, { type JSX } from 'react';
import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom';
import LoginPage from '../pages/LoginPage';
import HomePage from '../pages/HomePage';
import { useAuth } from '../contexts/AuthContext';
import MainLayout from '../layouts/MainLayout';
import { Typography } from '@mui/material';
import SectionProtectedRoute from './SectionProtectedRoute';
// Distribución
import DistribucionIndexPage from '../pages/Distribucion/DistribucionIndexPage';
import GestionarCanillitasPage from '../pages/Distribucion/GestionarCanillitasPage';
import GestionarDistribuidoresPage from '../pages/Distribucion/GestionarDistribuidoresPage';
import GestionarPublicacionesPage from '../pages/Distribucion/GestionarPublicacionesPage';
import GestionarSeccionesPublicacionPage from '../pages/Distribucion/GestionarSeccionesPublicacionPage';
import GestionarPreciosPublicacionPage from '../pages/Distribucion/GestionarPreciosPublicacionPage';
import GestionarRecargosPublicacionPage from '../pages/Distribucion/GestionarRecargosPublicacionPage';
import GestionarPorcentajesPagoPage from '../pages/Distribucion/GestionarPorcentajesPagoPage';
import GestionarPorcMonCanillaPage from '../pages/Distribucion/GestionarPorcMonCanillaPage';
import GestionarOtrosDestinosPage from '../pages/Distribucion/GestionarOtrosDestinosPage';
import GestionarZonasPage from '../pages/Distribucion/GestionarZonasPage';
import GestionarEmpresasPage from '../pages/Distribucion/GestionarEmpresasPage';
import GestionarSalidasOtrosDestinosPage from '../pages/Distribucion/GestionarSalidasOtrosDestinosPage';
import GestionarEntradasSalidasDistPage from '../pages/Distribucion/GestionarEntradasSalidasDistPage';
import GestionarEntradasSalidasCanillaPage from '../pages/Distribucion/GestionarEntradasSalidasCanillaPage';
import GestionarControlDevolucionesPage from '../pages/Distribucion/GestionarControlDevolucionesPage';
import GestionarParadasCanillaPage from '../pages/Distribucion/GestionarParadasCanillaPage';
// Impresión
import ImpresionIndexPage from '../pages/Impresion/ImpresionIndexPage';
import GestionarPlantasPage from '../pages/Impresion/GestionarPlantasPage';
import GestionarTiposBobinaPage from '../pages/Impresion/GestionarTiposBobinaPage';
import GestionarEstadosBobinaPage from '../pages/Impresion/GestionarEstadosBobinaPage';
import GestionarStockBobinasPage from '../pages/Impresion/GestionarStockBobinasPage';
import GestionarTiradasPage from '../pages/Impresion/GestionarTiradasPage';
// Contables
import ContablesIndexPage from '../pages/Contables/ContablesIndexPage';
import GestionarTiposPagoPage from '../pages/Contables/GestionarTiposPagoPage';
import GestionarPagosDistribuidorPage from '../pages/Contables/GestionarPagosDistribuidorPage';
import GestionarNotasCDPage from '../pages/Contables/GestionarNotasCDPage';
import GestionarSaldosPage from '../pages/Contables/GestionarSaldosPage';
// Usuarios
import UsuariosIndexPage from '../pages/Usuarios/UsuariosIndexPage'; // Crear este componente
import GestionarPerfilesPage from '../pages/Usuarios/GestionarPerfilesPage';
import GestionarPermisosPage from '../pages/Usuarios/GestionarPermisosPage';
import AsignarPermisosAPerfilPage from '../pages/Usuarios/AsignarPermisosAPerfilPage';
import GestionarUsuariosPage from '../pages/Usuarios/GestionarUsuariosPage';
// Radios
import RadiosIndexPage from '../pages/Radios/RadiosIndexPage';
import GestionarRitmosPage from '../pages/Radios/GestionarRitmosPage';
import GestionarCancionesPage from '../pages/Radios/GestionarCancionesPage';
import GenerarListasRadioPage from '../pages/Radios/GenerarListasRadioPage';
// Reportes
import ReportesIndexPage from '../pages/Reportes/ReportesIndexPage';
import ReporteExistenciaPapelPage from '../pages/Reportes/ReporteExistenciaPapelPage';
import ReporteMovimientoBobinasPage from '../pages/Reportes/ReporteMovimientoBobinasPage';
import ReporteMovimientoBobinasEstadoPage from '../pages/Reportes/ReporteMovimientoBobinasEstadoPage';
import ReporteListadoDistribucionGeneralPage from '../pages/Reportes/ReporteListadoDistribucionGeneralPage';
import ReporteListadoDistribucionCanillasPage from '../pages/Reportes/ReporteListadoDistribucionCanillasPage';
import ReporteListadoDistribucionCanillasImportePage from '../pages/Reportes/ReporteListadoDistribucionCanillasImportePage';
import ReporteVentaMensualSecretariaPage from '../pages/Reportes/ReporteVentaMensualSecretariaPage';
import ReporteDetalleDistribucionCanillasPage from '../pages/Reportes/ReporteDetalleDistribucionCanillasPage';
import ReporteTiradasPublicacionesSeccionesPage from '../pages/Reportes/ReporteTiradasPublicacionesSeccionesPage';
import ReporteConsumoBobinasSeccionPage from '../pages/Reportes/ReporteConsumoBobinasSeccionPage';
import ReporteConsumoBobinasPublicacionPage from '../pages/Reportes/ReporteConsumoBobinasPublicacionPage';
import ReporteComparativaConsumoBobinasPage from '../pages/Reportes/ReporteComparativaConsumoBobinasPage';
import ReporteCuentasDistribuidoresPage from '../pages/Reportes/ReporteCuentasDistribuidoresPage';
import ReporteListadoDistribucionPage from '../pages/Reportes/ReporteListadoDistribucionPage';
import ReporteControlDevolucionesPage from '../pages/Reportes/ReporteControlDevolucionesPage';
import GestionarNovedadesCanillaPage from '../pages/Distribucion/GestionarNovedadesCanillaPage';
import ReporteNovedadesCanillasPage from '../pages/Reportes/ReporteNovedadesCanillasPage';
import ReporteListadoDistMensualPage from '../pages/Reportes/ReporteListadoDistMensualPage';
// Anonalías
import AlertasPage from '../pages/Anomalia/AlertasPage';
// Auditorias
import GestionarAuditoriaUsuariosPage from '../pages/Usuarios/Auditoria/GestionarAuditoriaUsuariosPage';
import AuditoriaGeneralPage from '../pages/Auditoria/AuditoriaGeneralPage';
// --- ProtectedRoute y PublicRoute SIN CAMBIOS ---
const ProtectedRoute: React.FC<{ children: JSX.Element }> = ({ children }) => {
const { isAuthenticated, isLoading } = useAuth();
// console.log("ProtectedRoute Check:", { path: window.location.pathname, isAuthenticated, isLoading });
if (isLoading) return null;
if (!isAuthenticated) {
// console.log("ProtectedRoute: Not authenticated, redirecting to /login");
return ;
}
// console.log("ProtectedRoute: Authenticated, rendering children");
return children;
};
const PublicRoute: React.FC<{ children: JSX.Element }> = ({ children }) => {
const { isAuthenticated, isLoading } = useAuth();
// console.log("PublicRoute Check:", { path: window.location.pathname, isAuthenticated, isLoading });
if (isLoading) return null;
if (isAuthenticated) {
// console.log("PublicRoute: Authenticated, redirecting to /");
return ;
}
// console.log("PublicRoute: Not authenticated, rendering children");
return children;
};
// --- Fin Protected/Public ---
const MainLayoutWrapper: React.FC = () => (
);
const AppRoutes = () => {
return (
} />
{/* Rutas Protegidas que usan el MainLayout */}
}
>
{/* Rutas hijas que se renderizarán en el Outlet de MainLayoutWrapper */}
} /> {/* Para la ruta exacta "/" */}
{/* Módulo de Anomalías */}
}
>
} />
} />
{/* Módulo de Distribución (anidado) */}
}
>
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
{/* Rutas para Publicaciones y sus detalles */}
}> {/* Contenedor para sub-rutas de publicaciones */}
} /> {/* Lista de publicaciones */}
} />
} />
} />
} />
} />
{/* Módulo Contable (anidado) */}
}
>
} />
} />
} />
} />
} />
{/* Módulo de Impresión (anidado) */}
}
>
} />
} />
} />
} />
} />
} />
{/* Módulo de Reportes */}
}
>
Seleccione un reporte del menú lateral.} /> {/* Placeholder */}
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
{/* Módulo de Radios (anidado) */}
}
>
} />
} />
} />
} />
{/* Módulo de Usuarios (anidado) */}
}
>
} /> {/* Redirigir a la primera subpestaña */}
} />
} />
} />
} />
} />
{/* Módulo de Auditoías (anidado) */}
}
>
} />
} />
{/* Ruta catch-all DENTRO del layout protegido */}
} />
{/* Cierre de la ruta padre "/" */}
);
};
export default AppRoutes;