{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forecast-04",
  "description": "Low, base and high growth scenarios from the last actual, as a chart and a table with when each one reaches the target.",
  "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/forecast.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forecast/forecast-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  ChartTooltipContent,\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  ForecastKey,\n  type ForecastKeyShape,\n  ForecastLegend,\n  ForecastStatusLabel,\n  forecastColors,\n  forecastDash,\n  getForecastAxis,\n  projectGrowth,\n} from '@/registry/components/dashboardblocks/forecast'\nimport {\n  DataTable,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableStateRows,\n} from '@/registry/components/dashboardblocks/table'\nimport {\n  formatCompact,\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n  formatSigned,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  CartesianGrid,\n  ComposedChart,\n  Line,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ntype ScenarioKey = 'low' | 'base' | 'high'\n\ninterface Scenario {\n  note: string\n  /** Growth per step, as a fraction. */\n  rate: number\n}\n\ninterface Forecast4Props extends BlockStateProps {\n  /** Values so far, oldest first. Leave out, or pass none, to show the empty state. */\n  actuals?: { label: string; value: number }[]\n  description: string\n  formatter?: (value: number) => string\n  horizon: string[]\n  scenarios: Record<ScenarioKey, Scenario>\n  target?: number\n  title: string\n}\n\nconst exampleProps: Forecast4Props = {\n  actuals: [\n    { label: 'Mar 2026', value: 182_400 },\n    { label: 'Apr 2026', value: 188_900 },\n    { label: 'May 2026', value: 193_100 },\n    { label: 'Jun 2026', value: 201_700 },\n    { label: 'Jul 2026', value: 207_300 },\n    { label: 'Aug 2026', value: 214_200 },\n  ],\n  description: 'Monthly recurring revenue under three growth scenarios.',\n  formatter: (value) => formatCurrency(value),\n  horizon: ['Sep 2026', 'Oct 2026', 'Nov 2026', 'Dec 2026', 'Jan 2027', 'Feb 2027'],\n  scenarios: {\n    base: { note: 'Current growth continues', rate: 0.03 },\n    high: { note: 'Enterprise plan launches in October', rate: 0.05 },\n    low: { note: 'Churn rises to last winter’s level', rate: 0.01 },\n  },\n  target: 250_000,\n  title: 'Revenue scenarios',\n}\n\nconst SCENARIOS: { key: ScenarioKey; label: string; shape: ForecastKeyShape }[] = [\n  { key: 'high', label: 'High', shape: 'dotted' },\n  { key: 'base', label: 'Base', shape: 'dashed' },\n  { key: 'low', label: 'Low', shape: 'dotted' },\n]\n\nconst formatGrowth = (ratio: number) =>\n  formatSigned(ratio, (value) => formatPercent(value))\n\nconst Forecast4 = (props: Forecast4Props) => {\n  const {\n    actuals = [],\n    description,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    horizon,\n    scenarios,\n    errorMessage,\n    status,\n    target,\n    title,\n  } = props\n  const state = getBlockState(status, actuals)\n\n  const current = actuals[actuals.length - 1]?.value ?? 0\n  const paths = {\n    base: projectGrowth(current, scenarios.base.rate, horizon.length),\n    high: projectGrowth(current, scenarios.high.rate, horizon.length),\n    low: projectGrowth(current, scenarios.low.rate, horizon.length),\n  }\n  const rows = [\n    ...actuals.map((point, index) => {\n      const isLast = index === actuals.length - 1\n      return {\n        actual: point.value,\n        base: isLast ? point.value : null,\n        high: isLast ? point.value : null,\n        label: point.label,\n        low: isLast ? point.value : null,\n        range: isLast ? [point.value, point.value] : null,\n      }\n    }),\n    ...horizon.map((label, index) => ({\n      actual: null,\n      base: paths.base[index],\n      high: paths.high[index],\n      label,\n      low: paths.low[index],\n      range: [paths.low[index], paths.high[index]],\n    })),\n  ]\n  const endLabel = horizon[horizon.length - 1] ?? ''\n  const yAxis = getForecastAxis([\n    ...rows.flatMap((row) => [row.actual, row.low, row.high]),\n    target ?? null,\n  ])\n\n  const renderEndLabel =\n    (text: string) =>\n    ({ index, x, y }: { index?: number; x?: number | string; y?: number | string }) =>\n      index === rows.length - 1 ? (\n        <text\n          x={Number(x) + 6}\n          y={Number(y)}\n          dominantBaseline='middle'\n          fill='var(--color-muted-foreground)'\n          fontSize={11}\n        >\n          {text}\n        </text>\n      ) : null\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container/data-table 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            <div className='flex flex-col gap-4 border-t pt-4'>\n              <ForecastLegend\n                items={[\n                  { label: 'Actual', shape: 'line' },\n                  { label: 'Base', shape: 'dashed' },\n                  { label: 'Low to high', shape: 'band' },\n                  ...(target !== undefined\n                    ? [{ label: `Target ${formatter(target)}`, shape: 'dotted' as const }]\n                    : []),\n                ]}\n              />\n              {state ? (\n                <ChartPlaceholder height={224} />\n              ) : (\n                <ChartPanelFigure className='h-56'>\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <ComposedChart\n                      aria-label={title}\n                      data={rows}\n                      margin={{ top: 8, right: 36, bottom: 0, left: 0 }}\n                    >\n                      <CartesianGrid {...chartGridProps} />\n                      <XAxis\n                        {...chartAxisProps}\n                        dataKey='label'\n                        interval='preserveStartEnd'\n                        minTickGap={16}\n                        tickFormatter={(label: string) => label.slice(0, 3)}\n                      />\n                      <YAxis\n                        {...chartAxisProps}\n                        domain={yAxis.domain}\n                        tickFormatter={(value: number) => formatCompact(value)}\n                        ticks={yAxis.ticks}\n                        width={chartValueAxisWidth}\n                      />\n                      {target !== undefined && (\n                        <ReferenceLine\n                          {...chartReferenceProps}\n                          y={target}\n                          label={{\n                            ...chartReferenceLabel,\n                            position: 'insideTopLeft',\n                            value: 'Target',\n                          }}\n                        />\n                      )}\n                      <Tooltip\n                        content={(tooltipProps) => {\n                          const row = tooltipProps.payload?.[0]?.payload as\n                            | (typeof rows)[number]\n                            | undefined\n                          const payload = tooltipProps.payload?.filter((item) =>\n                            row?.actual !== null\n                              ? item.dataKey === 'actual'\n                              : item.dataKey !== 'range' && item.dataKey !== 'actual',\n                          )\n                          return (\n                            <ChartTooltipContent\n                              {...tooltipProps}\n                              payload={payload}\n                              valueFormatter={formatter}\n                            />\n                          )\n                        }}\n                        cursor={chartLineCursor}\n                      />\n                      <Area\n                        activeDot={false}\n                        dataKey='range'\n                        fill={forecastColors.band}\n                        fillOpacity={1}\n                        name='Low to high'\n                        stroke='none'\n                        type='linear'\n                      />\n                      {SCENARIOS.map((scenario) => (\n                        <Line\n                          key={scenario.key}\n                          activeDot={chartActiveDot}\n                          dataKey={scenario.key}\n                          dot={false}\n                          label={renderEndLabel(scenario.label)}\n                          name={scenario.label}\n                          stroke={forecastColors.forecast}\n                          strokeDasharray={\n                            scenario.key === 'base'\n                              ? forecastDash.forecast\n                              : forecastDash.target\n                          }\n                          strokeOpacity={scenario.key === 'base' ? 1 : 0.7}\n                          strokeWidth={scenario.key === 'base' ? 2 : 1.5}\n                          type='linear'\n                        />\n                      ))}\n                      <Line\n                        activeDot={chartActiveDot}\n                        dataKey='actual'\n                        dot={false}\n                        name='Actual'\n                        stroke={forecastColors.actual}\n                        strokeLinecap='round'\n                        strokeWidth={2}\n                        type='monotone'\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: formatter, key: 'actual', label: 'Actual' },\n                    ...SCENARIOS.map((scenario) => ({\n                      format: formatter,\n                      key: scenario.key,\n                      label: scenario.label,\n                    })),\n                  ]}\n                  rows={rows.map((row, index) => {\n                    const isScenario = index >= actuals.length\n                    return {\n                      actual: row.actual ?? '—',\n                      base: isScenario ? (row.base ?? '—') : '—',\n                      high: isScenario ? (row.high ?? '—') : '—',\n                      label: row.label,\n                      low: isScenario ? (row.low ?? '—') : '—',\n                    }\n                  })}\n                />\n              )}\n            </div>\n            <DataTable caption={`${title} by scenario, to ${endLabel}`}>\n              <DataTableHeader>\n                <DataTableRow>\n                  <DataTableHead>Scenario</DataTableHead>\n                  <DataTableHead align='end'>Growth</DataTableHead>\n                  <DataTableHead align='end'>{endLabel}</DataTableHead>\n                  <DataTableHead align='end'>Change</DataTableHead>\n                  {target !== undefined && (\n                    <DataTableHead align='end'>Reaches target</DataTableHead>\n                  )}\n                </DataTableRow>\n              </DataTableHeader>\n              <DataTableBody>\n                <DataTableStateRows colSpan={target !== undefined ? 5 : 4} rows={3} />\n                {!state &&\n                  SCENARIOS.map((scenario) => {\n                    const path = paths[scenario.key]\n                    const end = path[path.length - 1] ?? current\n                    const reachedIndex =\n                      target !== undefined\n                        ? path.findIndex((value) => value >= target)\n                        : -1\n                    const reached =\n                      target !== undefined && current >= target\n                        ? 'Already'\n                        : reachedIndex >= 0\n                          ? horizon[reachedIndex]\n                          : null\n                    return (\n                      <DataTableRow key={scenario.key}>\n                        <DataTableCell primary>\n                          <div className='flex items-start gap-2'>\n                            <ForecastKey className='mt-1' shape={scenario.shape} />\n                            <div className='flex min-w-0 flex-col'>\n                              <span className='font-medium'>{scenario.label}</span>\n                              <span className='text-muted-foreground text-xs'>\n                                {scenarios[scenario.key].note}\n                              </span>\n                            </div>\n                          </div>\n                        </DataTableCell>\n                        <DataTableCell align='end'>\n                          {formatGrowth(scenarios[scenario.key].rate)} a month\n                        </DataTableCell>\n                        <DataTableCell align='end' className='font-medium'>\n                          {formatter(end)}\n                        </DataTableCell>\n                        <DataTableCell align='end'>\n                          {formatGrowth(current > 0 ? end / current - 1 : 0)}\n                        </DataTableCell>\n                        {target !== undefined && (\n                          <DataTableCell align='end'>\n                            <ForecastStatusLabel\n                              variant='text'\n                              label={reached ?? `Not by ${endLabel}`}\n                              status={reached ? 'on-track' : 'off-track'}\n                            />\n                          </DataTableCell>\n                        )}\n                      </DataTableRow>\n                    )\n                  })}\n              </DataTableBody>\n            </DataTable>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forecast4, exampleProps as forecast4ExampleProps, type Forecast4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forecast/forecast-04.tsx"
    }
  ],
  "meta": {
    "shows": "Low, base and high growth scenarios from the last actual, as a chart and a table with when each one reaches the target.",
    "size": "full",
    "usedWith": [
      "forecast-01",
      "forecast-02",
      "goals-03"
    ],
    "component": "Forecast4",
    "props": "{ actuals?: { label: string; value: number }[]; description: string; formatter?: (value: number) => string; horizon: string[]; scenarios: { low: { note: string; rate: number }; base: { note: string; rate: number }; high: { note: string; rate: number } }; target?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
