import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
import { ConfigProvider } from 'antd'
import zhCN from 'antd/locale/zh_CN'
import AppLayout from './components/Layout/AppLayout'
import Login from './pages/Login/Login'
import Dashboard from './pages/Dashboard/Dashboard'
import EditorHome from './pages/EditorHome/EditorHome'
import TPS from './pages/TPS/TPS'
import KnowledgeBase from './pages/KnowledgeBase/KnowledgeBase'
import Doco from './pages/Doco/Doco'
import UserManage from './pages/UserManage/UserManage'
import EditorDesk from './pages/EditorDesk/EditorDesk'
import AuthGuard from './components/AuthGuard/AuthGuard'
import RoleGuard from './components/AuthGuard/RoleGuard'

const theme = {
  token: {
    colorPrimary: '#6b8e6b',
    borderRadius: 12,
    borderRadiusLG: 16,
  },
}

function App() {
  return (
    <ConfigProvider locale={zhCN} theme={theme}>
      <BrowserRouter>
        <Routes>
          <Route path="/login" element={<Login />} />
          <Route path="/" element={<AuthGuard />}>
            <Route element={<AppLayout />}>
              <Route index element={<Navigate to="/dashboard" replace />} />
              <Route path="dashboard" element={<Dashboard />} />
              <Route path="tps" element={<TPS />} />
              <Route path="knowledge" element={<KnowledgeBase />} />
              <Route path="doco" element={<Doco />} />
              <Route path="editor-home" element={<EditorHome />} />
              <Route
                path="users"
                element={
                  <RoleGuard roles={['zhipianren']}>
                    <UserManage />
                  </RoleGuard>
                }
              />
              <Route
                path="editor-desk"
                element={
                  <RoleGuard roles={['zhipianren', 'zebian']}>
                    <EditorDesk />
                  </RoleGuard>
                }
              />
            </Route>
          </Route>
        </Routes>
      </BrowserRouter>
    </ConfigProvider>
  )
}

export default App