export interface AcademicTermLike {
  id: string
  name: string
  isCurrent?: boolean
  isArchived?: boolean
  isEnabled?: boolean
  hasPublishedTimetable?: boolean
}

export function academicTermLabel(term: AcademicTermLike): string {
  if (term.isCurrent) return `${term.name} · 当前`
  if (term.isArchived) return `${term.name} · 已归档`
  return `${term.name} · 历史`
}

export function academicTermOptionClass(term: AcademicTermLike): string {
  if (term.isCurrent) return 'academic-term-option academic-term-option--current'
  if (term.isArchived) return 'academic-term-option academic-term-option--archived'
  return 'academic-term-option academic-term-option--historical'
}

export function defaultAcademicTermId(
  terms: AcademicTermLike[],
  requirePublishedTimetable = false,
): string | undefined {
  const usable = requirePublishedTimetable
    ? terms.filter((term) => term.hasPublishedTimetable)
    : terms
  return usable.find((term) => term.isCurrent)?.id
    ?? usable.find((term) => !term.isArchived)?.id
    ?? usable[0]?.id
}

export function academicTermRowClass(term: {
  isCurrent?: boolean
  isArchived?: boolean
}): string {
  if (term.isCurrent) return 'academic-term-row academic-term-row--current'
  if (term.isArchived) return 'academic-term-row academic-term-row--archived'
  return 'academic-term-row academic-term-row--historical'
}
