{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stat-group-05",
  "description": "Four metrics, each with a bar for this period over a bar for the one before.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/stat-group.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/stat-group/stat-group-05.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n  useBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  Stat,\n  StatChange,\n  StatGroup,\n  StatLabel,\n  type StatMetric,\n  StatValue,\n  formatStatValue,\n  getStatPlaceholders,\n} from '@/registry/components/dashboardblocks/stat-group'\nimport {\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface StatGroup5Props extends BlockStateProps {\n  /** Follows each previous value, such as `the previous 30 days`. */\n  comparison: string\n  /** @default 'This period' */\n  currentLabel?: string\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  metrics?: StatMetric[]\n  /** How many metrics to sketch while loading. @default 4 */\n  placeholders?: number\n  title: string\n}\n\nconst exampleProps: StatGroup5Props = {\n  comparison: 'the 30 days before',\n  currentLabel: 'Last 30 days',\n  description:\n    'The last 30 days against the 30 before. Revenue grew while trial conversion slipped.',\n  metrics: [\n    {\n      formatter: (value) => formatCurrency(value),\n      key: 'revenue',\n      label: 'Revenue',\n      previous: 42_890,\n      value: 48_210,\n    },\n    { key: 'signups', label: 'New customers', previous: 318, value: 342 },\n    {\n      changeType: 'points',\n      formatter: (value) => formatPercent(value / 100),\n      key: 'conversion',\n      label: 'Trial conversion',\n      previous: 19.8,\n      value: 18.6,\n    },\n    {\n      formatter: (value) => `${formatNumber(value)} h`,\n      goodDirection: 'down',\n      key: 'response',\n      label: 'First response time',\n      previous: 5.6,\n      value: 4.2,\n    },\n  ],\n  title: 'Overview',\n}\n\nfunction PeriodBars({ metric }: { metric: StatMetric }) {\n  const loading = useBlockState() === 'loading'\n  if (loading) {\n    return (\n      <dd\n        aria-hidden\n        className='mt-3 flex animate-pulse flex-col gap-1 motion-reduce:animate-none'\n      >\n        <span className='bg-muted h-1.5 rounded-full' />\n        <span className='bg-muted h-1.5 w-3/4 rounded-full' />\n      </dd>\n    )\n  }\n  if (metric.previous === undefined) return null\n  const max = Math.max(Math.abs(metric.value), Math.abs(metric.previous)) || 1\n\n  return (\n    <dd aria-hidden className='mt-3 flex flex-col gap-1'>\n      <span\n        className='bg-chart-2 h-1.5 rounded-full'\n        style={{ width: `${(Math.abs(metric.value) / max) * 100}%` }}\n      />\n      <span\n        className='bg-muted-foreground/30 h-1.5 rounded-full'\n        style={{ width: `${(Math.abs(metric.previous) / max) * 100}%` }}\n      />\n    </dd>\n  )\n}\n\nconst StatGroup5 = (props: StatGroup5Props) => {\n  const {\n    comparison,\n    currentLabel = 'This period',\n    description,\n    metrics = [],\n    placeholders = 4,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, metrics)\n  const shown = status === 'loading' ? getStatPlaceholders(placeholders) : metrics\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <StatGroup className='grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-4'>\n              {shown.map((metric) => (\n                <Stat key={metric.key}>\n                  <StatLabel>{metric.label}</StatLabel>\n                  <StatValue className='text-3xl @4xl:text-4xl'>\n                    {formatStatValue(metric)}\n                  </StatValue>\n                  <StatChange comparison={comparison} metric={metric} />\n                  <PeriodBars metric={metric} />\n                </Stat>\n              ))}\n            </StatGroup>\n            {state !== 'error' && state !== 'empty' && (\n              <p\n                aria-hidden\n                className='text-muted-foreground flex items-center gap-4 text-xs'\n              >\n                <span className='flex items-center gap-1.5'>\n                  <span className='bg-chart-2 h-1.5 w-3 rounded-full' />\n                  {currentLabel}\n                </span>\n                <span className='flex items-center gap-1.5'>\n                  <span className='bg-muted-foreground/30 h-1.5 w-3 rounded-full' />\n                  <span className='first-letter:uppercase'>{comparison}</span>\n                </span>\n              </p>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { StatGroup5, exampleProps as statGroup5ExampleProps, type StatGroup5Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/stat-group/stat-group-05.tsx"
    }
  ],
  "meta": {
    "shows": "Four metrics, each with a bar for this period over a bar for the one before.",
    "size": "full",
    "usedWith": [
      "chart-panel-03",
      "kpi-01",
      "breakdown-01"
    ],
    "component": "StatGroup5",
    "props": "{ comparison: string; currentLabel?: string; description: string; metrics?: { changeType?: \"percent\" | \"points\" | \"count\"; detail?: ReactNode; formatter?: (value: number) => string; goodDirection?: \"up\" | \"down\"; key: string; label: string; previous?: number; tone?: \"warning\" | \"bad\"; value: number }[]; placeholders?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
