import { Badge, type BadgeProps } from '@/components/ui/badge'
import { cn } from '@/lib/utils'

const STATUS_STYLES: Record<string, { variant: BadgeProps['variant']; className?: string }> = {
  // Round statuses
  DRAFT: { variant: 'secondary' },
  ACTIVE: { variant: 'default', className: 'bg-blue-500/10 text-blue-700 border-blue-200 dark:text-blue-400' },
  EVALUATION: { variant: 'default', className: 'bg-violet-500/10 text-violet-700 border-violet-200 dark:text-violet-400' },
  CLOSED: { variant: 'secondary', className: 'bg-slate-500/10 text-slate-600 border-slate-200' },

  // Project statuses
  SUBMITTED: { variant: 'secondary', className: 'bg-indigo-500/10 text-indigo-700 border-indigo-200 dark:text-indigo-400' },
  ELIGIBLE: { variant: 'default', className: 'bg-emerald-500/10 text-emerald-700 border-emerald-200 dark:text-emerald-400' },
  ASSIGNED: { variant: 'default', className: 'bg-violet-500/10 text-violet-700 border-violet-200 dark:text-violet-400' },
  UNDER_REVIEW: { variant: 'default', className: 'bg-blue-500/10 text-blue-700 border-blue-200 dark:text-blue-400' },
  SHORTLISTED: { variant: 'default', className: 'bg-amber-500/10 text-amber-700 border-amber-200 dark:text-amber-400' },
  SEMIFINALIST: { variant: 'default', className: 'bg-amber-500/10 text-amber-700 border-amber-200 dark:text-amber-400' },
  FINALIST: { variant: 'default', className: 'bg-orange-500/10 text-orange-700 border-orange-200 dark:text-orange-400' },
  WINNER: { variant: 'default', className: 'bg-yellow-500/10 text-yellow-800 border-yellow-300 dark:text-yellow-400' },
  REJECTED: { variant: 'destructive' },
  WITHDRAWN: { variant: 'secondary' },

  // Evaluation statuses
  IN_PROGRESS: { variant: 'default', className: 'bg-blue-500/10 text-blue-700 border-blue-200 dark:text-blue-400' },
  COMPLETED: { variant: 'default', className: 'bg-emerald-500/10 text-emerald-700 border-emerald-200 dark:text-emerald-400' },

  // User statuses
  NONE: { variant: 'secondary', className: 'bg-slate-500/10 text-slate-500 border-slate-200 dark:text-slate-400' },
  INVITED: { variant: 'secondary', className: 'bg-sky-500/10 text-sky-700 border-sky-200 dark:text-sky-400' },
  INACTIVE: { variant: 'secondary' },
  SUSPENDED: { variant: 'destructive' },
}

type StatusBadgeProps = {
  status: string
  className?: string
  size?: 'sm' | 'default'
}

export function StatusBadge({ status, className, size = 'default' }: StatusBadgeProps) {
  const style = STATUS_STYLES[status] || { variant: 'secondary' as const }
  const label = status === 'NONE' ? 'NOT INVITED' : status.replace(/_/g, ' ')

  return (
    <Badge
      variant={style.variant}
      className={cn(
        style.className,
        size === 'sm' && 'text-[10px] px-1.5 py-0',
        className,
      )}
    >
      {label}
    </Badge>
  )
}
