import { Badge } from '@/Components/ui/badge';
import { cn } from '@/lib/utils';

interface HealthScoreBadgeProps {
  score: number | null;
  className?: string;
}

type HealthStatus = 'healthy' | 'needs-attention' | 'at-risk' | 'critical' | 'unknown';

const healthStatusConfig: Record<
  HealthStatus,
  {
    label: string;
    variant:
      | 'success'
      | 'default'
      | 'secondary'
      | 'destructive'
      | 'outline'
      | 'critical'
      | 'high'
      | 'medium'
      | 'low';
  }
> = {
  healthy: { label: 'Healthy', variant: 'success' },
  'needs-attention': { label: 'Needs Attention', variant: 'medium' },
  'at-risk': { label: 'At Risk', variant: 'high' },
  critical: { label: 'Critical', variant: 'critical' },
  unknown: { label: 'N/A', variant: 'outline' },
};

function getHealthStatus(score: number | null): HealthStatus {
  if (score === null || score === undefined) {
    return 'unknown';
  }

  if (score >= 80) {
    return 'healthy';
  } else if (score >= 60) {
    return 'needs-attention';
  } else if (score >= 40) {
    return 'at-risk';
  } else {
    return 'critical';
  }
}

export default function HealthScoreBadge({ score, className }: HealthScoreBadgeProps) {
  const status = getHealthStatus(score);
  const config = healthStatusConfig[status];

  return (
    <Badge variant={config.variant} className={cn(className)}>
      {config.label}
    </Badge>
  );
}
