{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spend-03",
  "description": "Monthly spend as bars against a stepped budget line, with months over budget in red and labelled with the overspend, and the year-to-date variance.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/spend.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/spend/spend-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartAxisProps,\n  chartBarCursor,\n  chartGridProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { spendColors } from '@/registry/components/dashboardblocks/spend'\nimport { formatCurrency, formatSigned } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Bar,\n  CartesianGrid,\n  Cell,\n  ComposedChart,\n  LabelList,\n  Line,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface SpendPeriod {\n  budget: number\n  label: string\n  spent: number\n}\n\ninterface Spend3Props extends BlockStateProps {\n  /** @default 'USD' */\n  currency?: string\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  periods?: SpendPeriod[]\n  title: string\n}\n\nconst MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']\nconst SPENT = [31_200, 30_850, 33_900, 35_120, 38_460, 36_980, 41_720, 43_050, 44_380]\nconst BUDGET = [34_000, 34_000, 34_000, 38_000, 38_000, 38_000, 42_000, 42_000, 42_000]\n\nconst exampleProps: Spend3Props = {\n  description: 'Cloud spend against the monthly budget, January to September 2026.',\n  periods: MONTHS.map((label, index) => ({\n    budget: BUDGET[index],\n    label,\n    spent: SPENT[index],\n  })),\n  title: 'Spend vs budget',\n}\n\nconst MIN_LABELLED_BAR_WIDTH = 30\n\nconst Spend3 = (props: Spend3Props) => {\n  const {\n    currency = 'USD',\n    description,\n    periods = [],\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, periods)\n  const format = (value: number) => formatCurrency(value, { currency })\n  const compact = (value: number) => formatCurrency(value, { compact: true, currency })\n  const spent = periods.reduce((sum, period) => sum + period.spent, 0)\n  const budget = periods.reduce((sum, period) => sum + period.budget, 0)\n  const variance = spent - budget\n  const overMonths = periods.filter((period) => period.spent > period.budget).length\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            <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4 @lg:grid-cols-3 @lg:items-start'>\n              <div className='col-span-2 flex flex-col gap-1 @lg:col-span-1'>\n                <dt className='text-muted-foreground text-sm'>Spent, year to date</dt>\n                <dd>\n                  <KPIValue className='whitespace-nowrap' value={spent} format={format} />\n                </dd>\n              </div>\n              {state !== 'empty' && state !== 'error' && (\n                <>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Budget</dt>\n                    <dd>\n                      <KPIValue className='text-2xl' value={budget} format={format} />\n                    </dd>\n                  </div>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>\n                      {variance > 0 ? 'Over budget' : 'Under budget'}\n                    </dt>\n                    <dd>\n                      <KPIValue\n                        className={cn(\n                          'text-2xl',\n                          variance > 0 && 'text-red-700 dark:text-red-400',\n                        )}\n                        value={Math.abs(variance)}\n                        format={format}\n                      />\n                    </dd>\n                    <dd className='text-muted-foreground text-xs'>\n                      <BlockReady className='text-xs'>\n                        {overMonths} of {periods.length} months over\n                      </BlockReady>\n                    </dd>\n                  </div>\n                </>\n              )}\n            </dl>\n            {state !== 'empty' && state !== 'error' && (\n              <ChartPanelLegend\n                items={[\n                  { color: spendColors.spent, label: 'Within budget' },\n                  { color: spendColors.over, label: 'Over budget' },\n                  {\n                    color: 'var(--color-muted-foreground)',\n                    label: 'Budget',\n                    shape: 'line',\n                  },\n                ]}\n              />\n            )}\n            {state ? (\n              <ChartPlaceholder height={256} />\n            ) : (\n              <ChartPanelFigure className='h-64'>\n                <ResponsiveContainer width='100%' height='100%'>\n                  <ComposedChart\n                    aria-label={`${title} chart`}\n                    data={periods}\n                    margin={{ top: 20, right: 8, bottom: 0, left: 0 }}\n                  >\n                    <CartesianGrid {...chartGridProps} />\n                    <XAxis {...chartAxisProps} dataKey='label' />\n                    <YAxis\n                      {...chartAxisProps}\n                      tickFormatter={compact}\n                      width={chartValueAxisWidth}\n                    />\n                    <Tooltip\n                      content={(tooltipProps) => (\n                        <ChartTooltipContent {...tooltipProps} valueFormatter={format} />\n                      )}\n                      cursor={chartBarCursor}\n                    />\n                    <Bar\n                      dataKey='spent'\n                      maxBarSize={36}\n                      name='Spent'\n                      radius={[4, 4, 0, 0]}\n                    >\n                      {periods.map((period) => (\n                        <Cell\n                          key={period.label}\n                          fill={\n                            period.spent > period.budget\n                              ? spendColors.over\n                              : spendColors.spent\n                          }\n                        />\n                      ))}\n                      <LabelList\n                        dataKey='spent'\n                        content={({ x, y, width, index }) => {\n                          const period = index === undefined ? undefined : periods[index]\n                          if (!period || period.spent <= period.budget) return null\n                          if (Number(width) < MIN_LABELLED_BAR_WIDTH) return null\n                          return (\n                            <text\n                              x={Number(x) + Number(width) / 2}\n                              y={Number(y) - 6}\n                              textAnchor='middle'\n                              fontSize={11}\n                              fontWeight={500}\n                              fill='var(--color-foreground)'\n                            >\n                              {formatSigned(period.spent - period.budget, compact)}\n                            </text>\n                          )\n                        }}\n                      />\n                    </Bar>\n                    <Line\n                      activeDot={false}\n                      dataKey='budget'\n                      dot={false}\n                      name='Budget'\n                      stroke='var(--color-muted-foreground)'\n                      strokeDasharray='5 4'\n                      strokeWidth={1.5}\n                      type='step'\n                    />\n                  </ComposedChart>\n                </ResponsiveContainer>\n              </ChartPanelFigure>\n            )}\n            {!state && (\n              <ChartPanelTable\n                caption={`${title}: ${description}`}\n                columns={[\n                  { key: 'label', label: 'Month' },\n                  { format, key: 'spent', label: 'Spent' },\n                  { format, key: 'budget', label: 'Budget' },\n                  { key: 'status', label: 'Status' },\n                ]}\n                rows={periods.map((period) => ({\n                  ...period,\n                  status: period.spent > period.budget ? 'Over budget' : 'Within budget',\n                }))}\n              />\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Spend3, exampleProps as spend3ExampleProps, type Spend3Props, type SpendPeriod }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/spend/spend-03.tsx"
    }
  ],
  "meta": {
    "shows": "Monthly spend as bars against a stepped budget line, with months over budget in red and labelled with the overspend, and the year-to-date variance.",
    "size": "full",
    "usedWith": [
      "spend-01",
      "spend-02"
    ],
    "component": "Spend3",
    "props": "{ currency?: string; description: string; periods?: { budget: number; label: string; spent: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
