import { lazy, Suspense } from 'react' import { Navigate, Route, Routes } from 'react-router' import { LocaleProvider } from './components/LocaleProvider' import { ThemeProvider } from './components/ThemeProvider' import { Toaster } from './components/ui/sonner' import { AuthProvider, useAuth } from './contexts/AuthContext' import { SocketProvider } from './contexts/SocketContext' // Lazy load all pages for code splitting const AccountPage = lazy(() => import('./pages/AccountPage').then(m => ({ default: m.AccountPage }))) const AuthCallbackPage = lazy(() => import('./pages/AuthCallbackPage').then(m => ({ default: m.AuthCallbackPage }))) const DashboardPage = lazy(() => import('./pages/DashboardPage').then(m => ({ default: m.DashboardPage }))) const ExtractionsPage = lazy(() => import('./pages/ExtractionsPage').then(m => ({ default: m.ExtractionsPage }))) const LoginPage = lazy(() => import('./pages/LoginPage').then(m => ({ default: m.LoginPage }))) const PlaylistEditPage = lazy(() => import('./pages/PlaylistEditPage').then(m => ({ default: m.PlaylistEditPage }))) const PlaylistsPage = lazy(() => import('./pages/PlaylistsPage').then(m => ({ default: m.PlaylistsPage }))) const RegisterPage = lazy(() => import('./pages/RegisterPage').then(m => ({ default: m.RegisterPage }))) const SchedulersPage = lazy(() => import('./pages/SchedulersPage').then(m => ({ default: m.SchedulersPage }))) const SequencerPage = lazy(() => import('./pages/SequencerPage').then(m => ({ default: m.SequencerPage }))) const SoundsPage = lazy(() => import('./pages/SoundsPage').then(m => ({ default: m.SoundsPage }))) const TTSPage = lazy(() => import('./pages/TTSPage').then(m => ({ default: m.TTSPage }))) const SettingsPage = lazy(() => import('./pages/admin/SettingsPage').then(m => ({ default: m.SettingsPage }))) const UsersPage = lazy(() => import('./pages/admin/UsersPage').then(m => ({ default: m.UsersPage }))) // Loading component for lazy-loaded routes function PageLoader() { return (

Loading...

) } function ProtectedRoute({ children }: { children: React.ReactNode }) { const { user, loading } = useAuth() if (loading) { return (
Loading...
) } if (!user) { return } return <>{children} } function AdminRoute({ children }: { children: React.ReactNode }) { const { user, loading } = useAuth() if (loading) { return (
Loading...
) } if (!user) { return } if (user.role !== 'admin') { return } return <>{children} } function AppRoutes() { const { user } = useAuth() return ( }> : } /> : } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ) } function App() { return ( ) } export default App