import { cva, type VariantProps } from 'class-variance-authority'

export const badgeVariants = cva(
  'inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors',
  {
    variants: {
      variant: {
        running: 'bg-emerald-500/15 text-emerald-400 border border-emerald-500/30',
        pending: 'bg-amber-500/15 text-amber-400 border border-amber-500/30',
        waking: 'bg-amber-500/15 text-amber-400 border border-amber-500/30',
        success: 'bg-emerald-500/15 text-emerald-400 border border-emerald-500/30',
        error: 'bg-rose-500/15 text-rose-400 border border-rose-500/30',
        info: 'bg-sky-500/15 text-sky-400 border border-sky-500/30',
        neutral: 'bg-zinc-500/15 text-zinc-400 border border-zinc-500/30',
      },
    },
    defaultVariants: {
      variant: 'neutral',
    },
  }
)

export type BadgeVariant = VariantProps<typeof badgeVariants>['variant']

const STATUS_TO_VARIANT: Record<string, BadgeVariant> = {
  running: 'running',
  pending: 'pending',
  waking: 'waking',
  success: 'success',
  error: 'error',
  failed: 'error',
  completed: 'success',
  cancelled: 'neutral',
  info: 'info',
  unknown: 'neutral',
}

export function statusVariant(status: string): BadgeVariant {
  return STATUS_TO_VARIANT[status.toLowerCase()] ?? 'neutral'
}

export function statusLabel(status: string): string {
  const labels: Record<string, string> = {
    running: 'Running',
    pending: 'Pending',
    waking: 'Waking',
    success: 'Success',
    error: 'Error',
    failed: 'Failed',
    completed: 'Completed',
    cancelled: 'Cancelled',
    info: 'Info',
    unknown: 'Unknown',
  }
  return labels[status.toLowerCase()] ?? status
}
