import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { useState } from 'react';
import Register from './components/Register';
import ConfigForm from './components/ConfigForm';
import Home from './pages/Home';
import TextToSpeechPage from './pages/TextToSpeechPage';
import LoginPage from './pages/LoginPage';
import ProtectedRoute from './components/ProtectedRoute';
import OCRDashboard from './pages/OCRDashboardPage';
import ERPCredential from './pages/ERPCredentialPage';
import OCRTemplate from './pages/OCRTemplatePage';
import Logout from './components/Logout';
import Chat from './pages/ChatPage';
import Analytics from './pages/AnalyticsPage';
import DocumentManagement from './pages/DocumentManagement';

function App() {
  const [token, setToken] = useState(localStorage.getItem('token'));

  return (
    <Router>
      <div className="min-h-screen flex flex-col">
        <Routes>
          <Route path="/" element={<Navigate to="/ocrdashboard" replace />} />
          <Route path="/text-to-speech" element={<ProtectedRoute token={token}><TextToSpeechPage /></ProtectedRoute>} />
          <Route path="/login" element={<LoginPage setToken={setToken} />} />
          <Route path="/logout" element={<ProtectedRoute token={token}><Logout setToken={setToken} /></ProtectedRoute>} />
          <Route path="/register" element={<Register />} />
          <Route path="/ocrdashboard" element={<ProtectedRoute token={token}><OCRDashboard /></ProtectedRoute>} />
          <Route path="/ocrtemplate" element={<ProtectedRoute token={token}><OCRTemplate /></ProtectedRoute>} />
          <Route path="/erpcredential" element={<ProtectedRoute token={token}><ERPCredential /></ProtectedRoute>} />
          <Route path="/chat" element={<ProtectedRoute token={token}><Chat /></ProtectedRoute>} />
          <Route path="/analytics" element={<ProtectedRoute token={token}><Analytics /></ProtectedRoute>} />
          <Route path="/models" element={<ProtectedRoute token={token}><DocumentManagement /></ProtectedRoute>} />
          <Route path="/config" element={<ProtectedRoute token={token}><ConfigForm /></ProtectedRoute>} />
        </Routes>
      </div>
    </Router>
  );
}

export default App;
