{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pipeline-02",
  "description": "Open value across stages, with each stage as a segment sized by value or by count, and the three largest open deals.",
  "registryDependencies": [
    "card",
    "button",
    "button-group",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/breakdown.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/pipeline.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/pipeline/pipeline-02.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 { BreakdownBar } from '@/registry/components/dashboardblocks/breakdown'\nimport { ChartPlaceholder } from '@/registry/components/dashboardblocks/chart'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport { getStageColor } from '@/registry/components/dashboardblocks/pipeline'\nimport {\n  DataTableListItem,\n  DataTableRowLink,\n} from '@/registry/components/dashboardblocks/table'\nimport {\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport { type ReactNode, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { ButtonGroup } from '@/components/ui/button-group'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface StageTotal {\n  count: number\n  label: string\n  value: number\n}\n\ninterface LargestItem {\n  /** A second line, such as what the deal is for. */\n  detail?: string\n  /** The item's page, such as the deal: the whole row opens it. */\n  href?: string\n  id: string\n  name: string\n  /** After the detail, such as `Proposal`. */\n  stage?: string\n  value: number\n}\n\ninterface Pipeline2Props extends BlockStateProps {\n  /** After the measure buttons, such as a link to every deal. */\n  action?: ReactNode\n  /** Defaults to a sentence naming the stage that holds the most value. */\n  description?: string\n  /** Drawn first inside the Card, such as a `CardStyleIcon` for a card style's top rim. */\n  icon?: ReactNode\n  /** The largest open items, listed under the stages, largest first. Leave out for none. */\n  largest?: LargestItem[]\n  /** What the stages hold, such as `deals`. @default 'items' */\n  noun?: string\n  /** The noun for one, such as `deal`. @default noun */\n  singular?: string\n  /** Leave out, or pass none, to show the empty state. */\n  stages?: StageTotal[]\n  title: string\n}\n\nconst exampleProps: Pipeline2Props = {\n  largest: [\n    {\n      detail: 'Enterprise plan',\n      stage: 'Negotiation',\n      id: 'northwind',\n      name: 'Northwind Health',\n      value: 186_000,\n    },\n    {\n      detail: 'Platform renewal',\n      stage: 'Proposal',\n      id: 'acme',\n      name: 'Acme Logistics',\n      value: 142_500,\n    },\n    {\n      detail: 'New region',\n      stage: 'Discovery',\n      id: 'globex',\n      name: 'Globex Retail',\n      value: 98_000,\n    },\n  ],\n  noun: 'deals',\n  singular: 'deal',\n  stages: [\n    { count: 48, label: 'Lead', value: 1_240_000 },\n    { count: 31, label: 'Qualified', value: 982_000 },\n    { count: 22, label: 'Discovery', value: 861_500 },\n    { count: 14, label: 'Proposal', value: 724_000 },\n    { count: 7, label: 'Negotiation', value: 409_000 },\n  ],\n  title: 'Open pipeline',\n}\n\ntype Measure = 'value' | 'count'\n\nconst MEASURES: { label: string; value: Measure }[] = [\n  { label: 'Value', value: 'value' },\n  { label: 'Count', value: 'count' },\n]\n\nconst Pipeline2 = (props: Pipeline2Props) => {\n  const {\n    action,\n    errorMessage,\n    icon,\n    largest = [],\n    noun = 'items',\n    singular,\n    stages = [],\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, stages)\n  const [measure, setMeasure] = useState<Measure>('value')\n\n  const totalCount = stages.reduce((sum, stage) => sum + stage.count, 0)\n  const totalValue = stages.reduce((sum, stage) => sum + stage.value, 0)\n  const total = measure === 'value' ? totalValue : totalCount\n  const biggest = stages.reduce<StageTotal | undefined>(\n    (best, stage) => (best && best.value >= stage.value ? best : stage),\n    undefined,\n  )\n  const last = stages[stages.length - 1]\n  const {\n    description = biggest && last\n      ? `${biggest.label} holds the most value; ${formatCurrency(last.value, { compact: true })} is in ${last.label}, the last stage before closing.`\n      : `No open ${noun}.`,\n  } = props\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        {icon}\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-wrap 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                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                </BlockReady>\n              </div>\n              <div className='flex items-center gap-2'>\n                <ButtonGroup aria-label='Size stages by'>\n                  {MEASURES.map((option) => (\n                    <Button\n                      key={option.value}\n                      aria-pressed={measure === option.value}\n                      disabled={state !== undefined}\n                      className='not-aria-pressed:text-muted-foreground aria-pressed:bg-muted aria-pressed:text-foreground'\n                      onClick={() => setMeasure(option.value)}\n                      size='sm'\n                      variant='outline'\n                    >\n                      {option.label}\n                    </Button>\n                  ))}\n                </ButtonGroup>\n                {action}\n              </div>\n            </header>\n            <p className='flex flex-wrap items-baseline gap-x-2 border-t pt-4'>\n              <span className='text-4xl font-light tracking-tight tabular-nums'>\n                {state ? (\n                  <BlockStateText variant='short' />\n                ) : (\n                  formatCurrency(totalValue, { compact: true })\n                )}\n              </span>\n              {!state && (\n                <span className='text-muted-foreground text-sm'>\n                  in {formatNumber(totalCount)} open{' '}\n                  {totalCount === 1 ? (singular ?? noun) : noun}\n                </span>\n              )}\n            </p>\n            {state === 'loading' && (\n              <>\n                <ChartPlaceholder className='rounded-full' height={12} />\n                <BlockStateRows rows={3} />\n              </>\n            )}\n            {!state && (\n              <>\n                <BreakdownBar\n                  segments={stages.map((stage, index) => ({\n                    color: getStageColor(index, stages.length),\n                    label: stage.label,\n                    value: measure === 'value' ? stage.value : stage.count,\n                  }))}\n                />\n                <ol className='grid grid-cols-2 gap-x-4 gap-y-3 @md:grid-cols-3 @2xl:auto-cols-fr @2xl:grid-flow-col @2xl:grid-cols-none'>\n                  {stages.map((stage, index) => {\n                    const amount = measure === 'value' ? stage.value : stage.count\n                    return (\n                      <li key={stage.label} className='flex min-w-0 flex-col gap-0.5'>\n                        <span className='flex items-center gap-1.5 text-xs font-medium'>\n                          <span\n                            aria-hidden\n                            className='size-2 shrink-0 rounded-full'\n                            style={{\n                              backgroundColor: getStageColor(index, stages.length),\n                            }}\n                          />\n                          <span className='truncate'>{stage.label}</span>\n                          <span className='text-muted-foreground ml-auto font-normal tabular-nums'>\n                            {formatPercent(total > 0 ? amount / total : 0, {\n                              maximumFractionDigits: 0,\n                            })}\n                            <span className='sr-only'> of {measure}</span>\n                          </span>\n                        </span>\n                        <span className='pl-3.5 text-sm tabular-nums'>\n                          {formatCurrency(stage.value, { compact: true })}\n                        </span>\n                        <span className='text-muted-foreground pl-3.5 text-xs tabular-nums'>\n                          {formatNumber(stage.count)}{' '}\n                          {stage.count === 1 ? (singular ?? noun) : noun}\n                        </span>\n                      </li>\n                    )\n                  })}\n                </ol>\n                {largest.length > 0 && (\n                  <div className='flex flex-col gap-1 border-t pt-4'>\n                    <h3 className='text-sm font-medium'>Largest open {noun}</h3>\n                    <ul className='divide-y'>\n                      {largest.map((item) => (\n                        <DataTableListItem\n                          key={item.id}\n                          className='flex items-baseline justify-between gap-3 py-2.5'\n                        >\n                          <span className='flex min-w-0 flex-col'>\n                            {item.href ? (\n                              <DataTableRowLink href={item.href} className='text-sm'>\n                                {item.name}\n                              </DataTableRowLink>\n                            ) : (\n                              <span className='truncate text-sm font-medium'>\n                                {item.name}\n                              </span>\n                            )}\n                            {(item.detail || item.stage) && (\n                              <Details className='text-muted-foreground truncate text-xs'>\n                                {item.detail}\n                                {item.stage}\n                              </Details>\n                            )}\n                          </span>\n                          <span className='text-sm tabular-nums'>\n                            {formatCurrency(item.value)}\n                          </span>\n                        </DataTableListItem>\n                      ))}\n                    </ul>\n                  </div>\n                )}\n              </>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Pipeline2, exampleProps as pipeline2ExampleProps, type Pipeline2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/pipeline/pipeline-02.tsx"
    }
  ],
  "meta": {
    "shows": "Open value across stages, with each stage as a segment sized by value or by count, and the three largest open deals.",
    "size": "full",
    "usedWith": [
      "pipeline-01",
      "funnel-01",
      "stat-group-02"
    ],
    "component": "Pipeline2",
    "props": "{ action?: ReactNode; description?: string; icon?: ReactNode; largest?: { detail?: string; href?: string; id: string; name: string; stage?: string; value: number }[]; noun?: string; singular?: string; stages?: { count: number; label: string; value: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
