﻿import { lazy } from 'react'
import type { AdminRole } from '@/types/admin'

const Dashboard = lazy(() => import('@/pages/Dashboard'))
const TaskAssistant = lazy(() => import('@/pages/TaskAssistant'))
const UserManagement = lazy(() => import('@/pages/UserManagement'))
const MemberManagement = lazy(() => import('@/pages/MemberManagement'))

const LearningDashboard = lazy(() => import('@/pages/learning/Dashboard'))
const ReadingEventPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.ReadingEventPage })))
const SessionPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.SessionPage })))
const ProgressPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.ProgressPage })))
const DailyActivityPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.DailyActivityPage })))
const RecordPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.RecordPage })))
const AnomalyPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.AnomalyPage })))
const UserDiagnosePage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.UserDiagnosePage })))
const MaterialDiagnosePage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.MaterialDiagnosePage })))

export interface RouteConfig {
  path: string
  title: string
  element: React.LazyExoticComponent<React.ComponentType<any>>
  requiredRole?: AdminRole
}

export const routeConfig: RouteConfig[] = [
  { path: '/', title: '总览', element: Dashboard },
  { path: '/assistant', title: '任务助理', element: TaskAssistant },
  { path: '/users', title: '用户管理', element: UserManagement, requiredRole: 'ADMIN' },
  { path: '/users/admins', title: '管理员', element: UserManagement, requiredRole: 'SUPER_ADMIN' },
  { path: '/users/members', title: '普通用户', element: MemberManagement },
  { path: '/membership', title: '会员与额度', element: UserManagement, requiredRole: 'ADMIN' },
  { path: '/knowledge/bases', title: '知识库列表', element: UserManagement },
  { path: '/knowledge/sources', title: '知识源列表', element: UserManagement },
  { path: '/imports', title: '文档导入', element: UserManagement },
  { path: '/ai-costs', title: 'AI 调用与成本', element: UserManagement },
  { path: '/files', title: '文件与 COS', element: UserManagement },
  { path: '/settings', title: '系统配置', element: UserManagement, requiredRole: 'ADMIN' },
  { path: '/audit', title: '审计日志', element: UserManagement, requiredRole: 'ADMIN' },
  // ── Learning Info ──
  { path: '/learning', title: '学习 Dashboard', element: LearningDashboard },
  { path: '/learning/events', title: '阅读事件', element: ReadingEventPage },
  { path: '/learning/sessions', title: '学习会话', element: SessionPage },
  { path: '/learning/progress', title: '阅读进度', element: ProgressPage },
  { path: '/learning/daily', title: '每日活动', element: DailyActivityPage },
  { path: '/learning/records', title: '学习记录', element: RecordPage },
  { path: '/learning/anomalies', title: '异常数据', element: AnomalyPage },
  { path: '/learning/user-diagnose', title: '用户诊断', element: UserDiagnosePage },
  { path: '/learning/material-diagnose', title: '资料诊断', element: MaterialDiagnosePage },
]
