{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "states-02",
  "description": "A chart that stays in place at reduced opacity while it refreshes, with an updating indicator in the header.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/states/states-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockBusy,\n  BlockBusyIndicator,\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStatus,\n  type LoadStatus,\n  useBlockData,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  useChartId,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCompact, formatCurrency } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  AreaChart,\n  CartesianGrid,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface DailyPoint {\n  label: string\n  value: number\n}\n\ninterface States2Props {\n  description: string\n  load: () => Promise<DailyPoint[]>\n  title: string\n}\n\nlet exampleRequests = 0\n\nconst exampleProps: States2Props = {\n  description: 'Revenue each day in September, against the daily average.',\n  load: () => {\n    const shift = exampleRequests++ * 0.9\n    return new Promise((resolve) =>\n      setTimeout(\n        () =>\n          resolve(\n            Array.from({ length: 30 }, (_, day) => ({\n              label: `Sep ${day + 1}`,\n              value: Math.round(\n                1_450 +\n                  day * 14 +\n                  Math.sin(day / 2.4 + shift) * 190 -\n                  (day % 7 > 4 ? 260 : 0),\n              ),\n            })),\n          ),\n        1_200,\n      ),\n    )\n  },\n  title: 'Revenue',\n}\n\nconst SERIES_COLOR = 'var(--color-chart-2)'\nconst currency = (value: number) => formatCurrency(value)\n\nfunction toBlockStatus(status: LoadStatus): BlockStatus | undefined {\n  if (status === 'idle' || status === 'loading') return 'loading'\n  if (status === 'error') return 'error'\n  return undefined\n}\n\nconst States2 = (props: States2Props) => {\n  const { description, load, title } = props\n  const { data, reload, status: loadStatus } = useBlockData(load)\n  const status = toBlockStatus(loadStatus)\n  const refreshing = loadStatus === 'refreshing'\n  const gradient = useChartId()\n  const total = data?.reduce((sum, point) => sum + point.value, 0) ?? 0\n  const average = data?.length ? total / data.length : 0\n  const best = data?.length\n    ? data.reduce((top, point) => (point.value > top.value ? point : top))\n    : undefined\n\n  return (\n    <BlockStateProvider state={getBlockState(status, data)}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex items-start justify-between gap-3'>\n              <div className='flex min-w-0 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              </div>\n              <div className='flex shrink-0 items-center gap-3'>\n                {refreshing && <BlockBusyIndicator />}\n                <Button\n                  variant='outline'\n                  size='sm'\n                  disabled={status === 'loading' || refreshing}\n                  onClick={() => void reload()}\n                >\n                  <IconPlaceholder\n                    lucide='RefreshCwIcon'\n                    tabler='IconRefresh'\n                    hugeicons='RefreshIcon'\n                    phosphor='ArrowClockwiseIcon'\n                    remixicon='RiRefreshLine'\n                  />\n                  Refresh\n                </Button>\n              </div>\n            </header>\n            {status || !data?.length ? (\n              <div className='flex flex-col gap-4 border-t pt-4'>\n                <div className='flex flex-col gap-1'>\n                  <KPIValue />\n                  {status === 'loading' && <BlockStateText className='text-sm' />}\n                </div>\n                <ChartPlaceholder height={224} />\n              </div>\n            ) : (\n              <BlockBusy\n                busy={refreshing}\n                label={`Updating ${title.toLowerCase()}`}\n                className='flex flex-col gap-4 border-t pt-4'\n              >\n                <div className='flex flex-col gap-1'>\n                  <p className='text-4xl font-light tracking-tight tabular-nums'>\n                    {currency(total)}\n                  </p>\n                  {best && (\n                    <p className='text-muted-foreground text-sm'>\n                      {best.label} was the best day, at {currency(best.value)}.\n                    </p>\n                  )}\n                </div>\n                <ChartPanelFigure className='h-56'>\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <AreaChart\n                      aria-label={`${title} chart`}\n                      data={data}\n                      margin={{ top: 8, right: 8, bottom: 0, left: 0 }}\n                    >\n                      <defs>\n                        <linearGradient id={gradient} x1='0' y1='0' x2='0' y2='1'>\n                          <stop offset='0%' stopColor={SERIES_COLOR} stopOpacity={0.3} />\n                          <stop offset='100%' stopColor={SERIES_COLOR} stopOpacity={0} />\n                        </linearGradient>\n                      </defs>\n                      <CartesianGrid {...chartGridProps} />\n                      <XAxis\n                        {...chartAxisProps}\n                        dataKey='label'\n                        interval='preserveStartEnd'\n                        minTickGap={40}\n                      />\n                      <YAxis\n                        {...chartAxisProps}\n                        tickFormatter={(value: number) => formatCompact(value)}\n                        width={chartValueAxisWidth}\n                      />\n                      <Tooltip\n                        content={(tooltipProps) => (\n                          <ChartTooltipContent\n                            {...tooltipProps}\n                            valueFormatter={currency}\n                          />\n                        )}\n                        cursor={chartLineCursor}\n                      />\n                      <ReferenceLine\n                        {...chartReferenceProps}\n                        y={average}\n                        label={{\n                          ...chartReferenceLabel,\n                          value: `avg ${currency(Math.round(average))}`,\n                          position: 'insideBottomLeft',\n                          dy: -4,\n                        }}\n                      />\n                      <Area\n                        activeDot={chartActiveDot}\n                        dataKey='value'\n                        dot={chartLastDot(data.length, SERIES_COLOR)}\n                        fill={`url(#${gradient})`}\n                        name={title}\n                        stroke={SERIES_COLOR}\n                        strokeLinecap='round'\n                        strokeLinejoin='round'\n                        strokeWidth={2}\n                        type='monotone'\n                      />\n                    </AreaChart>\n                  </ResponsiveContainer>\n                </ChartPanelFigure>\n                <ChartPanelTable\n                  caption={`${title}: ${description}`}\n                  columns={[\n                    { key: 'label', label: 'Day' },\n                    { format: currency, key: 'value', label: title },\n                  ]}\n                  rows={data}\n                />\n              </BlockBusy>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { States2, exampleProps as states2ExampleProps, type States2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/states/states-02.tsx"
    }
  ],
  "meta": {
    "shows": "A chart that stays in place at reduced opacity while it refreshes, with an updating indicator in the header.",
    "size": "half",
    "usedWith": [
      "chart-panel-01",
      "states-01"
    ],
    "component": "States2",
    "props": "{ description: string; load: () => Promise<{ label: string; value: number }[]>; title: string }"
  },
  "type": "registry:component"
}
