/* eslint-disable react-refresh/only-export-components */
import { lazy } from 'react';
import { Navigate } from 'react-router-dom';
import type { RouteObject } from 'react-router-dom';

import AuthGuard from './AuthGuard';
import BasicLayout from '@/layouts/BasicLayout';
import BlankLayout from '@/layouts/BlankLayout';

const Login = lazy(() => import('@/pages/login'));
const Dashboard = lazy(() => import('@/pages/dashboard'));
const LLM = lazy(() => import('@/pages/llm'));
const LLMProviders = lazy(() => import('@/pages/llm/providers'));
const UserManagement = lazy(() => import('@/pages/system/user'));
const RoleManagement = lazy(() => import('@/pages/system/role'));
const PermissionManagement = lazy(() => import('@/pages/system/permission'));
const NotFound = lazy(() => import('@/pages/exception/404'));
const Forbidden = lazy(() => import('@/pages/exception/403'));

export const routes: RouteObject[] = [
  {
    path: '/login',
    element: <BlankLayout />,
    children: [{ index: true, element: <Login /> }],
  },
  {
    path: '/404',
    element: <BlankLayout />,
    children: [{ index: true, element: <NotFound /> }],
  },
  {
    path: '/403',
    element: <BlankLayout />,
    children: [{ index: true, element: <Forbidden /> }],
  },
  {
    path: '/',
    element: <AuthGuard />,
    children: [
      {
        element: <BasicLayout />,
        children: [
          { index: true, element: <Navigate to="/dashboard" replace /> },
          { path: 'dashboard', element: <Dashboard /> },
          { path: 'llm', element: <Navigate to="/llm/models" replace /> },
          { path: 'llm/models', element: <LLM /> },
          { path: 'llm/providers', element: <LLMProviders /> },
          { path: 'llm/usage', element: <div>用量统计</div> },
          { path: 'llm/usage/details', element: <div>用量明细</div> },
          { path: 'llm/quota', element: <div>限流配额</div> },
          { path: 'system/user', element: <UserManagement /> },
          { path: 'system/role', element: <RoleManagement /> },
          { path: 'system/permission', element: <PermissionManagement /> },
          { path: 'system/permission/menu', element: <Navigate to="/system/permission" replace /> },
          { path: 'system/permission/button', element: <Navigate to="/system/permission" replace /> },
          { path: '*', element: <NotFound /> },
        ],
      },
    ],
  },
  { path: '*', element: <Navigate to="/404" replace /> },
];
