"use client"; import { Bell } from "lucide-react"; import { useState } from "react"; import { CHART_COLORS, SEVERITY_ORDER } from "./shared/constants"; import { getSeverityColorByName } from "./shared/utils"; import { BarDataPoint } from "./types"; interface HorizontalBarChartProps { data: BarDataPoint[]; height?: number; title?: string; } export function HorizontalBarChart({ data, title }: HorizontalBarChartProps) { const [hoveredIndex, setHoveredIndex] = useState(null); const sortedData = [...data].sort((a, b) => { const orderA = SEVERITY_ORDER[a.name as keyof typeof SEVERITY_ORDER] ?? 999; const orderB = SEVERITY_ORDER[b.name as keyof typeof SEVERITY_ORDER] ?? 999; return orderA - orderB; }); return (
{title && (

{title}

)}
{sortedData.map((item, index) => { const isHovered = hoveredIndex === index; const isFaded = hoveredIndex !== null && !isHovered; const barColor = item.color || getSeverityColorByName(item.name) || CHART_COLORS.defaultColor; return (
setHoveredIndex(index)} onMouseLeave={() => setHoveredIndex(null)} >
{item.name}
d.value))) * 100}%`, backgroundColor: barColor, opacity: isFaded ? 0.5 : 1, }} /> {isHovered && (
{item.value.toLocaleString()} {item.name} Risk
{item.newFindings !== undefined && (
{item.newFindings} New Findings
)} {item.change !== undefined && (

{item.change > 0 ? "+" : ""} {item.change}% {" "} Since Last Scan

)}
)}
{item.percentage}% {item.value.toLocaleString()}
); })}
); }