import { lazy, Suspense } from 'react'; import { BrowserRouter as Router, Routes, Route, Navigate, useLocation } from 'react-router-dom'; import { Toaster } from 'sonner'; import { PortalHome } from './features/portal/components/PortalHome.jsx'; import AuthProvider, { useAuthContext } from '@/components/shared/AuthProvider'; import { Building, Zap } from 'lucide-react'; import { LoadingOverlay } from '@/components/shared/LoadingOverlay'; import { useGlobalLoading } from '@/hooks/useGlobalLoading'; // Lazy loading feature components const FleetLogin = lazy(() => import('@/features/fleet').then(m => ({ default: m.FleetLogin }))); const FleetDashboard = lazy(() => import('@/features/fleet').then(m => ({ default: m.FleetDashboard }))); const HRLogin = lazy(() => import('@/features/rh').then(m => ({ default: m.HRLogin }))); const HRDashboard = lazy(() => import('@/features/rh').then(m => ({ default: m.HRDashboard }))); const PontoPage = lazy(() => import('@/features/rh').then(m => ({ default: m.PontoPage }))); const RhRoutes = lazy(() => import('@/features/rh/routes').then(m => ({ default: m.RhRoutes }))); const LoginPage = lazy(() => import('@/features/auth/login/LoginPage').then(m => ({ default: m.LoginPage }))); const FinanceLogin = lazy(() => import('@/features/auth/login-finance/LoginPage').then(m => ({ default: m.LoginPage }))); const CnabLogin = lazy(() => import('@/features/auth/login-cnab/LoginPage').then(m => ({ default: m.LoginPage }))); const FleetV2App = lazy(() => import('@/features/fleet-v2').then(m => ({ default: m.FleetV2App }))); const FinanceiroV2App = lazy(() => import('@/features/financeiro-v2').then(m => ({ default: m.FinanceiroV2App }))); const PrafrotRoutes = lazy(() => import('@/features/prafrot/routes').then(m => ({ default: m.PrafrotRoutes }))); const PrafrotLogin = lazy(() => import('@/features/prafrot/views/LoginView')); const TableDebug = lazy(() => import('@/features/prafrot/views/TableDebug')); const PlaygroundView = lazy(() => import('@/features/dev-tools/views/PlaygroundView')); const WorkspaceLayout = lazy(() => import('@/features/workspace/components/WorkspaceLayout.jsx').then(m => ({ default: m.WorkspaceLayout }))); const LoginView = lazy(() => import('@/features/workspace/views/LoginView.jsx').then(m => ({ default: m.LoginView }))); const WorkspaceGuard = lazy(() => import('@/features/workspace/components/WorkspaceGuard.jsx').then(m => ({ default: m.WorkspaceGuard }))); const CnabRoutes = lazy(() => import('@/features/financeiro-cnab/routes').then(m => ({ default: m.CnabRoutes }))); const GrRoutes = lazy(() => import('@/features/gr/routes').then(m => ({ default: m.GrRoutes }))); const GrLogin = lazy(() => import('@/features/gr/views/LoginView')); const GrResetPassword = lazy(() => import('@/features/gr/views/ResetPasswordView')); const ExternalDriverRegistration = lazy(() => import('@/features/gr/views/ExternalDriverRegistrationView').then(m => ({ default: m.ExternalDriverRegistrationView }))); const DriverPortalView = lazy(() => import('@/features/prafrot/views/DriverPortalView').then(m => ({ default: m.DriverPortalView }))); const AutoLabRoutes = lazy(() => import('@/features/autolab/routes').then(m => ({ default: m.AutoLabRoutes }))); const AutoLabLogin = lazy(() => import('@/features/autolab/views/AutoLabLoginView')); const OestPanRoutes = lazy(() => import('@/features/Oest_Pan/routes').then(m => ({ default: m.OestPanRoutes }))); const OestPanLogin = lazy(() => import('@/features/Oest_Pan/views/LoginView')); // Loading component const PageLoader = () => ( ); /** * Componente de proteção de rotas. * Redireciona para o login se o usuário não estiver autenticado. */ const ProtectedRoute = ({ children, loginPath = '/plataforma/auth/login', environment = 'global' }) => { const { user, loading, isAuthorized } = useAuthContext(); const location = useLocation(); if (loading) return ; // Verifica autorização - isAuthorized já verifica o usuário do módulo específico if (!isAuthorized(environment)) { return ; } return children; }; function App() { return ( }> {/* Portal Home - System Selection */} } /> {/* 🔧 COMPONENT LABORATORY - Design System Testing */} }> } /> {/* Auth Login - Explícitos */} } /> } /> } /> {/* Fleet Management Management (Legacy) */} } /> } /> } /> {/* HR Management (Modern) */} } /> {/* Fleet V2 Environment - Protegido */} } /> {/* Financeiro V2 Environment - Protegido */} } /> {/* Prafrot Environment */} } /> } /> } /> }> } /> {/* GR Environment (Gestão de Risco) */} } /> } /> } /> } /> {/* Workspace Environment - Novo Ambiente Modernizado */} } /> } /> } /> {/* Financeiro CNAB Environment */} } /> {/* Auto Lab Environment */} } /> } /> } /> {/* Oeste Pan Environment */} } /> } /> } /> {/* Fallback */} } /> {/* GR Public Routes */} }> } /> ); } // Wrapper component to use the hook inside the provider context if needed, // though here it's at the top level so we just need to import the store. const LoadingOverlayWrapper = () => { const { isLoading, loadingMessage } = useGlobalLoading(); return ; }; export default App;