{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kpi-period-compare",
  "title": "KPI Period Compare",
  "description": "A KPI card whose period switch recomputes the value and the change against the previous period, announcing the new figures politely.",
  "registryDependencies": [
    "toggle-group",
    "card"
  ],
  "files": [
    {
      "path": "registry/patterns/kpi-period-compare/kpi-period-compare.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Card, CardContent } from \"@/components/ui/card\"\nimport { ToggleGroup, ToggleGroupItem } from \"@/components/ui/toggle-group\"\n\nexport interface KpiPeriodCompareProps {\n  label: string\n  /** Current and previous value for each period key. */\n  series: Record<string, [number, number]>\n  format?: (n: number) => string\n}\n\nconst plain = (n: number) => new Intl.NumberFormat(\"en-US\").format(n)\n\n/** A KPI card with a period switch that recomputes value and change. */\nexport function KpiPeriodCompare({\n  label,\n  series,\n  format = plain,\n}: KpiPeriodCompareProps) {\n  const keys = Object.keys(series)\n  const [period, setPeriod] = React.useState(keys[0])\n  const [now, before] = series[period]\n  const change = before === 0 ? 0 : ((now - before) / before) * 100\n  const up = change >= 0\n  return (\n    <Card>\n      <CardContent className=\"space-y-3 p-5\">\n        <div className=\"flex flex-wrap items-center justify-between gap-2\">\n          <p className=\"text-muted-foreground text-sm\">{label}</p>\n          <ToggleGroup\n            type=\"single\"\n            value={period}\n            onValueChange={(v) => v && setPeriod(v)}\n            aria-label={`${label} period`}\n            size=\"sm\"\n          >\n            {keys.map((k) => (\n              <ToggleGroupItem key={k} value={k}>\n                {k}\n              </ToggleGroupItem>\n            ))}\n          </ToggleGroup>\n        </div>\n        <div aria-live=\"polite\" aria-atomic=\"true\">\n          <p className=\"text-3xl font-semibold tabular-nums\">{format(now)}</p>\n          <p className=\"text-muted-foreground text-sm tabular-nums\">\n            {up ? \"Up\" : \"Down\"} {Math.abs(change).toFixed(1)}% from{\" \"}\n            {format(before)}\n          </p>\n        </div>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}