{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forecast-03",
  "description": "Month to date, projected to the end of the month at the daily run-rate, with what is needed per day to hit the target.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/forecast.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forecast/forecast-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  ForecastLegend,\n  ForecastStatusLabel,\n  ProjectionBar,\n  getProjectionStatus,\n  getRunRate,\n} from '@/registry/components/dashboardblocks/forecast'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Forecast3Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  current?: number\n  description: string\n  elapsed: number\n  formatter?: (value: number) => string\n  target: number\n  title: string\n  total: number\n}\n\nconst exampleProps: Forecast3Props = {\n  current: 38_420,\n  description: 'Month to date through Sep 25, projected at the daily run-rate.',\n  elapsed: 25,\n  formatter: (value) => formatCurrency(value),\n  target: 48_000,\n  title: 'September revenue',\n  total: 30,\n}\n\nconst Forecast3 = (props: Forecast3Props) => {\n  const {\n    current = 0,\n    description,\n    elapsed,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    errorMessage,\n    status: blockStatus,\n    target,\n    title,\n    total,\n  } = props\n  const state = getBlockState(blockStatus, props.current)\n\n  const { projected, rate, remaining, required } = getRunRate({\n    current,\n    elapsed,\n    target,\n    total,\n  })\n  const status = current >= target ? 'reached' : getProjectionStatus(projected, target)\n  const gap = projected - target\n  const share = formatPercent(target > 0 ? projected / target : 0, {\n    maximumFractionDigits: 0,\n  })\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 items-start justify-between gap-4'>\n              <div 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              </div>\n              <ForecastStatusLabel status={status} />\n            </header>\n            <dl className='flex flex-wrap items-start gap-x-10 gap-y-3 border-t pt-4'>\n              <div className='flex flex-col gap-1'>\n                <dt className='text-muted-foreground text-sm'>\n                  So far, day {elapsed} of {total}\n                </dt>\n                <dd>\n                  <KPIValue value={props.current} format={formatter} />\n                </dd>\n              </div>\n              {state !== 'empty' && state !== 'error' && (\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Projected</dt>\n                  <dd>\n                    <KPIValue className='text-2xl' value={projected} format={formatter} />\n                  </dd>\n                  <dd className='text-muted-foreground text-xs tabular-nums'>\n                    <BlockReady className='text-xs'>\n                      {share} of {formatter(target)}\n                    </BlockReady>\n                  </dd>\n                </div>\n              )}\n            </dl>\n            <div className='flex flex-col gap-2'>\n              <ProjectionBar\n                current={current}\n                max={Math.max(projected, target) * 1.05}\n                projected={projected}\n                target={target}\n              />\n              <ForecastLegend\n                items={[\n                  { label: 'So far', shape: 'bar' },\n                  { label: 'Projected', shape: 'striped' },\n                  { label: 'Target', shape: 'marker' },\n                ]}\n              />\n            </div>\n            <BlockReady className='text-sm'>\n              <p className='text-sm text-pretty'>\n                {status === 'reached'\n                  ? `Target met with ${remaining} ${remaining === 1 ? 'day' : 'days'} to go, at ${formatter(rate)} a day.`\n                  : `At ${formatter(rate)} a day the month ends ${formatter(Math.abs(gap))} ${gap >= 0 ? 'over' : 'short'}.`}\n                {status !== 'reached' && required !== null && required > 0 && (\n                  <span className='text-muted-foreground'>\n                    {` Hitting the target takes ${formatter(required)} a day for the last ${remaining} ${remaining === 1 ? 'day' : 'days'}.`}\n                  </span>\n                )}\n              </p>\n            </BlockReady>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forecast3, exampleProps as forecast3ExampleProps, type Forecast3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forecast/forecast-03.tsx"
    }
  ],
  "meta": {
    "shows": "Month to date, projected to the end of the month at the daily run-rate, with what is needed per day to hit the target.",
    "size": "half",
    "usedWith": [
      "goals-01",
      "goals-03",
      "progress-kpi-01"
    ],
    "component": "Forecast3",
    "props": "{ current?: number; description: string; elapsed: number; formatter?: (value: number) => string; target: number; title: string; total: number; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
