import React from 'react';
import { createBrowserRouter, Navigate } from 'react-router';
import { ProtectedRoute } from './components_protected_route.tsx';
import { MainLayout } from './layouts/MainLayout.tsx';
import { ErrorPage } from './components/ErrorPage.tsx';
import { NotFoundPage } from './components/NotFoundPage.tsx';
import { DashboardPage } from './pages_dashboard.tsx';
import { UsersPage } from './pages_users.tsx';
import { FileLibraryPage } from './pages_file_library.tsx';
import { KnowInfoPage } from './pages_know_info.tsx';
import { MessagesPage } from './pages_messages.tsx';
import { SettingsPage } from './pages_settings.tsx';
import { ThemeSettingsPage } from './pages_theme_settings.tsx';
import { ChartDashboardPage } from './pages_chart.tsx';
import { LoginMapPage } from './pages_map.tsx';
import { LoginPage } from './pages_login_reg.tsx';
import { ClassroomDataPage } from './pages_classroom_data.tsx';
import { DateNotesPage } from './pages_date_notes.tsx';
import { SubmissionRecordsPage } from './pages_submission_records.tsx';
import { XunlianCodePage } from './pages_xunlian_codes.tsx';
import { VodUploadPage } from './pages_vod_upload.tsx';

export const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/admin" replace />
  },
  {
    path: '/admin/login',
    element: <LoginPage />
  },
  {
    path: '/admin',
    element: (
      <ProtectedRoute>
        <MainLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/admin/dashboard" />
      },
      {
        path: 'dashboard',
        element: <DashboardPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'users',
        element: <UsersPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'settings',
        element: <SettingsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'theme-settings',
        element: <ThemeSettingsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'chart-dashboard',
        element: <ChartDashboardPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'map-dashboard',
        element: <LoginMapPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'know-info',
        element: <KnowInfoPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'file-library',
        element: <FileLibraryPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'messages',
        element: <MessagesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'classroom-data',
        element: <ClassroomDataPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'date-notes',
        element: <DateNotesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'submission-records',
        element: <SubmissionRecordsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'xunlian-codes',
        element: <XunlianCodePage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'vod-upload',
        element: <VodUploadPage />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
]);