{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pipeline",
  "title": "Pipeline",
  "description": "Primitives for pipelines of work in flight: stage summaries with count, value and weighted value, days in stage with a stuck state, a stage header, an item card, an owner with their photo and age formatting.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/link.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/team.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/pipeline.tsx",
      "content": "'use client'\n\nimport { isPlainClick, Link } from '@/registry/components/dashboardblocks/link'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { PersonAvatar } from '@/registry/components/dashboardblocks/team'\nimport type { ReactNode } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ninterface PipelineStage {\n  expectedDays?: number\n  id: string\n  label: string\n  /** Chance that an item in this stage closes, 0–1. */\n  probability?: number\n}\n\ninterface PipelineItem {\n  enteredStageAt: Date\n  id: string\n  owner?: string\n  /** A photo of the owner, shown in place of their initials. */\n  ownerAvatar?: string\n  stage: string\n  subtitle?: string\n  title: string\n  value?: number\n}\n\ninterface StageSummary extends PipelineStage {\n  count: number\n  stuck: number\n  value: number\n  weighted: number\n}\n\nconst DAY = 86_400_000\n\nfunction getDaysInStage(date: Date, now: Date) {\n  return Math.max(0, Math.floor((now.getTime() - date.getTime()) / DAY))\n}\n\nfunction isStuck(days: number, expectedDays?: number) {\n  return expectedDays !== undefined && days > expectedDays\n}\n\nfunction getStageSummaries(\n  stages: PipelineStage[],\n  items: PipelineItem[],\n  now: Date,\n): StageSummary[] {\n  return stages.map((stage) => {\n    const inStage = items.filter((item) => item.stage === stage.id)\n    const value = inStage.reduce((sum, item) => sum + (item.value ?? 0), 0)\n    return {\n      ...stage,\n      count: inStage.length,\n      stuck: inStage.filter((item) =>\n        isStuck(getDaysInStage(item.enteredStageAt, now), stage.expectedDays),\n      ).length,\n      value,\n      weighted: value * (stage.probability ?? 0),\n    }\n  })\n}\n\nfunction getStageColor(index: number, count: number) {\n  const share = count > 1 ? index / (count - 1) : 1\n  return `color-mix(in oklab, var(--color-chart-2) ${Math.round(50 + share * 50)}%, var(--color-card))`\n}\n\nfunction formatAge(days: number, style: 'short' | 'long' = 'short') {\n  const [amount, unit] =\n    days < 28\n      ? [days, 'd']\n      : days < 90\n        ? [Math.floor(days / 7), 'w']\n        : [Math.floor(days / 30), 'mo']\n  if (style === 'short') return `${amount}${unit}`\n  const word = unit === 'd' ? 'day' : unit === 'w' ? 'week' : 'month'\n  return `${amount} ${word}${amount === 1 ? '' : 's'}`\n}\n\nfunction PipelineAge({\n  className,\n  days,\n  expectedDays,\n}: {\n  className?: string\n  days: number\n  expectedDays?: number\n}) {\n  const stuck = isStuck(days, expectedDays)\n  return (\n    <span\n      className={cn(\n        'text-xs whitespace-nowrap tabular-nums',\n        stuck\n          ? 'font-medium text-orange-700 dark:text-orange-400'\n          : 'text-muted-foreground',\n        className,\n      )}\n    >\n      {stuck ? `Stuck ${formatAge(days, 'long')}` : formatAge(days, 'long')}\n      <span className='sr-only'>\n        {' '}\n        in stage{stuck && `, over the ${expectedDays}-day limit`}\n      </span>\n    </span>\n  )\n}\n\nfunction PipelineOwner({\n  avatar,\n  className,\n  name,\n  showName = false,\n}: {\n  avatar?: string\n  className?: string\n  name: string\n  showName?: boolean\n}) {\n  return (\n    <span className={cn('inline-flex min-w-0 items-center gap-2', className)}>\n      <PersonAvatar person={{ avatar, name }} size='sm' />\n      <span className={cn(showName ? 'truncate text-sm' : 'sr-only')}>\n        {showName ? name : `Owner: ${name}`}\n      </span>\n    </span>\n  )\n}\n\nfunction PipelineStageHeader({\n  className,\n  color,\n  count,\n  id,\n  label,\n  total,\n}: {\n  className?: string\n  color: string\n  /** Leave out while the items load. */\n  count?: number\n  /** Lets the column's list point at the heading with `aria-labelledby`. */\n  id?: string\n  label: string\n  total?: string\n}) {\n  return (\n    <div className={cn('flex flex-col gap-0.5', className)}>\n      <h3 id={id} className='flex items-center gap-2 text-sm font-medium'>\n        <span\n          aria-hidden\n          className='size-2.5 shrink-0 rounded-full'\n          style={{ backgroundColor: color }}\n        />\n        <span className='truncate'>{label}</span>\n        {count !== undefined && (\n          <Tag className='ml-auto'>\n            {count}\n            <span className='sr-only'> {count === 1 ? 'item' : 'items'}</span>\n          </Tag>\n        )}\n      </h3>\n      {total !== undefined && (\n        <p className='text-muted-foreground pl-4.5 text-xs tabular-nums'>\n          <span className='sr-only'>Total </span>\n          {total}\n        </p>\n      )}\n    </div>\n  )\n}\n\ninterface PipelineCardProps {\n  action?: ReactNode\n  className?: string\n  days: number\n  expectedDays?: number\n  /** The item's own page. With it, the whole card is a link, so it opens in a new tab with Cmd or Ctrl. */\n  href?: string\n  /** Opens the item, such as in a panel beside the board: the whole card is the button, or with `href`, what a plain click on the link does. */\n  onOpen?: () => void\n  /** Whether the item is open beside the board, which draws it muted. */\n  open?: boolean\n  owner?: string\n  ownerAvatar?: string\n  subtitle?: string\n  title: string\n  value?: string\n}\n\nfunction PipelineCard({\n  action,\n  className,\n  days,\n  expectedDays,\n  href,\n  onOpen,\n  open = false,\n  owner,\n  ownerAvatar,\n  subtitle,\n  title,\n  value,\n}: PipelineCardProps) {\n  const opens = onOpen !== undefined || href !== undefined\n  const trigger = {\n    'aria-current': open || undefined,\n    'aria-label': subtitle ? `${title}, ${subtitle}` : undefined,\n    className:\n      'cursor-pointer text-start text-sm leading-snug font-medium outline-none after:absolute after:inset-0 after:rounded-xl',\n    'data-slot': 'pipeline-card-trigger',\n  }\n  return (\n    <div\n      data-open={open || undefined}\n      className={cn(\n        'bg-muted/50 flex flex-col gap-3 rounded-xl p-3',\n        opens &&\n          'has-[[data-slot=pipeline-card-trigger]:focus-visible]:ring-ring/50 hover:bg-muted data-open:bg-muted relative transition-colors has-[[data-slot=pipeline-card-trigger]:focus-visible]:ring-3',\n        className,\n      )}\n    >\n      <div className='flex items-start justify-between gap-2'>\n        <div className='flex min-w-0 flex-col gap-0.5'>\n          {href !== undefined ? (\n            <Link\n              {...trigger}\n              href={href}\n              onClick={(event) => {\n                if (!onOpen || !isPlainClick(event)) return\n                event.preventDefault()\n                onOpen()\n              }}\n            >\n              {title}\n            </Link>\n          ) : onOpen ? (\n            <button type='button' {...trigger} onClick={onOpen}>\n              {title}\n            </button>\n          ) : (\n            <p className='text-sm leading-snug font-medium'>{title}</p>\n          )}\n          {subtitle && <p className='text-muted-foreground text-xs'>{subtitle}</p>}\n        </div>\n        {action && <div className='relative z-10 -mt-1 -mr-1 shrink-0'>{action}</div>}\n      </div>\n      <div className='flex items-center gap-2'>\n        {value !== undefined && (\n          <span className='text-sm font-medium tabular-nums'>{value}</span>\n        )}\n        <PipelineAge className='ml-auto' days={days} expectedDays={expectedDays} />\n        {owner && <PipelineOwner avatar={ownerAvatar} name={owner} />}\n      </div>\n    </div>\n  )\n}\n\nexport {\n  PipelineAge,\n  PipelineCard,\n  PipelineOwner,\n  PipelineStageHeader,\n  formatAge,\n  getDaysInStage,\n  getStageColor,\n  getStageSummaries,\n  isStuck,\n}\n\nexport type { PipelineCardProps, PipelineItem, PipelineStage, StageSummary }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/pipeline.tsx"
    }
  ],
  "type": "registry:component"
}
