import { Tag, Tooltip } from 'antd';
import type { RiskLevel } from '../../api/copilot';
import { useCopilotRisk } from './useCopilotRisk';

const levelConfig: Record<RiskLevel, { color: string; label: string }> = {
  low: { color: 'green', label: '低风险' },
  medium: { color: 'orange', label: '中风险' },
  high: { color: 'red', label: '高风险' },
  critical: { color: '#cf1322', label: '危急' },
};

interface CopilotBadgeProps {
  patientId: string | undefined;
}

export function CopilotBadge({ patientId }: CopilotBadgeProps) {
  const { data, loading } = useCopilotRisk(patientId);

  if (!data || loading) return null;

  const config = levelConfig[data.level as RiskLevel] ?? levelConfig.low;

  return (
    <Tooltip title={`Copilot 风险评分: ${data.score}/10 — ${config.label}`}>
      <Tag color={config.color}>{config.label} {data.score}/10</Tag>
    </Tooltip>
  );
}
