import React, { useMemo } from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { ThemeProvider, CssBaseline } from '@mui/material';
import { useThemeStore } from './store/themeStore';
import { useAuthStore } from './store/authStore';
import { lightTheme, darkTheme } from './theme';
import { SecurityNotificationProvider } from './components/SecurityNotificationProvider';
import Login from './pages/Login';
import Register from './pages/Register';
import Dashboard from './pages/Dashboard';
import LiveTV from './pages/LiveTV';
import Radio from './pages/Radio';
import Movies from './pages/Movies';
import Series from './pages/Series';
import Favorites from './pages/Favorites';
import Settings from './pages/Settings';
import Stats from './pages/Stats';
import SecurityDashboard from './pages/SecurityDashboard';
import CSPDashboard from './components/CSPDashboard';
import RBACDashboard from './components/RBACDashboard';
import SecurityMonitor from './pages/SecurityMonitor';
import SecurityHeadersDashboard from './components/SecurityHeadersDashboard';
import SecurityTestingDashboard from './components/SecurityTestingDashboard';
import SecurityIntelligenceDashboard from './pages/SecurityIntelligenceDashboard';
import SecurityConfigDashboard from './pages/SecurityConfigDashboard';
import LogManagementDashboard from './components/LogManagementDashboard';
import EncryptionManagementDashboard from './components/EncryptionManagementDashboard';

function App() {
  const { mode } = useThemeStore();
  const { isAuthenticated } = useAuthStore();

  const theme = useMemo(() => (mode === 'light' ? lightTheme : darkTheme), [mode]);

  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      <SecurityNotificationProvider>
        <Router>
        <Routes>
          <Route path="/login" element={!isAuthenticated ? <Login /> : <Navigate to="/" />} />
          {/* Registration disabled - redirect to login */}
          <Route path="/register" element={<Navigate to="/login" replace />} />
          <Route path="/" element={isAuthenticated ? <Dashboard /> : <Navigate to="/login" />}>
            <Route index element={<LiveTV />} />
            <Route path="live-tv" element={<LiveTV />} />
            <Route path="radio" element={<Radio />} />
            <Route path="movies" element={<Movies />} />
            <Route path="series" element={<Series />} />
            <Route path="favorites" element={<Favorites />} />
            <Route path="favorites/:type" element={<Favorites />} />
            <Route path="stats" element={<Stats />} />
            <Route path="security" element={<SecurityDashboard />} />
            <Route path="security/csp" element={<CSPDashboard />} />
            <Route path="security/rbac" element={<RBACDashboard />} />
            <Route path="security/monitor" element={<SecurityMonitor />} />
            <Route path="security/headers" element={<SecurityHeadersDashboard />} />
            <Route path="security/testing" element={<SecurityTestingDashboard />} />
            <Route path="security/intelligence" element={<SecurityIntelligenceDashboard />} />
            <Route path="security/config" element={<SecurityConfigDashboard />} />
            <Route path="security/logs" element={<LogManagementDashboard />} />
            <Route path="security/encryption" element={<EncryptionManagementDashboard />} />
            <Route path="settings" element={<Settings />} />
            <Route path="settings/sessions" element={<Settings />} />
          </Route>
        </Routes>
      </Router>
      </SecurityNotificationProvider>
    </ThemeProvider>
  );
}

export default App;
