{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "goals-01",
  "description": "One target with an expected-by-today marker, the projection at the current pace hatched on the bar, and what is left to do each day.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/goals.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/goals/goals-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  GoalProgress,\n  GoalProgressKey,\n  PaceLabel,\n  getElapsed,\n  getPace,\n} from '@/registry/components/dashboardblocks/goals'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCurrency,\n  formatDateRange,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface Goals1Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  current?: number\n  end: Date\n  formatter?: (value: number) => string\n  start: Date\n  target: number\n  title: string\n  today: Date\n}\n\nconst exampleProps: Goals1Props = {\n  current: 412_300,\n  end: new Date(Date.UTC(2026, 8, 30)),\n  formatter: (value) => formatCurrency(value),\n  start: new Date(Date.UTC(2026, 6, 1)),\n  target: 500_000,\n  title: 'Q3 revenue target',\n  today: new Date(Date.UTC(2026, 8, 25)),\n}\n\nconst DAY = 86_400_000\n\nconst Goals1 = (props: Goals1Props) => {\n  const {\n    end,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    start,\n    errorMessage,\n    status,\n    target,\n    title,\n    today,\n  } = props\n  const state = getBlockState(status, props.current)\n  const current = props.current ?? 0\n  const periodEnd = new Date(end.getTime() + DAY)\n  const pace = getPace({\n    current,\n    elapsed: getElapsed(start, periodEnd, today),\n    target,\n  })\n  const daysLeft = Math.max(\n    0,\n    Math.ceil((periodEnd.getTime() - today.getTime()) / DAY) - 1,\n  )\n  const share = target > 0 ? current / target : 0\n\n  const gap = current - pace.expected\n  const shortfall = target - pace.projected\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\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'>\n                  {formatDateRange({ end, start })}, with {daysLeft}{' '}\n                  {daysLeft === 1 ? 'day' : 'days'} to go.\n                </p>\n              </div>\n              {!state && <PaceLabel className='mt-0.5' status={pace.status} />}\n            </header>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <div className='flex flex-wrap items-baseline gap-x-2'>\n                <KPIValue value={props.current} format={formatter} />\n                {(!state || state === 'loading') && (\n                  <span className='text-muted-foreground text-sm tabular-nums'>\n                    of {formatter(target)}\n                  </span>\n                )}\n              </div>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>\n                  <span className='text-foreground font-medium tabular-nums'>\n                    {formatPercent(share, { maximumFractionDigits: 0 })}\n                  </span>{' '}\n                  of the target,{' '}\n                  <span\n                    className={cn(\n                      'font-medium tabular-nums',\n                      gap >= 0\n                        ? 'text-emerald-700 dark:text-emerald-400'\n                        : 'text-orange-700 dark:text-orange-400',\n                    )}\n                  >\n                    {formatter(Math.abs(gap))} {gap >= 0 ? 'ahead of' : 'behind'}\n                  </span>{' '}\n                  where a steady pace would be today.\n                </p>\n              </BlockReady>\n            </div>\n            <div className='flex flex-col gap-2.5'>\n              <GoalProgress\n                current={current}\n                expected={pace.status === 'met' ? undefined : pace.expected}\n                projected={pace.projected}\n                target={target}\n              />\n              <div className='flex flex-wrap items-center gap-x-4 gap-y-1'>\n                <GoalProgressKey label='So far' shape='progress' />\n                <GoalProgressKey label='At this pace' shape='projected' />\n                {pace.status !== 'met' && <GoalProgressKey />}\n              </div>\n            </div>\n            {(!state || state === 'loading') && (\n              <dl className='grid grid-cols-2 gap-4 border-t pt-4'>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>\n                    Projected at this pace\n                  </dt>\n                  <dd>\n                    <KPIValue\n                      className='text-2xl'\n                      value={pace.projected}\n                      format={formatter}\n                    />\n                  </dd>\n                  <dd\n                    className={cn(\n                      'text-xs tabular-nums',\n                      shortfall > 0\n                        ? 'font-medium text-orange-700 dark:text-orange-400'\n                        : 'text-muted-foreground',\n                    )}\n                  >\n                    <BlockReady>\n                      {shortfall > 0\n                        ? `${formatter(shortfall)} short of the target`\n                        : `${formatter(-shortfall)} over the target`}\n                    </BlockReady>\n                  </dd>\n                </div>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>\n                    Left to reach the target\n                  </dt>\n                  <dd>\n                    <KPIValue\n                      className='text-2xl'\n                      value={Math.max(0, target - current)}\n                      format={formatter}\n                    />\n                  </dd>\n                  <dd className='text-muted-foreground text-xs tabular-nums'>\n                    <BlockReady>\n                      {current >= target\n                        ? 'Target reached'\n                        : daysLeft > 0\n                          ? `${formatter((target - current) / daysLeft)} a day to get there`\n                          : 'No days left'}\n                    </BlockReady>\n                  </dd>\n                </div>\n              </dl>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Goals1, exampleProps as goals1ExampleProps, type Goals1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/goals/goals-01.tsx"
    }
  ],
  "meta": {
    "shows": "One target with an expected-by-today marker, the projection at the current pace hatched on the bar, and what is left to do each day.",
    "size": "half",
    "usedWith": [
      "forecast-03",
      "progress-kpi-01",
      "goals-03"
    ],
    "component": "Goals1",
    "props": "{ current?: number; end: Date; formatter?: (value: number) => string; start: Date; target: number; title: string; today: Date; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
