/**
 * 考勤状态共享常量。
 *
 * 考勤状态是跨模块的 UI 关注点（attendance / parent / 未来可能的 notifications 等
 * 均需使用），因此类型与视觉映射下沉至 shared 层，避免业务模块间相互依赖。
 *
 * 规则遵循：`shared/` 不得反向依赖任何 `modules/*`。
 *
 * L-1 演进：新增 `school_activity`（校内活动请假，如运动会、研学、社团活动）。
 */

/** 考勤状态枚举（跨模块共享）。 */
export type AttendanceStatus =
  | "present"
  | "absent"
  | "late"
  | "early_leave"
  | "excused"
  | "school_activity"

/** 考勤状态选项（顺序即 UI 展示顺序）。 */
export const ATTENDANCE_STATUS_OPTIONS: AttendanceStatus[] = [
  "present",
  "absent",
  "late",
  "early_leave",
  "excused",
  "school_activity",
]

/** 考勤状态 → i18n key 映射（组件层 `t(key)` 解析，namespace 为 attendance）。 */
export const ATTENDANCE_STATUS_LABEL_KEYS: Record<AttendanceStatus, string> = {
  present: "status.present",
  absent: "status.absent",
  late: "status.late",
  early_leave: "status.early_leave",
  excused: "status.excused",
  school_activity: "status.school_activity",
}

/** 考勤状态 → Badge variant 映射。 */
export const ATTENDANCE_STATUS_BADGE_VARIANTS: Record<
  AttendanceStatus,
  "default" | "secondary" | "destructive" | "outline"
> = {
  present: "default",
  absent: "destructive",
  late: "secondary",
  early_leave: "outline",
  excused: "outline",
  school_activity: "outline",
}

/** 考勤状态 → Tailwind 圆点颜色类。 */
export const ATTENDANCE_STATUS_DOT_COLORS: Record<AttendanceStatus, string> = {
  present: "bg-green-500",
  absent: "bg-red-500",
  late: "bg-yellow-500",
  early_leave: "bg-blue-500",
  excused: "bg-purple-500",
  school_activity: "bg-cyan-500",
}

/** 键盘快捷键映射（考勤点名场景）。 */
export const ATTENDANCE_STATUS_SHORTCUTS: Record<string, AttendanceStatus> = {
  p: "present",
  a: "absent",
  l: "late",
  e: "early_leave",
  x: "excused",
  s: "school_activity",
}

/** 初始化状态计数，避免 `{} as Record<...>` 类型断言。 */
export function createInitialStatusCounts(): Record<AttendanceStatus, number> {
  return {
    present: 0,
    absent: 0,
    late: 0,
    early_leave: 0,
    excused: 0,
    school_activity: 0,
  }
}

/** 类型守卫：验证字符串是否为合法考勤状态。 */
export function isAttendanceStatus(v: unknown): v is AttendanceStatus {
  return (
    v === "present" ||
    v === "absent" ||
    v === "late" ||
    v === "early_leave" ||
    v === "excused" ||
    v === "school_activity"
  )
}
