import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import React, { useEffect, useState, useCallback, Suspense } from 'react'; import { AnimatePresence } from 'framer-motion'; import { AuthProvider } from './contexts/AuthContext'; import { ToastProvider } from './contexts/ToastContext'; import { useUserStore } from './store/userStore'; import SplashScreen from './components/SplashScreen'; import { Loader2 } from 'lucide-react'; import Landing from './pages/Landing'; import Login from './pages/Login'; import AuthCallback from './pages/AuthCallback'; import AppLayout from './components/layout/AppLayout'; import ProtectedRoute from './components/ProtectedRoute'; // Lazy load non-critical routes for performance optimization const DataHub = React.lazy(() => import('./pages/DataHub')); const AnalystChat = React.lazy(() => import('./pages/AnalystChat')); const Reports = React.lazy(() => import('./pages/Reports')); const Settings = React.lazy(() => import('./pages/Settings')); const NotificationSettings = React.lazy(() => import('./pages/NotificationSettings')); const Signup = React.lazy(() => import('./pages/Signup')); const AcceptInvite = React.lazy(() => import('./pages/AcceptInvite')); const ForgotPassword = React.lazy(() => import('./pages/ForgotPassword')); const UpdatePassword = React.lazy(() => import('./pages/UpdatePassword')); const EmailConfirm = React.lazy(() => import('./pages/EmailConfirm')); const AutonomousDashboard = React.lazy(() => import('./pages/AutonomousDashboard')); const MLPredictions = React.lazy(() => import('./pages/MLPredictions')); const Clustering = React.lazy(() => import('./pages/Clustering')); const ScenarioSimulator = React.lazy(() => import('./pages/ScenarioSimulator')); const DataLineage = React.lazy(() => import('./pages/DataLineage')); const Collaborate = React.lazy(() => import('./pages/Collaborate')); const Developer = React.lazy(() => import('./pages/Developer')); const ComputerVision = React.lazy(() => import('./pages/ComputerVision')); const Autopilot = React.lazy(() => import('./pages/Autopilot')); const PrivacyPolicy = React.lazy(() => import('./pages/PrivacyPolicy')); const TermsOfService = React.lazy(() => import('./pages/TermsOfService')); const HelpCenter = React.lazy(() => import('./pages/HelpCenter')); const DataStories = React.lazy(() => import('./pages/DataStories')); const PipelineBuilder = React.lazy(() => import('./pages/PipelineBuilder')); const EmbedWidget = React.lazy(() => import('./pages/EmbedWidget')); const AdminLogin = React.lazy(() => import('./pages/AdminLogin')); const AdminDashboard = React.lazy(() => import('./pages/AdminDashboard')); function App() { const [showSplash, setShowSplash] = useState(false); // Splash screen disabled const { isDark, accentTheme } = useUserStore(); // Apply theme on mount & changes useEffect(() => { // 1. Dark/Light Mode if (isDark) { document.documentElement.classList.remove('light-theme'); document.documentElement.classList.add('dark'); document.body.classList.remove('light-theme'); } else { document.documentElement.classList.add('light-theme'); document.documentElement.classList.remove('dark'); document.body.classList.add('light-theme'); } // 2. Accent Theme // Remove all existing accent themes document.documentElement.classList.forEach(className => { if (className.startsWith('theme-')) { document.documentElement.classList.remove(className); } }); // Add new accent theme if (accentTheme && accentTheme !== 'default') { document.documentElement.classList.add(`theme-${accentTheme}`); } }, [isDark, accentTheme]); const handleSplashComplete = useCallback(() => { setShowSplash(false); }, []); return ( <> {showSplash && ( )}
}> {/* Public routes */} } /> } /> } /> } /> } /> } /> } /> } /> {/* Legal & Help Pages */} } /> } /> } /> {/* Redirect /overview to /data-hub */} } /> {/* Standalone Embedded Widget */} } /> {/* Admin Console — separate from normal user auth */} } /> } /> {/* Chat - Full screen without main navigation */} } /> {/* Embed Widgets - Standalone, unauthenticated (token-based) route */} } /> {/* Protected routes wrapped in AppLayout */} }> } /> } /> } /> } /> } /> } /> {/* V3 New Pages */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Legacy redirects */} } /> {/* Redirect any unknown route to home */} } />
); } export default App;