/** Enrollment status badges aligned with legacy PHP enroll_withdraw views. */

export function normStatus(v: string | undefined | null): string {
  return String(v ?? '')
    .trim()
    .toLowerCase()
    .replace(/[_\s]+/g, ' ')
}

type DeniedVariant = 'light' | 'dark'

export function EnrollmentStatusBadge({
  status,
  deniedVariant = 'dark',
}: {
  status?: string | null
  deniedVariant?: DeniedVariant
}) {
  const s = normStatus(status || 'not enrolled')

  if (s === 'admission under review')
    return <span className="badge bg-primary">admission under review</span>
  if (s === 'payment pending')
    return <span className="badge bg-warning text-dark">payment pending</span>
  if (s === 'enrolled') return <span className="badge bg-success">enrolled</span>
  if (s === 'withdraw under review')
    return <span className="badge bg-warning text-dark">withdraw under review</span>
  if (s === 'refund pending')
    return <span className="badge bg-info text-dark">refund pending</span>
  if (s === 'withdrawn') return <span className="badge bg-danger">withdrawn</span>
  if (s === 'waitlist') return <span className="badge bg-secondary">waitlist</span>
  if (s === 'denied')
    return deniedVariant === 'light' ? (
      <span className="badge bg-light">denied</span>
    ) : (
      <span className="badge bg-dark">denied</span>
    )
  if (s === 'not enrolled')
    return <span className="badge bg-danger text-dark">not enrolled</span>
  return <span className="badge bg-light text-dark">unknown</span>
}

export function NewStudentBadge({ value }: { value?: string | null }) {
  const v = String(value ?? '').trim()
  if (v === 'Yes') return <span className="badge bg-warning text-dark">Yes</span>
  if (v === 'No') return <span className="badge bg-success">No</span>
  return <span className="badge bg-light text-dark">Unknown</span>
}

export function RemovedPriorYearBadge({ value }: { value?: string | null }) {
  const v = String(value ?? '').trim()
  if (v === 'Yes') return <span className="badge bg-danger text-light">Yes</span>
  return <span className="badge bg-secondary">No</span>
}
