import { createBrowserRouter, Navigate } from 'react-router'
import { authLoader } from './guards'
import {
  DefaultLayout,
  Login,
  Dashboard,
  UserManagement,
  RoleManagement,
  MenuManagement,
  ConfigManagement,
  DictManagement,
  FileManagement,
  NoticeManagement,
  LoginLog,
  OperationLog,
  ExceptionLog,
  Forbidden,
} from './routes'

export const router = createBrowserRouter([
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/403',
    element: <Forbidden />,
  },
  {
    path: '/',
    element: <DefaultLayout />,
    loader: authLoader,
    children: [
      { index: true, element: <Navigate to="/dashboard" replace /> },
      { path: 'dashboard', element: <Dashboard /> },
      { path: 'users', element: <UserManagement /> },
      { path: 'roles', element: <RoleManagement /> },
      { path: 'menus', element: <MenuManagement /> },
      { path: 'sys/config', element: <ConfigManagement /> },
      { path: 'dict', element: <DictManagement /> },
      { path: 'files', element: <FileManagement /> },
      { path: 'notice', element: <NoticeManagement /> },
      { path: 'loginlog', element: <LoginLog /> },
      { path: 'oplog', element: <OperationLog /> },
      { path: 'exceptionlog', element: <ExceptionLog /> },
    ],
  },
])
