import type { SchoolLevel } from '../types'

export type { SchoolLevel }

export const SCHOOL_LEVEL_LABELS: Record<SchoolLevel, string> = {
  junior_high: '初中',
  senior_high: '高中',
}

export const GRADE_OPTIONS: Record<SchoolLevel, { value: string; label: string }[]> = {
  junior_high: [
    { value: '初一', label: '初一（七年级）' },
    { value: '初二', label: '初二（八年级）' },
    { value: '初三', label: '初三（九年级）' },
  ],
  senior_high: [
    { value: '高一', label: '高一（十年级）' },
    { value: '高二', label: '高二（十一年级）' },
    { value: '高三', label: '高三（十二年级）' },
  ],
}

export function formatStudentMeta(
  student: {
    school_level: SchoolLevel
    school_name?: string | null
    grade?: string | null
    class_name?: string | null
  },
  options?: { includeLevel?: boolean },
): string {
  const parts: string[] = []
  if (student.school_name?.trim()) parts.push(student.school_name.trim())
  if (options?.includeLevel !== false) parts.push(SCHOOL_LEVEL_LABELS[student.school_level])
  if (student.grade) parts.push(student.grade)
  if (student.class_name) {
    const cls = student.class_name.trim()
    parts.push(cls.endsWith('班') ? cls : `${cls}班`)
  }
  return parts.length ? parts.join(' · ') : '未设置年级信息'
}

export function formatStudentSubtitle(student: {
  school_level: SchoolLevel
  school_name?: string | null
  grade?: string | null
  class_name?: string | null
}): string {
  return formatStudentMeta(student, { includeLevel: false })
}
