import type { StudentDashboardGradeProps, StudentHomeworkAssignmentListItem } from "@/modules/homework/types"
import type { TeacherClass, ClassScheduleItem } from "@/modules/classes/types"
import type { HomeworkAssignmentListItem, HomeworkSubmissionListItem, TeacherGradeTrendItem } from "@/modules/homework/types"

export type AdminDashboardUserRoleCount = {
  role: string
  count: number
}

export type AdminDashboardRecentUser = {
  id: string
  name: string | null
  email: string
  role: string | null
  createdAt: string
}

export type AdminDashboardData = {
  activeSessionsCount: number
  userCount: number
  userRoleCounts: AdminDashboardUserRoleCount[]
  classCount: number
  textbookCount: number
  chapterCount: number
  questionCount: number
  examCount: number
  homeworkAssignmentCount: number
  homeworkAssignmentPublishedCount: number
  homeworkSubmissionCount: number
  homeworkSubmissionToGradeCount: number
  recentUsers: AdminDashboardRecentUser[]
  userGrowth: Array<{ date: string; count: number }>
  homeworkTrend: Array<{ date: string; count: number }>
}

export type StudentTodayScheduleItem = {
  id: string
  classId: string
  className: string
  course: string
  startTime: string
  endTime: string
  location: string | null
}

export type StudentDashboardProps = {
  studentName: string
  enrolledClassCount: number
  dueSoonCount: number
  overdueCount: number
  gradedCount: number
  todayScheduleItems: StudentTodayScheduleItem[]
  upcomingAssignments: StudentHomeworkAssignmentListItem[]
  grades: StudentDashboardGradeProps
}

export type TeacherTodayScheduleItem = {
  id: string
  classId: string
  className: string
  course: string
  startTime: string
  endTime: string
  location: string | null
}

export type TeacherDashboardData = {
  classes: TeacherClass[]
  schedule: ClassScheduleItem[]
  assignments: HomeworkAssignmentListItem[]
  submissions: HomeworkSubmissionListItem[]
  teacherName: string
  gradeTrends: TeacherGradeTrendItem[]
}

// ─── 配置驱动 Widget 渲染 ─────────────────────────────────

/** 仪表盘角色 */
export type DashboardRole = "admin" | "teacher" | "student" | "parent"

/** Widget 骨架屏变体（与 DashboardSection 对齐） */
export type WidgetSkeletonVariant = "stats" | "card" | "chart" | "table" | "list"

/**
 * Widget 配置项。
 *
 * 通过配置决定每个角色仪表盘渲染哪些 Widget 及其布局，
 * 新增角色或调整 Widget 只需修改配置，不需动组件代码。
 */
export interface DashboardWidgetConfig {
  /** Widget 唯一标识（用于埋点） */
  id: string
  /** Widget 渲染区域标识（用于布局分配） */
  slot: string
  /** 骨架屏变体 */
  skeletonVariant: WidgetSkeletonVariant
  /** 响应式布局类名（Tailwind grid classes） */
  layoutClassName: string
  /** 是否默认显示（可被用户偏好覆盖） */
  defaultVisible: boolean
}

/** 角色仪表盘布局配置 */
export interface DashboardLayoutConfig {
  role: DashboardRole
  widgets: DashboardWidgetConfig[]
}
