import { ORIGIN_LABELS, OriginClass } from '../api'

interface Props {
  origin: OriginClass | string | null | undefined
  withLabel?: boolean
}

function isOriginClass(v: unknown): v is OriginClass {
  return v === 'A' || v === 'B' || v === 'C' || v === 'D' || v === 'E'
}

export default function OriginBadge({ origin, withLabel = false }: Props) {
  if (!isOriginClass(origin)) return null
  const label = ORIGIN_LABELS[origin]
  return (
    <span className={`origin-badge origin-${origin}`} title={label}>
      <span className="origin-badge-letter">{origin}</span>
      {withLabel && <span className="origin-badge-label">{label}</span>}
    </span>
  )
}
