import React from 'react';
import { createBrowserRouter, Navigate } from 'react-router';
import { ProtectedRoute } from './components/ProtectedRoute';
import { MainLayout } from './layouts/MainLayout';
import { ErrorPage } from './components/ErrorPage';
import { NotFoundPage } from './components/NotFoundPage';
import { DashboardPage } from './pages/Dashboard';
import { UsersPage } from './pages/Users';
import { ClassroomDataPage } from './pages/ClassroomDataPage';
import { SubmissionRecordsPage } from './pages/SubmissionRecordsPage';
import { StockDataPage } from './pages/StockDataPage';
import { StockXunlianCodesPage } from './pages/StockXunlianCodesPage';
import { DateNotesPage } from './pages/DateNotesPage';
import { LoginPage } from './pages/Login';
import { FilesPage } from './pages/Files';
import { ChatMessagesPage } from './pages/ChatMessages';
import { VodVideosPage } from './pages/VodVideos';

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: 'files',
        element: <FilesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'classroom-data',
        element: <ClassroomDataPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'submission-records',
        element: <SubmissionRecordsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'stock-data',
        element: <StockDataPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'stock-xunlian-codes',
        element: <StockXunlianCodesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'date-notes',
        element: <DateNotesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'chat-messages',
        element: <ChatMessagesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'vod-videos',
        element: <VodVideosPage />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);