{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "insight-cards",
  "title": "Insight cards",
  "description": "Paged agent insights with responsive, pointer- and keyboard-scrubbable SVG charts.",
  "registryDependencies": [
    "https://beadkit.dev/r/ai-core.json"
  ],
  "files": [
    {
      "path": "components/ai/InsightCards.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport styles from \"./ai-state.module.css\";\n\nexport interface InsightPoint { label?: string; value: number }\nexport interface InsightSeries { id: string; label: string; data: readonly InsightPoint[]; color?: string; formatValue?: (value: number) => string }\nexport interface Insight { id: string; title: string; description?: string; series: readonly InsightSeries[]; ctaLabel?: string; onCta?: () => void }\nexport interface InsightCardsProps { insights: readonly Insight[]; initialPage?: number; className?: string }\n\nfunction Chart({ series }: { series: readonly InsightSeries[] }) {\n  const [index, setIndex] = useState<number | null>(null);\n  const count = Math.max(0, ...series.map((item) => item.data.length));\n  const values = series.flatMap((item) => item.data.map((point) => point.value));\n  const min = Math.min(...values, 0); const max = Math.max(...values, 1); const range = max - min || 1;\n  const x = (i: number) => count < 2 ? 50 : (i / (count - 1)) * 100;\n  const y = (value: number) => 94 - ((value - min) / range) * 78;\n  const selected = index === null ? null : Math.min(index, count - 1);\n  function move(next: number) { setIndex(Math.max(0, Math.min(count - 1, next))); }\n  if (count === 0) {\n    return <div className=\"bg-muted text-muted-foreground mt-3 rounded-lg border p-8 text-center text-xs\">No chart data</div>;\n  }\n  return (\n    <div className=\"bg-muted relative mt-3 overflow-hidden rounded-lg border\" role=\"group\" aria-label=\"Interactive insight chart\">\n      <svg viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" className=\"block h-36 w-full\" role=\"img\" aria-label=\"Insight trend chart\">\n        {[20, 45, 70].map((line) => <line key={line} x1=\"0\" x2=\"100\" y1={line} y2={line} stroke=\"currentColor\" className=\"text-border\" strokeWidth=\"0.35\" />)}\n        {series.map((item) => <polyline key={item.id} fill=\"none\" stroke={item.color ?? \"var(--accent)\"} strokeWidth=\"1.8\" vectorEffect=\"non-scaling-stroke\" points={item.data.map((point, i) => `${x(i)},${y(point.value)}`).join(\" \")} />)}\n        {selected !== null ? <line x1={x(selected)} x2={x(selected)} y1=\"8\" y2=\"96\" stroke=\"currentColor\" className=\"text-muted-foreground\" strokeWidth=\"0.5\" strokeDasharray=\"2 2\" vectorEffect=\"non-scaling-stroke\" /> : null}\n      </svg>\n      <div tabIndex={0} role=\"slider\" aria-label=\"Scrub chart date\" aria-valuemin={0} aria-valuemax={Math.max(0, count - 1)} aria-valuenow={selected ?? Math.max(0, count - 1)} aria-valuetext={selected === null ? \"No point selected\" : series[0]?.data[selected]?.label ?? `Point ${selected + 1}`} onPointerMove={(event) => { const rect = event.currentTarget.getBoundingClientRect(); move(Math.round(((event.clientX - rect.left) / rect.width) * (count - 1))); }} onPointerDown={(event) => { const rect = event.currentTarget.getBoundingClientRect(); move(Math.round(((event.clientX - rect.left) / rect.width) * (count - 1))); }} onPointerLeave={() => setIndex(null)} onKeyDown={(event) => { if (event.key === \"ArrowLeft\") { event.preventDefault(); move((selected ?? count - 1) - 1); } if (event.key === \"ArrowRight\") { event.preventDefault(); move((selected ?? -1) + 1); } }} className=\"absolute inset-0 cursor-crosshair focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring\" />\n      {selected !== null ? <div className=\"bg-card pointer-events-none absolute top-2 min-w-32 -translate-x-1/2 rounded-md border px-2 py-1 text-[11px] shadow-sm\" style={{ left: `${Math.max(12, Math.min(88, x(selected)))}%` }}><div className=\"text-muted-foreground mb-0.5\">{series[0]?.data[selected]?.label ?? `Point ${selected + 1}`}</div>{series.map((item) => <div key={item.id} className=\"flex items-center justify-between gap-3\"><span className=\"flex items-center gap-1\"><i aria-hidden=\"true\" className=\"size-1.5 rounded-full\" style={{ background: item.color ?? \"var(--foreground)\" }} />{item.label}</span><strong>{item.formatValue?.(item.data[selected]?.value ?? 0) ?? (item.data[selected]?.value ?? 0)}</strong></div>)}</div> : null}\n    </div>\n  );\n}\n\nexport function InsightCards({ insights, initialPage = 0, className = \"\" }: InsightCardsProps) {\n  const [page, setPage] = useState(() => Math.max(0, Math.min(initialPage, Math.max(0, insights.length - 1))));\n  useEffect(() => setPage((current) => Math.min(current, Math.max(0, insights.length - 1))), [insights.length]);\n  if (insights.length === 0) return null;\n  const insight = insights[page] ?? insights[0];\n  const move = (amount: number) => setPage((current) => (current + amount + insights.length) % insights.length);\n  return <section data-ai-state=\"insight-cards\" aria-label=\"Insights\" className={`${styles.fadeIn} w-full max-w-md ${className}`}><header className=\"flex items-center justify-between\"><span className=\"text-foreground flex items-baseline gap-1.5 text-[13px] font-semibold\">Insights <span className=\"text-muted-foreground font-normal tabular-nums\">{page + 1}/{insights.length}</span></span><span className=\"flex gap-1\"><button type=\"button\" aria-label=\"Previous insight\" disabled={insights.length < 2} onClick={() => move(-1)} className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex size-8 items-center justify-center rounded-md transition-colors duration-150 disabled:opacity-40 motion-reduce:transition-none\">‹</button><button type=\"button\" aria-label=\"Next insight\" disabled={insights.length < 2} onClick={() => move(1)} className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex size-8 items-center justify-center rounded-md transition-colors duration-150 disabled:opacity-40 motion-reduce:transition-none\">›</button></span></header><div key={insight.id} className={styles.fadeIn}>{insight.description ? <p className=\"text-muted-foreground mt-1 text-sm leading-relaxed\">{insight.description}</p> : null}<div className=\"bg-card mt-2 rounded-xl border p-3 shadow-sm\"><h3 className=\"text-foreground text-sm font-semibold\">{insight.title}</h3><div className=\"mt-2 flex flex-wrap gap-x-4 gap-y-1\">{insight.series.map((item) => <span key={item.id} className=\"text-muted-foreground flex items-center gap-1.5 text-xs\"><i aria-hidden=\"true\" className=\"size-2 rounded-full\" style={{ background: item.color ?? \"var(--foreground)\" }} />{item.label}</span>)}</div><Chart series={insight.series} /></div>{insight.ctaLabel && insight.onCta ? <button type=\"button\" onClick={insight.onCta} className=\"bg-card text-foreground hover:bg-muted mt-2 min-h-9 rounded-full border px-3 text-xs transition-colors duration-150 motion-reduce:transition-none\">{insight.ctaLabel}</button> : null}</div></section>;\n}\n",
      "type": "registry:component",
      "target": "@components/ai/InsightCards.tsx"
    }
  ],
  "type": "registry:component"
}
