import { lazy, Suspense } from 'react' import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom' import { AuthProvider, useAuth } from './context/AuthContext' import { ThemeProvider } from './context/ThemeContext' import Navbar from './components/Navbar' const LoginPage = lazy(() => import('./pages/LoginPage')) const RegisterPage = lazy(() => import('./pages/RegisterPage')) const DashboardPage = lazy(() => import('./pages/DashboardPage')) const UploadPage = lazy(() => import('./pages/UploadPage')) const DocumentDetailPage = lazy(() => import('./pages/DocumentDetailPage')) const QuizPage = lazy(() => import('./pages/QuizPage')) const CustomQuizPage = lazy(() => import('./pages/CustomQuizPage')) const QuizzesPage = lazy(() => import('./pages/QuizzesPage')) const ResultsPage = lazy(() => import('./pages/ResultsPage')) const AdminPage = lazy(() => import('./pages/AdminPage')) const AccountPage = lazy(() => import('./pages/AccountPage')) const SettingsPage = lazy(() => import('./pages/SettingsPage')) const QuestionBankPage = lazy(() => import('./pages/QuestionBankPage')) const QuestionManagerPage = lazy(() => import('./pages/QuestionManagerPage')) const CategoriesPage = lazy(() => import('./pages/CategoriesPage')) const QuestionEditPage = lazy(() => import('./pages/QuestionEditPage')) const AnalysisPage = lazy(() => import('./pages/AnalysisPage')) const JobsPage = lazy(() => import('./pages/JobsPage')) const TrashPage = lazy(() => import('./pages/TrashPage')) const QuizEditPage = lazy(() => import('./pages/QuizEditPage')) const VerifyEmailPage = lazy(() => import('./pages/VerifyEmailPage')) const ForgotPasswordPage = lazy(() => import('./pages/ForgotPasswordPage')) const ResetPasswordPage = lazy(() => import('./pages/ResetPasswordPage')) const NotFoundPage = lazy(() => import('./pages/NotFoundPage')) const LandingPage = lazy(() => import('./pages/LandingPage')) const FlashcardsPage = lazy(() => import('./pages/FlashcardsPage')) const ArticlesPage = lazy(() => import('./pages/ArticlesPage')) const SearchPage = lazy(() => import('./pages/SearchPage')) const AiModePage = lazy(() => import('./pages/AiModePage')) const MediaPage = lazy(() => import('./pages/MediaPage')) const StudyPlansPage = lazy(() => import('./pages/StudyPlansPage')) const StudyPlanPage = lazy(() => import('./pages/StudyPlanPage')) const ArticlePage = lazy(() => import('./pages/ArticlesPage').then(m => ({ default: m.ArticlePage }))) const PublicQuizPage = lazy(() => import('./pages/PublicQuizPage')) const FlashcardStudyPage = lazy(() => import('./pages/FlashcardStudyPage')) const CoursesPage = lazy(() => import('./pages/CoursesPage')) const CourseDetailPage = lazy(() => import('./pages/CourseDetailPage')) const CourseEditorPage = lazy(() => import('./pages/CourseEditorPage')) const SsoCallbackPage = lazy(() => import('./pages/SsoCallbackPage')) function LoadingFallback() { return
} // Layout wrapper for authenticated app pages (Navbar + container + footer) function AppLayout() { return ( <>
© {new Date().getFullYear()} PedsHub
) } // Guard: redirect to /home if not logged in, or to / if not moderator function RequireAuth({ moderator = false }) { const { user, loading } = useAuth() if (loading) return if (!user) return if (moderator && user.role !== 'admin' && user.role !== 'moderator') return return } function AppRoutes() { const { user, loading } = useAuth() if (loading) return return ( }> {/* Always public */} } /> : } /> : } /> } /> } /> } /> } /> } /> {/* Authenticated app — wrapped in AppLayout */} }> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Cross-references in article prose address a topic by slug, which outlives a numeric id and is what an educator actually writes. */} } /> } /> } /> } /> } /> } /> {/* Moderator-only */} }> }> } /> } /> } /> } /> } /> } /> } /> {/* Catch-all */} : } /> ) } export default function App() { return ( ) }