{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "revenue-chart",
  "type": "registry:block",
  "title": "Revenue Lines",
  "description": "Dual-line revenue chart with keyboard-navigable points and a hover readout.",
  "dependencies": [
    "clsx@^2.1.1",
    "tailwind-merge@^3.6.0"
  ],
  "registryDependencies": [
    "https://www.paneloui.com/r/panelo-theme.json"
  ],
  "files": [
    {
      "path": "components/panelo-ui/blocks/charts/revenue-chart.tsx",
      "type": "registry:file",
      "target": "components/panelo-ui/blocks/charts/revenue-chart.tsx",
      "content": "'use client'\n\nimport { useId, useRef, useState } from 'react'\n\nimport { cn } from '@/components/panelo-ui/lib/utils'\n\nconst focusRing = 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'\n\n/* ------------------------------ Revenue chart ----------------------------- */\n\n/** Daily revenue, 19 Nov → 16 Dec (today), against the same days a period earlier. */\nconst REVENUE_START = Date.UTC(2024, 10, 19)\n\nconst revenueSeries: { current: number; previous: number }[] = [\n    { current: 17200, previous: 14800 },\n    { current: 16400, previous: 15600 },\n    { current: 14800, previous: 16100 },\n    { current: 13200, previous: 15400 },\n    { current: 14600, previous: 14200 },\n    { current: 16000, previous: 13900 },\n    { current: 15200, previous: 14600 },\n    { current: 16800, previous: 15800 },\n    { current: 18200, previous: 14200 },\n    { current: 17400, previous: 15100 },\n    { current: 19600, previous: 16400 },\n    { current: 21400, previous: 17200 },\n    { current: 20100, previous: 16800 },\n    { current: 22600, previous: 18100 },\n    { current: 24200, previous: 17500 },\n    { current: 23100, previous: 19300 },\n    { current: 25400, previous: 18600 },\n    { current: 27200, previous: 20600 },\n    { current: 26100, previous: 19800 },\n    { current: 28400, previous: 21400 },\n    { current: 30100, previous: 20900 },\n    { current: 28900, previous: 22600 },\n    { current: 27600, previous: 21600 },\n    { current: 29800, previous: 22900 },\n    { current: 31400, previous: 21800 },\n    { current: 30200, previous: 20400 },\n    { current: 31800, previous: 21200 },\n    { current: 30600, previous: 20000 },\n]\n\n/* -------------------------------------------------------------------------- */\n/*  Daily revenue: this period (line + area) against last period (dashed).     */\n/*  The <svg> stretches to its box, so HTML overlays (dots, tooltip, labels)   */\n/*  use the same fractions and stay pixel-aligned at any width. The crosshair  */\n/*  rests on today and follows the pointer; arrow keys, Home and End move it.  */\n/* -------------------------------------------------------------------------- */\n\nconst VW = 1000\nconst VH = 300\nconst MIN = 10_000\nconst MAX = 35_000\nconst TICKS = [35_000, 30_000, 25_000, 20_000, 15_000, 10_000]\nconst DAY = 86_400_000\n\n// UTC on both sides of hydration, so the server and the client print the same date.\nconst dayFormat = new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' })\nconst weekdayFormat = new Intl.DateTimeFormat('en-GB', { weekday: 'short', timeZone: 'UTC' })\n// Joined by hand: Node and Chrome disagree on the comma after the weekday, which breaks hydration.\nconst longFormat = { format: (d: Date) => `${weekdayFormat.format(d)} ${dayFormat.format(d)}` }\nconst money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })\n\nconst y = (v: number) => (1 - (v - MIN) / (MAX - MIN)) * VH\nconst top = (v: number) => `${(y(v) / VH) * 100}%`\n\nexport function RevenueChart({ days = revenueSeries.length, showPrevious = true, className }: { days?: number; showPrevious?: boolean; className?: string }) {\n    const gradient = `rev-${useId().replace(/[^\\w-]/g, '')}`\n    const plot = useRef<HTMLDivElement>(null)\n    const [hover, setHover] = useState<number | null>(null)\n\n    const first = revenueSeries.length - days\n    const series = revenueSeries.slice(first)\n    const last = series.length - 1\n    const clamp = (i: number) => Math.min(last, Math.max(0, i))\n    const index = clamp(hover ?? last)\n    const point = series[index]\n    const pct = (i: number) => (i / last) * 100\n    const dateOf = (i: number) => new Date(REVENUE_START + (first + i) * DAY)\n    const line = (key: 'current' | 'previous') => series.map((p, i) => `${i ? 'L' : 'M'}${((i / last) * VW).toFixed(1)} ${y(p[key]).toFixed(1)}`).join(' ')\n    const current = line('current')\n    const change = point.current / point.previous - 1\n\n    // Labels count back from today so it's always labelled; narrow plots drop every other one.\n    const step = days <= 7 ? 1 : days <= 14 ? 2 : 3\n    const ticks = Array.from({ length: Math.floor(last / step) + 1 }, (_, k) => last - k * step)\n\n    const track = (clientX: number) => {\n        const box = plot.current?.getBoundingClientRect()\n        if (box) setHover(clamp(Math.round(((clientX - box.left) / box.width) * last)))\n    }\n\n    const onKeyDown = (event: React.KeyboardEvent) => {\n        const next = ({ ArrowLeft: index - 1, ArrowRight: index + 1, Home: 0, End: last } as Record<string, number>)[event.key]\n        if (next === undefined) return\n        event.preventDefault()\n        setHover(clamp(next))\n    }\n\n    // The tooltip sits beside the crosshair, never on it, and flips sides past the middle.\n    const at = pct(index)\n    const tooltipLeft = at > 50 ? `max(0px, calc(${at}% - 11rem - 12px))` : `min(calc(100% - 11rem), calc(${at}% + 12px))`\n\n    return (\n        <div className={cn('@container select-none', className)}>\n            <div className=\"flex gap-3\">\n                <div\n                    ref={plot}\n                    role=\"slider\"\n                    tabIndex={0}\n                    aria-label=\"Daily revenue\"\n                    aria-orientation=\"horizontal\"\n                    aria-valuemin={0}\n                    aria-valuemax={last}\n                    aria-valuenow={index}\n                    aria-valuetext={`${longFormat.format(dateOf(index))}: ${money.format(point.current)}${showPrevious ? `, last period ${money.format(point.previous)}` : ''}`}\n                    onPointerDown={(event) => track(event.clientX)}\n                    onPointerMove={(event) => track(event.clientX)}\n                    onPointerLeave={() => setHover(null)}\n                    onBlur={() => setHover(null)}\n                    onKeyDown={onKeyDown}\n                    // pan-y: a vertical swipe still scrolls the page, a horizontal one scrubs.\n                    className={cn('relative h-56 min-w-0 flex-1 cursor-crosshair touch-pan-y rounded-sm @2xl:h-72', focusRing, 'focus-visible:ring-offset-4 focus-visible:ring-offset-card')}\n                >\n                    <svg viewBox={`0 0 ${VW} ${VH}`} preserveAspectRatio=\"none\" className=\"absolute inset-0 size-full overflow-visible\" aria-hidden=\"true\">\n                        <defs>\n                            <linearGradient id={gradient} className=\"text-chart-1\" x1=\"0\" y1=\"0\" x2=\"0\" y2={VH} gradientUnits=\"userSpaceOnUse\">\n                                <stop offset=\"0\" stopColor=\"currentColor\" stopOpacity=\"0.18\" />\n                                <stop offset=\"1\" stopColor=\"currentColor\" stopOpacity=\"0\" />\n                            </linearGradient>\n                        </defs>\n                        {TICKS.map((v) => (\n                            <line\n                                key={v}\n                                x1={0}\n                                x2={VW}\n                                y1={y(v)}\n                                y2={y(v)}\n                                className={v === MIN ? 'text-border' : 'text-border/70'}\n                                stroke=\"currentColor\"\n                                strokeDasharray={v === MIN ? undefined : '2 4'}\n                                vectorEffect=\"non-scaling-stroke\"\n                            />\n                        ))}\n                        <path d={`${current} L${VW} ${VH} L0 ${VH} Z`} fill={`url(#${gradient})`} />\n                        {showPrevious ? (\n                            <path d={line('previous')} className=\"text-muted-foreground/70\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeDasharray=\"4 4\" strokeLinejoin=\"round\" vectorEffect=\"non-scaling-stroke\" />\n                        ) : null}\n                        <path d={current} className=\"text-chart-1\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinejoin=\"round\" strokeLinecap=\"round\" vectorEffect=\"non-scaling-stroke\" />\n                        {hover !== null ? (\n                            <line x1={(at / 100) * VW} x2={(at / 100) * VW} y1={0} y2={VH} className=\"text-foreground/25\" stroke=\"currentColor\" vectorEffect=\"non-scaling-stroke\" />\n                        ) : null}\n                    </svg>\n\n                    {/* HTML dots stay round under the plot's non-uniform scale. At rest they mark today. */}\n                    {showPrevious ? (\n                        <span aria-hidden=\"true\" className=\"absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-muted-foreground bg-card\" style={{ left: `${at}%`, top: top(point.previous) }} />\n                    ) : null}\n                    <span aria-hidden=\"true\" className=\"absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-card bg-chart-1 shadow-sm\" style={{ left: `${at}%`, top: top(point.current) }} />\n\n                    {hover !== null ? (\n                        <div aria-hidden=\"true\" className=\"pointer-events-none absolute top-1 z-10 w-44 rounded-lg border border-border/70 bg-popover p-2.5 text-popover-foreground shadow-lg\" style={{ left: tooltipLeft }}>\n                            <p className=\"text-[11px] font-medium text-muted-foreground\">{longFormat.format(dateOf(index))}</p>\n                            <dl className=\"mt-1.5 flex flex-col gap-1 text-xs\">\n                                <div className=\"flex items-center justify-between gap-3\">\n                                    <dt className=\"flex items-center gap-1.5 text-muted-foreground\">\n                                        <span className=\"h-0.5 w-3 rounded-full bg-chart-1\" />\n                                        This period\n                                    </dt>\n                                    <dd className=\"font-semibold tabular-nums\">{money.format(point.current)}</dd>\n                                </div>\n                                {showPrevious ? (\n                                    <>\n                                        <div className=\"flex items-center justify-between gap-3\">\n                                            <dt className=\"flex items-center gap-1.5 text-muted-foreground\">\n                                                <span className=\"w-3 border-t-2 border-dashed border-muted-foreground/70\" />\n                                                Last period\n                                            </dt>\n                                            <dd className=\"tabular-nums text-muted-foreground\">{money.format(point.previous)}</dd>\n                                        </div>\n                                        <div className=\"flex items-center justify-between gap-3 border-t border-border/70 pt-1\">\n                                            <dt className=\"text-muted-foreground\">Change</dt>\n                                            <dd className={cn('font-medium tabular-nums', change >= 0 ? 'text-success' : 'text-destructive')}>\n                                                {change >= 0 ? '+' : '−'}\n                                                {Math.abs(change * 100).toFixed(1)}%\n                                            </dd>\n                                        </div>\n                                    </>\n                                ) : null}\n                            </dl>\n                        </div>\n                    ) : null}\n                </div>\n\n                <div aria-hidden=\"true\" className=\"relative w-10 shrink-0 text-[11px] tabular-nums text-muted-foreground\">\n                    {TICKS.map((v) => (\n                        <span key={v} className=\"absolute start-0 -translate-y-1/2\" style={{ top: top(v) }}>\n                            ${v / 1000}k\n                        </span>\n                    ))}\n                </div>\n            </div>\n\n            {/* mr-13 = gutter (w-10) + gap-3, so labels share the plot's width. Edge labels hug the edges instead of overflowing. */}\n            <div aria-hidden=\"true\" className=\"relative mr-13 mt-2.5 h-4 text-[11px] text-muted-foreground\">\n                {ticks.map((i, k) => (\n                    <span\n                        key={i}\n                        className={cn('absolute whitespace-nowrap', i === last ? '-translate-x-full font-medium text-foreground' : i === 0 ? '' : '-translate-x-1/2', k % 2 === 1 && 'hidden @xl:block')}\n                        style={{ left: `${pct(i)}%` }}\n                    >\n                        {i === last ? 'Today' : dayFormat.format(dateOf(i))}\n                    </span>\n                ))}\n            </div>\n        </div>\n    )\n}\n"
    },
    {
      "path": "components/panelo-ui/lib/utils.ts",
      "type": "registry:file",
      "target": "components/panelo-ui/lib/utils.ts",
      "content": "import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n\nexport const stringToNumber = (title: string): number => {\n    const titles = [\"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\", \"twenty\"];\n    return titles.indexOf(title.toLowerCase()) + 1;\n};"
    }
  ]
}