import type { SchoolYearRecord } from '../../api/schoolYears'

function statusBadgeVariant(status: string | null | undefined): string {
  switch (String(status ?? '').toLowerCase()) {
    case 'active':
      return 'success'
    case 'closed':
      return 'danger'
    case 'archived':
      return 'dark'
    case 'draft':
      return 'warning'
    default:
      return 'secondary'
  }
}

export function SchoolYearStatusBadge({
  status,
  className = '',
}: {
  status: SchoolYearRecord['status'] | null | undefined
  className?: string
}) {
  const label = String(status ?? 'unknown').trim() || 'unknown'
  return (
    <span className={`badge text-bg-${statusBadgeVariant(status)} ${className}`.trim()}>
      {label.toUpperCase()}
    </span>
  )
}
