{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "goals-03",
  "description": "Cumulative progress this month, projected to the end of the month at the current daily rate, with the day it reaches the target or how far short it ends.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/goals.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/goals/goals-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  ChartTooltipContent,\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  chartValueAxisWidth,\n  useChartId,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { PaceLabel, getPace } from '@/registry/components/dashboardblocks/goals'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCompact,\n  formatCurrency,\n  formatNumber,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  CartesianGrid,\n  ComposedChart,\n  Line,\n  ReferenceDot,\n  ReferenceLine,\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 Goals3Props extends BlockStateProps {\n  /** Daily values so far, oldest first. Leave out, or pass none, to show the empty state. */\n  daily?: number[]\n  description: string\n  /** Day labels for the whole period, including days still to come. */\n  days: string[]\n  formatter?: (value: number) => string\n  target: number\n  title: string\n}\n\nconst SEPTEMBER = Array.from({ length: 30 }, (_, day) => `Sep ${day + 1}`)\n\nconst exampleProps: Goals3Props = {\n  daily: Array.from({ length: 25 }, (_, day) =>\n    Math.round(1_500 + day * 14 + Math.sin(day / 2.3) * 260 - (day % 7 > 4 ? 380 : 0)),\n  ),\n  description: 'Revenue so far this month, and where the daily rate takes it.',\n  days: SEPTEMBER,\n  formatter: (value) => formatCurrency(value),\n  target: 48_000,\n  title: 'September revenue goal',\n}\n\nconst ACTUAL_COLOR = 'var(--color-chart-2)'\nconst PROJECTED_COLOR = 'var(--color-muted-foreground)'\n\nconst Goals3 = (props: Goals3Props) => {\n  const {\n    daily = [],\n    description,\n    days,\n    formatter = (value) => formatNumber(value, { maximumFractionDigits: 0 }),\n    errorMessage,\n    status,\n    target,\n    title,\n  } = props\n  const state = getBlockState(status, daily)\n  const gradient = useChartId()\n\n  const actual = daily.map((_, index) =>\n    daily.slice(0, index + 1).reduce((sum, value) => sum + value, 0),\n  )\n  const today = actual.length - 1\n  const current = actual[today] ?? 0\n  const pace = getPace({ current, elapsed: daily.length / days.length, target })\n  const rate = daily.length > 0 ? current / daily.length : 0\n  const rows = days.map((label, index) => ({\n    actual: index <= today ? actual[index] : null,\n    label,\n    projected: index >= today ? Math.round(current + rate * (index - today)) : null,\n  }))\n  const projected = rows[rows.length - 1]?.projected ?? current\n  const crossing = rows.find(\n    (row, index) => index > today && row.projected !== null && row.projected >= target,\n  )\n  const daysLeft = days.length - daily.length\n  const needed = daysLeft > 0 ? Math.max(0, target - current) / daysLeft : 0\n  const step = 10 ** Math.floor(Math.log10(Math.max(target, projected, 1)))\n  const yMax = Math.ceil((Math.max(target, projected) * 1.1) / step) * step\n  const shortfall = target - 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'>{description}</p>\n              </div>\n              {!state && <PaceLabel className='mt-0.5' status={pace.status} />}\n            </header>\n            <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4 @lg:grid-cols-3'>\n              <div className='col-span-2 flex flex-col gap-1 @lg:col-span-1'>\n                <dt className='text-muted-foreground text-sm'>So far</dt>\n                <dd>\n                  <KPIValue value={current} format={formatter} />\n                </dd>\n                {(!state || state === 'loading') && (\n                  <dd className='text-muted-foreground text-xs tabular-nums'>\n                    <BlockReady>{formatter(rate)} a day on average</BlockReady>\n                  </dd>\n                )}\n              </div>\n              {(!state || state === 'loading') && (\n                <>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Projected</dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={projected}\n                        format={formatter}\n                      />\n                    </dd>\n                    <dd\n                      className={cn(\n                        'text-xs font-medium tabular-nums',\n                        shortfall > 0\n                          ? 'text-orange-700 dark:text-orange-400'\n                          : 'text-emerald-700 dark:text-emerald-400',\n                      )}\n                    >\n                      <BlockReady>\n                        {shortfall > 0\n                          ? `${formatter(shortfall)} short`\n                          : `${formatter(-shortfall)} over`}\n                      </BlockReady>\n                    </dd>\n                  </div>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Target</dt>\n                    <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                      {formatter(target)}\n                    </dd>\n                    <dd className='text-muted-foreground text-xs tabular-nums'>\n                      <BlockReady>\n                        {current >= target\n                          ? 'Reached'\n                          : daysLeft > 0\n                            ? `Needs ${formatter(needed)} a day from here`\n                            : 'Not reached'}\n                      </BlockReady>\n                    </dd>\n                  </div>\n                </>\n              )}\n            </dl>\n            {(!state || state === 'loading') && (\n              <ChartPanelLegend\n                items={[\n                  { color: ACTUAL_COLOR, label: 'Revenue so far', shape: 'line' },\n                  { color: PROJECTED_COLOR, label: 'At the daily rate', shape: 'line' },\n                ]}\n              />\n            )}\n            {state ? (\n              <ChartPlaceholder height={240} />\n            ) : (\n              <>\n                <ChartPanelFigure className='h-60'>\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <ComposedChart\n                      aria-label={`${title} by day, with the target and the daily rate projected to the end`}\n                      data={rows}\n                      margin={{ top: 20, right: 16, bottom: 0, left: 0 }}\n                    >\n                      <defs>\n                        <linearGradient id={gradient} x1='0' x2='0' y1='0' y2='1'>\n                          <stop offset='0%' stopColor={ACTUAL_COLOR} stopOpacity={0.3} />\n                          <stop offset='100%' stopColor={ACTUAL_COLOR} stopOpacity={0} />\n                        </linearGradient>\n                      </defs>\n                      <CartesianGrid {...chartGridProps} />\n                      <XAxis\n                        {...chartAxisProps}\n                        dataKey='label'\n                        interval='preserveStartEnd'\n                        minTickGap={40}\n                      />\n                      <YAxis\n                        {...chartAxisProps}\n                        domain={[0, yMax]}\n                        tickFormatter={(value: number) => formatCompact(value)}\n                        width={chartValueAxisWidth}\n                      />\n                      <Tooltip\n                        content={(tooltipProps) => (\n                          <ChartTooltipContent\n                            {...tooltipProps}\n                            payload={tooltipProps.payload\n                              ?.filter(\n                                (item) => item.value !== null && item.value !== undefined,\n                              )\n                              .slice(0, 1)}\n                            valueFormatter={formatter}\n                          />\n                        )}\n                        cursor={chartLineCursor}\n                      />\n                      <ReferenceLine\n                        {...chartReferenceProps}\n                        y={target}\n                        label={{\n                          ...chartReferenceLabel,\n                          position: 'insideTopLeft',\n                          value: `Target ${formatCompact(target)}`,\n                        }}\n                      />\n                      {rows[today] && (\n                        <ReferenceLine\n                          x={rows[today].label}\n                          stroke='var(--color-border)'\n                          label={{\n                            ...chartReferenceLabel,\n                            position: 'top',\n                            value: 'Today',\n                          }}\n                        />\n                      )}\n                      <Area\n                        activeDot={chartActiveDot}\n                        dataKey='actual'\n                        dot={chartLastDot(today + 1, ACTUAL_COLOR)}\n                        fill={`url(#${gradient})`}\n                        name='Revenue so far'\n                        stroke={ACTUAL_COLOR}\n                        strokeWidth={2}\n                        type='monotone'\n                      />\n                      <Line\n                        activeDot={chartActiveDot}\n                        dataKey='projected'\n                        dot={false}\n                        name='At the daily rate'\n                        stroke={PROJECTED_COLOR}\n                        strokeDasharray='5 4'\n                        strokeWidth={2}\n                        type='linear'\n                      />\n                      {crossing ? (\n                        <ReferenceDot\n                          x={crossing.label}\n                          y={target}\n                          r={4}\n                          fill='var(--color-emerald-600)'\n                          stroke='var(--color-background)'\n                          strokeWidth={2}\n                          label={{\n                            fill: 'var(--color-foreground)',\n                            fontSize: 11,\n                            fontWeight: 500,\n                            position:\n                              rows.indexOf(crossing) > rows.length * 0.75\n                                ? 'left'\n                                : 'top',\n                            value: `Hits it ${crossing.label}`,\n                          }}\n                        />\n                      ) : (\n                        rows.length > today + 1 && (\n                          <ReferenceDot\n                            x={rows[rows.length - 1].label}\n                            y={projected}\n                            r={4}\n                            fill={PROJECTED_COLOR}\n                            stroke='var(--color-background)'\n                            strokeWidth={2}\n                            label={{\n                              fill: 'var(--color-foreground)',\n                              fontSize: 11,\n                              fontWeight: 500,\n                              position: 'left',\n                              value: `${formatter(shortfall)} short`,\n                            }}\n                          />\n                        )\n                      )}\n                    </ComposedChart>\n                  </ResponsiveContainer>\n                </ChartPanelFigure>\n                <ChartPanelTable\n                  caption={`${title}: ${description} Target ${formatter(target)}.`}\n                  columns={[\n                    { key: 'label', label: 'Day' },\n                    { key: 'actual', label: 'Revenue so far' },\n                    { key: 'projected', label: 'At the daily rate' },\n                  ]}\n                  rows={rows.map((row, index) => ({\n                    actual: row.actual === null ? '—' : formatter(row.actual),\n                    label: row.label,\n                    projected:\n                      row.projected === null || index === today\n                        ? '—'\n                        : formatter(row.projected),\n                  }))}\n                />\n              </>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Goals3, exampleProps as goals3ExampleProps, type Goals3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/goals/goals-03.tsx"
    }
  ],
  "meta": {
    "shows": "Cumulative progress this month, projected to the end of the month at the current daily rate, with the day it reaches the target or how far short it ends.",
    "size": "full",
    "usedWith": [
      "goals-01",
      "forecast-03",
      "stat-group-01"
    ],
    "component": "Goals3",
    "props": "{ daily?: number[]; description: string; days: string[]; formatter?: (value: number) => string; target: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
