{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forecast-01",
  "description": "Weekly actuals continuing into a dashed forecast, with a shaded 80% range and a marker for today.",
  "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/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forecast/forecast-01.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  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartValueAxisWidth,\n  useChartId,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  type ConfidenceLevel,\n  ForecastLegend,\n  ForecastTooltip,\n  buildForecast,\n  forecastColors,\n  forecastDash,\n  getForecastAxis,\n} from '@/registry/components/dashboardblocks/forecast'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCompact,\n  formatDate,\n  formatNumber,\n  formatSigned,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  CartesianGrid,\n  ComposedChart,\n  Line,\n  ReferenceArea,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Forecast1Props extends BlockStateProps {\n  /** Values so far, oldest first, one step apart. Leave out, or pass none, to show the empty state. */\n  actuals?: number[]\n  description: string\n  formatter?: (value: number) => string\n  horizon: number\n  lastDate: Date\n  /** @default 0.8 */\n  level?: ConfidenceLevel\n  now: Date\n  stepDays?: number\n  title: string\n}\n\nconst exampleProps: Forecast1Props = {\n  actuals: Array.from({ length: 20 }, (_, week) =>\n    Math.round(\n      18_400 + week * 240 + Math.sin(week / 1.6) * 380 - (week % 5 === 2 ? 260 : 0),\n    ),\n  ),\n  description: 'Weekly active users, with a forecast for the rest of the year.',\n  formatter: (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n  horizon: 12,\n  lastDate: new Date(Date.UTC(2026, 8, 20)),\n  now: new Date(Date.UTC(2026, 8, 26)),\n  title: 'Active users forecast',\n}\n\nconst DAY = 86_400_000\n\nconst Forecast1 = (props: Forecast1Props) => {\n  const {\n    actuals = [],\n    description,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    horizon,\n    lastDate,\n    level = 0.8,\n    now,\n    errorMessage,\n    status,\n    stepDays = 7,\n    title,\n  } = props\n  const state = getBlockState(status, actuals)\n\n  const { fit, rows: forecastRows } = buildForecast(actuals, horizon, level)\n  const last = actuals.length - 1\n  const rows = forecastRows.map((row, index) => ({\n    ...row,\n    date: lastDate.getTime() + (index - last) * stepDays * DAY,\n  }))\n  const current = last >= 0 ? rows[last] : undefined\n  const end = last >= 0 ? rows[rows.length - 1] : undefined\n  const percent = `${level * 100}%`\n  const ticks = rows.filter((_, index) => (rows.length - 1 - index) % 4 === 0)\n  const yAxis = getForecastAxis(rows.flatMap((row) => [row.actual, row.low, row.high]))\n  const gradientId = useChartId()\n  const unit = stepDays === 7 ? 'week' : `${stepDays} days`\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'>\n                  {current && !state\n                    ? `Latest, ${formatDate(current.date, 'day')}`\n                    : 'Latest'}\n                </dt>\n                <dd>\n                  <KPIValue\n                    className='whitespace-nowrap'\n                    value={current?.actual ?? undefined}\n                    format={formatter}\n                  />\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'>\n                      {end && !state\n                        ? `Forecast, ${formatDate(end.date, 'day')}`\n                        : 'Forecast'}\n                    </dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={end?.forecast ?? 0}\n                        format={formatter}\n                      />\n                    </dd>\n                    <dd className='text-muted-foreground text-xs tabular-nums'>\n                      <BlockReady className='text-xs'>\n                        {percent} range {formatter(end?.low ?? 0)} to{' '}\n                        {formatter(end?.high ?? 0)}\n                      </BlockReady>\n                    </dd>\n                  </div>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Trend</dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={fit.slope}\n                        format={(value) => formatSigned(value, formatter)}\n                      />\n                    </dd>\n                    <dd className='text-muted-foreground text-xs'>\n                      <BlockReady className='text-xs'>a {unit}</BlockReady>\n                    </dd>\n                  </div>\n                </>\n              )}\n            </dl>\n            <ForecastLegend\n              items={[\n                { label: 'Actual', shape: 'line' },\n                { label: 'Forecast', shape: 'dashed' },\n                { label: `${percent} range`, shape: 'band' },\n                { label: 'Today', shape: 'marker' },\n              ]}\n            />\n            {!current || !end || state ? (\n              <ChartPlaceholder height={240} />\n            ) : (\n              <ChartPanelFigure className='h-60'>\n                <ResponsiveContainer width='100%' height='100%'>\n                  <ComposedChart\n                    aria-label={title}\n                    data={rows}\n                    margin={{ top: 20, right: 20, bottom: 0, left: 0 }}\n                  >\n                    <defs>\n                      <linearGradient id={gradientId} x1='0' y1='0' x2='0' y2='1'>\n                        <stop\n                          offset='0%'\n                          stopColor={forecastColors.actual}\n                          stopOpacity={0.3}\n                        />\n                        <stop\n                          offset='100%'\n                          stopColor={forecastColors.actual}\n                          stopOpacity={0}\n                        />\n                      </linearGradient>\n                    </defs>\n                    <CartesianGrid {...chartGridProps} />\n                    <XAxis\n                      {...chartAxisProps}\n                      dataKey='date'\n                      domain={['dataMin', 'dataMax']}\n                      interval='preserveStartEnd'\n                      minTickGap={24}\n                      scale='time'\n                      tickFormatter={(value: number) => formatDate(value, 'day')}\n                      ticks={ticks.map((row) => row.date)}\n                      type='number'\n                    />\n                    <YAxis\n                      {...chartAxisProps}\n                      domain={yAxis.domain}\n                      tickFormatter={(value: number) => formatCompact(value)}\n                      ticks={yAxis.ticks}\n                      width={chartValueAxisWidth}\n                    />\n                    <ReferenceArea\n                      x1={current.date}\n                      x2={end.date}\n                      fill='var(--color-muted)'\n                      fillOpacity={0.5}\n                      ifOverflow='hidden'\n                      label={{\n                        ...chartReferenceLabel,\n                        position: 'insideBottomRight',\n                        value: 'Forecast',\n                      }}\n                    />\n                    <ReferenceLine\n                      x={now.getTime()}\n                      stroke={forecastColors.marker}\n                      strokeWidth={1}\n                      label={{\n                        fill: 'var(--color-foreground)',\n                        fontSize: 11,\n                        position: 'top',\n                        value: 'Today',\n                      }}\n                    />\n                    <Tooltip\n                      content={(tooltipProps) => (\n                        <ForecastTooltip\n                          {...tooltipProps}\n                          formatLabel={(label) => formatDate(Number(label), 'day')}\n                          level={level}\n                          valueFormatter={formatter}\n                        />\n                      )}\n                      cursor={chartLineCursor}\n                    />\n                    <Area\n                      activeDot={false}\n                      dataKey='band'\n                      fill={forecastColors.band}\n                      fillOpacity={1}\n                      name={`${percent} range`}\n                      stroke='none'\n                      type='linear'\n                    />\n                    <Line\n                      activeDot={chartActiveDot}\n                      dataKey='forecast'\n                      dot={false}\n                      name='Forecast'\n                      stroke={forecastColors.forecast}\n                      strokeDasharray={forecastDash.forecast}\n                      strokeWidth={2}\n                      type='linear'\n                    />\n                    <Area\n                      activeDot={chartActiveDot}\n                      dataKey='actual'\n                      dot={chartLastDot(actuals.length, forecastColors.actual)}\n                      fill={`url(#${gradientId})`}\n                      fillOpacity={1}\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} The forecast is a straight-line fit with a ${percent} range.`}\n                columns={[\n                  { key: 'label', label: 'Week ending' },\n                  { format: formatter, key: 'actual', label: 'Actual' },\n                  { format: formatter, key: 'forecast', label: 'Forecast' },\n                  { format: formatter, key: 'low', label: `Low (${percent})` },\n                  { format: formatter, key: 'high', label: `High (${percent})` },\n                ]}\n                rows={rows.map((row, index) => {\n                  const isForecast = index > last\n                  return {\n                    actual: row.actual ?? '—',\n                    forecast: isForecast ? (row.forecast ?? '—') : '—',\n                    high: isForecast ? (row.high ?? '—') : '—',\n                    label: formatDate(row.date, 'day'),\n                    low: isForecast ? (row.low ?? '—') : '—',\n                  }\n                })}\n              />\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forecast1, exampleProps as forecast1ExampleProps, type Forecast1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forecast/forecast-01.tsx"
    }
  ],
  "meta": {
    "shows": "Weekly actuals continuing into a dashed forecast, with a shaded 80% range and a marker for today.",
    "size": "full",
    "usedWith": [
      "forecast-04",
      "chart-panel-01",
      "stat-group-01"
    ],
    "component": "Forecast1",
    "props": "{ actuals?: number[]; description: string; formatter?: (value: number) => string; horizon: number; lastDate: Date; level?: 0.8 | 0.9 | 0.95; now: Date; stepDays?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
