import React from 'react';
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { ConfigProvider, App as AntdApp } from 'antd';
import zhCN from 'antd/es/locale/zh_CN';
import MainLayout from './layouts/MainLayout';
import LoginPage from './pages/Login';
import DashboardPage from './pages/Dashboard';
import StudentsPage from './pages/Students';
import RoomsPage from './pages/Rooms';
import OccupanciesPage from './pages/Occupancies';
import ExpensesPage from './pages/Expenses';
import BillsPage from './pages/Bills';
import RoomVisualPage from './pages/RoomVisual';
import OperationLogsPage from './pages/OperationLogs';
import UsersPage from './pages/Users';
import DepositsPage from './pages/Deposits';
import ClassroomsPage from './pages/Classrooms';
import TenantsPage from './pages/Tenants';
import ClassroomRentalsPage from './pages/ClassroomRentals';
import ClassroomSchedulePage from './pages/ClassroomSchedule';

const PrivateRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  const token = localStorage.getItem('token');
  return token ? <>{children}</> : <Navigate to="/login" />;
};

const App: React.FC = () => {
  return (
    <ConfigProvider locale={zhCN} theme={{ token: { colorPrimary: '#007AFF', borderRadius: 10, colorBgContainer: '#fff', fontFamily: "-apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif" } }}>
      <AntdApp>
      <BrowserRouter>
        <Routes>
          <Route path="/login" element={<LoginPage />} />
          <Route path="/" element={<PrivateRoute><MainLayout /></PrivateRoute>}>
            <Route index element={<Navigate to="/dashboard" />} />
            <Route path="dashboard" element={<DashboardPage />} />
            <Route path="students" element={<StudentsPage />} />
            <Route path="rooms" element={<RoomsPage />} />
            <Route path="occupancies" element={<OccupanciesPage />} />
            <Route path="expenses" element={<ExpensesPage />} />
            <Route path="deposits" element={<DepositsPage />} />
            <Route path="bills" element={<BillsPage />} />
            <Route path="room-visual" element={<RoomVisualPage />} />
            <Route path="operation-logs" element={<OperationLogsPage />} />
            <Route path="users" element={<UsersPage />} />
            <Route path="classrooms" element={<ClassroomsPage />} />
            <Route path="tenants" element={<TenantsPage />} />
            <Route path="classroom-rentals" element={<ClassroomRentalsPage />} />
            <Route path="classroom-schedule" element={<ClassroomSchedulePage />} />
          </Route>
        </Routes>
      </BrowserRouter>
      </AntdApp>
    </ConfigProvider>
  );
};

export default App;
