{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pipeline-04",
  "description": "Closed and open deals weighted by the chance each stage closes, per owner, against their quota.",
  "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/pipeline.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/pipeline/pipeline-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  GoalProgress,\n  GoalProgressKey,\n} from '@/registry/components/dashboardblocks/goals'\nimport {\n  PipelineOwner,\n  type PipelineStage,\n} from '@/registry/components/dashboardblocks/pipeline'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport {\n  formatCurrency,\n  formatPercent,\n  joinDetails,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface OwnerPipeline {\n  avatar?: string\n  closed: number\n  deals: { stage: string; value: number }[]\n  name: string\n  quota: number\n}\n\ninterface Pipeline4Props extends BlockStateProps {\n  /** Defaults to a sentence counting who is on course for quota. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  owners?: OwnerPipeline[]\n  stages: PipelineStage[]\n  title: string\n}\n\nconst deals = (stage: string, ...values: number[]) =>\n  values.map((value) => ({ stage, value }))\n\nconst exampleProps: Pipeline4Props = {\n  owners: [\n    {\n      closed: 286_000,\n      deals: [\n        ...deals('qualified', 42_000, 31_200),\n        ...deals('proposal', 39_900, 58_000),\n        ...deals('negotiation', 74_000),\n      ],\n      name: 'Maya Patel',\n      avatar: '/images/avatar-16.webp',\n      quota: 400_000,\n    },\n    {\n      closed: 198_000,\n      deals: [\n        ...deals('discovery', 96_000),\n        ...deals('proposal', 64_500),\n        ...deals('negotiation', 212_000),\n      ],\n      name: 'Jonas Weber',\n      avatar: '/images/avatar-07.webp',\n      quota: 400_000,\n    },\n    {\n      closed: 142_000,\n      deals: [\n        ...deals('qualified', 27_000),\n        ...deals('discovery', 48_000),\n        ...deals('proposal', 128_000),\n      ],\n      name: 'Aiko Tanaka',\n      avatar: '/images/avatar-09.webp',\n      quota: 350_000,\n    },\n    {\n      closed: 121_000,\n      deals: [\n        ...deals('qualified', 18_500),\n        ...deals('discovery', 54_000),\n        ...deals('negotiation', 87_000),\n      ],\n      name: 'Luis Romero',\n      avatar: '/images/avatar-13.webp',\n      quota: 300_000,\n    },\n  ],\n  stages: [\n    { id: 'qualified', label: 'Qualified', probability: 0.1 },\n    { id: 'discovery', label: 'Discovery', probability: 0.25 },\n    { id: 'proposal', label: 'Proposal', probability: 0.5 },\n    { id: 'negotiation', label: 'Negotiation', probability: 0.75 },\n  ],\n  title: 'Weighted pipeline',\n}\n\nconst compact = (value: number) => formatCurrency(value, { compact: true })\n\nconst Pipeline4 = (props: Pipeline4Props) => {\n  const { owners = [], stages, errorMessage, status, title } = props\n  const state = getBlockState(status, owners)\n  const ready = state === undefined || state === 'loading'\n  const probability = new Map(stages.map((stage) => [stage.id, stage.probability ?? 0]))\n  const rows = owners.map((owner) => {\n    const weighted = owner.deals.reduce(\n      (sum, deal) => sum + deal.value * (probability.get(deal.stage) ?? 0),\n      0,\n    )\n    return { ...owner, forecast: owner.closed + weighted, weighted }\n  })\n  const teamForecast = rows.reduce((sum, row) => sum + row.forecast, 0)\n  const teamQuota = rows.reduce((sum, row) => sum + row.quota, 0)\n  const covered = rows.filter((row) => row.forecast >= row.quota).length\n  const {\n    description = `Closed deals plus open ones weighted by stage; ${covered} of ${rows.length} reps ${covered === 1 ? 'is' : 'are'} on course for quota.`,\n  } = props\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              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            <div className='flex flex-col gap-3 border-t pt-4 @md:flex-row @md:items-end @md:justify-between'>\n              <p className='flex flex-wrap items-baseline gap-x-2'>\n                <span className='text-4xl font-light tracking-tight tabular-nums'>\n                  {state ? <BlockStateText variant='short' /> : compact(teamForecast)}\n                </span>\n                {!state && (\n                  <span className='text-muted-foreground text-sm'>\n                    of {compact(teamQuota)} team quota,{' '}\n                    {formatPercent(teamQuota > 0 ? teamForecast / teamQuota : 0, {\n                      maximumFractionDigits: 0,\n                    })}\n                  </span>\n                )}\n              </p>\n              {ready && (\n                <div className='flex flex-wrap gap-x-4 gap-y-1'>\n                  <GoalProgressKey label='Closed' shape='progress' />\n                  <GoalProgressKey label='Weighted open' shape='projected' />\n                </div>\n              )}\n            </div>\n            {state === 'loading' && <BlockStateRows rows={owners.length || 4} />}\n            {!state && (\n              <ul className='flex flex-col'>\n                {rows.map((row) => {\n                  const gap = row.quota - row.forecast\n                  return (\n                    <li\n                      key={row.name}\n                      className='flex flex-col gap-2 border-b py-3 first:pt-0'\n                    >\n                      <div className='flex flex-wrap items-center justify-between gap-x-3 gap-y-1'>\n                        <PipelineOwner\n                          avatar={row.avatar}\n                          className='font-medium'\n                          name={row.name}\n                          showName\n                        />\n                        <span className='text-sm whitespace-nowrap tabular-nums'>\n                          {compact(row.forecast)}\n                          <span className='text-muted-foreground'>\n                            {' '}\n                            of {compact(row.quota)}\n                          </span>\n                        </span>\n                      </div>\n                      <GoalProgress\n                        current={row.closed}\n                        projected={row.forecast}\n                        target={row.quota}\n                      />\n                      <p className='text-muted-foreground flex flex-wrap justify-between gap-x-3 gap-y-1 text-xs tabular-nums'>\n                        <span>\n                          {joinDetails(\n                            `${compact(row.closed)} closed`,\n                            `${compact(row.weighted)} weighted open`,\n                          )}\n                        </span>\n                        <StatusLabel\n                          variant='text'\n                          className='text-xs'\n                          tone={gap <= 0 ? 'good' : 'warning'}\n                        >\n                          {gap <= 0\n                            ? `Covers quota by ${compact(-gap)}`\n                            : `Short ${compact(gap)}`}\n                        </StatusLabel>\n                      </p>\n                    </li>\n                  )\n                })}\n              </ul>\n            )}\n            {ready && (\n              <p className='text-muted-foreground text-xs'>\n                Weighted at{' '}\n                {stages\n                  .map(\n                    (stage) =>\n                      `${stage.label} ${formatPercent(stage.probability ?? 0, { maximumFractionDigits: 0 })}`,\n                  )\n                  .join(', ')}\n                .\n              </p>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Pipeline4, exampleProps as pipeline4ExampleProps, type Pipeline4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/pipeline/pipeline-04.tsx"
    }
  ],
  "meta": {
    "shows": "Closed and open deals weighted by the chance each stage closes, per owner, against their quota.",
    "size": "full",
    "usedWith": [
      "pipeline-02",
      "forecast-03",
      "leaderboard-01"
    ],
    "component": "Pipeline4",
    "props": "{ description?: string; owners?: { avatar?: string; closed: number; deals: { stage: string; value: number }[]; name: string; quota: number }[]; stages: { expectedDays?: number; id: string; label: string; probability?: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
