import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'; import { Toaster } from 'react-hot-toast'; import { useEffect, Suspense, lazy } from 'react'; import { ErrorBoundary } from './components/ErrorBoundary'; import { useSettingsStore } from './store/settingsStore'; import { config } from './config'; // Lazy load pages for better performance const HomePage = lazy(() => import('./pages/HomePage').then(m => ({ default: m.HomePage }))); const LoginPage = lazy(() => import('./pages/auth/LoginPage').then(m => ({ default: m.LoginPage }))); const RegisterPage = lazy(() => import('./pages/auth/RegisterPage').then(m => ({ default: m.RegisterPage }))); const ChatPage = lazy(() => import('./pages/chat/ChatPage').then(m => ({ default: m.ChatPage }))); const ProfilePage = lazy(() => import('./pages/ProfilePage').then(m => ({ default: m.ProfilePage }))); const CheckoutPage = lazy(() => import('./pages/CheckoutPage').then(m => ({ default: m.CheckoutPage }))); const ProtectedRoute = lazy(() => import('./hooks/useProtectedRoute').then(m => ({ default: m.ProtectedRoute }))); // Loading component for Suspense fallback function PageLoader() { return (

Loading...

); } function App() { const { theme, setTheme } = useSettingsStore(); // Initialize theme on app load useEffect(() => { // Apply theme to document document.documentElement.className = theme.mode; // Set theme color meta tag for mobile browsers const themeColorMeta = document.querySelector('meta[name="theme-color"]'); if (themeColorMeta) { themeColorMeta.setAttribute('content', theme.colors.primary); } // Set default theme if configured if (config.ui.defaultTheme !== theme.mode && !localStorage.getItem('settings-storage')) { const defaultTheme = theme.mode === 'light' ? { ...theme, mode: config.ui.defaultTheme as 'light' | 'dark' } : theme; setTheme(defaultTheme); } }, [theme, setTheme]); // Set document title useEffect(() => { document.title = config.appName; // Set meta description const metaDescription = document.querySelector('meta[name="description"]'); if (metaDescription) { metaDescription.setAttribute('content', config.appDescription); } }, []); // Log app info in development useEffect(() => { if (config.isDevelopment) { console.log(`%c${config.appName} v${config.appVersion}`, 'color: #3b82f6; font-weight: bold; font-size: 16px;'); console.log('Environment:', config.nodeEnv); console.log('Features:', config.features); } }, []); return (
}> {/* Public routes */} } /> } /> } /> {/* Protected routes */} } /> } /> } /> } /> {/* Catch-all redirect */} } /> {/* Toast notifications with theme-aware styling */}
); } export default App;