/**
 * 教材模块共享常量。
 *
 * 集中管理学科、年级、学科颜色映射，避免在 filters/form/settings/card 多处硬编码导致不一致。
 */

export type SubjectOption = {
  /** 存储值（英文 key，写入数据库） */
  value: string
  /** i18n 键（用于翻译显示） */
  labelKey: string
}

export type GradeOption = {
  value: string
  labelKey: string
}

/**
 * 学科列表。
 * 新增学科只需在此处添加一条记录，所有 Select/筛选/表单/设置弹窗自动同步。
 */
export const SUBJECTS: readonly SubjectOption[] = [
  { value: "Chinese", labelKey: "chinese" },
  { value: "Mathematics", labelKey: "mathematics" },
  { value: "Physics", labelKey: "physics" },
  { value: "Chemistry", labelKey: "chemistry" },
  { value: "Biology", labelKey: "biology" },
  { value: "English", labelKey: "english" },
  { value: "History", labelKey: "history" },
  { value: "Geography", labelKey: "geography" },
] as const

/**
 * 年级列表。
 */
export const GRADES: readonly GradeOption[] = [
  { value: "Grade 1", labelKey: "grade1" },
  { value: "Grade 2", labelKey: "grade2" },
  { value: "Grade 3", labelKey: "grade3" },
  { value: "Grade 4", labelKey: "grade4" },
  { value: "Grade 5", labelKey: "grade5" },
  { value: "Grade 6", labelKey: "grade6" },
  { value: "Grade 7", labelKey: "grade7" },
  { value: "Grade 8", labelKey: "grade8" },
  { value: "Grade 9", labelKey: "grade9" },
  { value: "Grade 10", labelKey: "grade10" },
  { value: "Grade 11", labelKey: "grade11" },
  { value: "Grade 12", labelKey: "grade12" },
] as const

/**
 * 学科主题色映射（用于教材卡片封面背景）。
 * key 必须与 SUBJECTS 中的 value 一致。
 */
export const SUBJECT_COLORS: Record<string, string> = {
  Chinese:
    "bg-rose-50 text-rose-700 border-rose-200/70 dark:bg-rose-950/50 dark:text-rose-200 dark:border-rose-900/60",
  Mathematics:
    "bg-blue-50 text-blue-700 border-blue-200/70 dark:bg-blue-950/50 dark:text-blue-200 dark:border-blue-900/60",
  Physics:
    "bg-purple-50 text-purple-700 border-purple-200/70 dark:bg-purple-950/50 dark:text-purple-200 dark:border-purple-900/60",
  Chemistry:
    "bg-teal-50 text-teal-700 border-teal-200/70 dark:bg-teal-950/50 dark:text-teal-200 dark:border-teal-900/60",
  English:
    "bg-orange-50 text-orange-700 border-orange-200/70 dark:bg-orange-950/50 dark:text-orange-200 dark:border-orange-900/60",
  History:
    "bg-amber-50 text-amber-700 border-amber-200/70 dark:bg-amber-950/50 dark:text-amber-200 dark:border-amber-900/60",
  Biology:
    "bg-emerald-50 text-emerald-700 border-emerald-200/70 dark:bg-emerald-950/50 dark:text-emerald-200 dark:border-emerald-900/60",
  Geography:
    "bg-sky-50 text-sky-700 border-sky-200/70 dark:bg-sky-950/50 dark:text-sky-200 dark:border-sky-900/60",
}

/** 默认学科色（未命中 SUBJECT_COLORS 时的兜底） */
export const DEFAULT_SUBJECT_COLOR =
  "bg-zinc-50 text-zinc-700 border-zinc-200/70 dark:bg-zinc-950/50 dark:text-zinc-200 dark:border-zinc-800/70"

/**
 * 根据学科 value 获取主题色 className。
 */
export function getSubjectColor(subject: string): string {
  return SUBJECT_COLORS[subject] ?? DEFAULT_SUBJECT_COLOR
}

/**
 * 根据学科 value 获取 i18n labelKey。
 * 未命中时返回 value 本身（作为兜底，调用方可直接用作显示文本）。
 */
export function getSubjectLabelKey(subject: string): string {
  return SUBJECTS.find((s) => s.value === subject)?.labelKey ?? subject
}

/**
 * 根据年级 value 获取 i18n labelKey。
 * 未命中时返回 value 本身。
 */
export function getGradeLabelKey(grade: string): string {
  return GRADES.find((g) => g.value === grade)?.labelKey ?? grade
}
