import type { LetterGrade } from '../../lib/judgmentGrade'

export function gradeDataAttr(grade: string): 'S' | 'A' | 'B' | 'C' | 'D' | 'F' | 'other' {
  const g = grade.trim().toUpperCase().slice(0, 1)
  if (g === 'S' || g === 'A' || g === 'B' || g === 'C' || g === 'D' || g === 'F') {
    return g
  }
  return 'other'
}

export function letterFromOverride(grade: string): LetterGrade {
  const g = grade.trim().toUpperCase().slice(0, 1)
  if (g === 'S' || g === 'A' || g === 'B' || g === 'C' || g === 'D' || g === 'F') {
    return g
  }
  return 'F'
}

export function dominantJudgment(
  perfect: number,
  good: number,
  miss: number,
): 'perfect' | 'good' | 'miss' | null {
  const max = Math.max(perfect, good, miss)
  if (max === 0) return null
  if (perfect === max) return 'perfect'
  if (good === max) return 'good'
  return 'miss'
}
