import { Badge } from "@/components/ui/badge";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";

export type AiRiskLevel = "At Risk" | "Monitor" | "On Track";

interface Props {
  riskLevel?: AiRiskLevel;
  reasons?: string[];
}

export default function AiRiskBadge({ riskLevel, reasons }: Props) {
  if (!riskLevel) {
    return (
      <Tooltip>
        <TooltipTrigger asChild>
          <Badge variant="outline" className="text-xs cursor-help">
            Unknown
          </Badge>
        </TooltipTrigger>
        <TooltipContent>
          <p className="text-xs max-w-[200px]">Risk data not available from profile.</p>
        </TooltipContent>
      </Tooltip>
    );
  }

  const variant: "destructive" | "secondary" | "default" =
    riskLevel === "At Risk" ? "destructive" : riskLevel === "Monitor" ? "secondary" : "default";

  const tooltipText =
    reasons?.filter(Boolean).length ? reasons!.filter(Boolean).join(" · ") : "No additional details provided.";

  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <Badge variant={variant} className="text-xs cursor-help">
          {riskLevel}
        </Badge>
      </TooltipTrigger>
      <TooltipContent>
        <p className="text-xs max-w-[200px]">{tooltipText}</p>
      </TooltipContent>
    </Tooltip>
  );
}
