import React from 'react'
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
import { ConfigProvider } from 'antd'
import zhCN from 'antd/locale/zh_CN'
import TabBarLayout from './components/TabBarLayout'
import ProtectedRoute from './components/ProtectedRoute'
import AdminRoute from './components/AdminRoute'
import QuestionPage from './pages/Question'
import Login from './pages/Login'
import Home from './pages/Home'
import About from './pages/About'
import WrongQuestions from './pages/WrongQuestions'
import QuestionManagement from './pages/QuestionManagement'
import QuestionList from './pages/QuestionList'
import UserManagement from './pages/UserManagement'
import UserDetail from './pages/UserDetail'
import ExamPrepare from './pages/ExamPrepare'
import ExamOnline from './pages/ExamOnline'
import ExamPrint from './pages/ExamPrint'
import ExamResult from './pages/ExamResult'
import ExamManagement from './pages/ExamManagement'
import ExamTaking from './pages/ExamTaking'
import ExamResultNew from './pages/ExamResultNew'

const App: React.FC = () => {
  return (
    <ConfigProvider locale={zhCN}>
      <Router>
        <Routes>
          {/* 带TabBar的页面，需要登录保护 */}
          <Route element={<ProtectedRoute><TabBarLayout /></ProtectedRoute>}>
            <Route path="/" element={<Home />} />
            <Route path="/question" element={<QuestionPage />} />
          </Route>

          {/* 不带TabBar的页面，但需要登录保护 */}
          <Route path="/wrong-questions" element={<ProtectedRoute><WrongQuestions /></ProtectedRoute>} />
          <Route path="/question-list" element={<ProtectedRoute><QuestionList /></ProtectedRoute>} />

          {/* 考试相关页面，需要登录保护 */}
          <Route path="/exam/new" element={<ProtectedRoute><ExamPrepare /></ProtectedRoute>} />
          <Route path="/exam/management" element={<ProtectedRoute><ExamManagement /></ProtectedRoute>} />
          <Route path="/exam/:examId/online" element={<ProtectedRoute><ExamOnline /></ProtectedRoute>} />
          <Route path="/exam/:examId/taking/:recordId" element={<ProtectedRoute><ExamTaking /></ProtectedRoute>} />
          <Route path="/exam/:examId/print" element={<ProtectedRoute><ExamPrint /></ProtectedRoute>} />
          <Route path="/exam/:examId/result" element={<ProtectedRoute><ExamResult /></ProtectedRoute>} />
          <Route path="/exam/result/:recordId" element={<ProtectedRoute><ExamResultNew /></ProtectedRoute>} />

          {/* 题库管理页面，需要管理员权限 */}
          <Route path="/question-management" element={
            <ProtectedRoute>
              <AdminRoute>
                <QuestionManagement />
              </AdminRoute>
            </ProtectedRoute>
          } />

          {/* 用户管理页面，仅yanlongqi用户可访问 */}
          <Route path="/user-management" element={
            <ProtectedRoute>
              <AdminRoute>
                <UserManagement />
              </AdminRoute>
            </ProtectedRoute>
          } />

          {/* 用户详情页面，仅yanlongqi用户可访问 */}
          <Route path="/user-management/:id" element={
            <ProtectedRoute>
              <AdminRoute>
                <UserDetail />
              </AdminRoute>
            </ProtectedRoute>
          } />

          {/* 不带TabBar的页面，不需要登录保护 */}
          <Route path="/login" element={<Login />} />
          <Route path="/about" element={<About />} />
        </Routes>
      </Router>
    </ConfigProvider>
  )
}

export default App
