{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "deals-pipeline-board",
  "title": "Deals Pipeline Board",
  "description": "A CRM sales pipeline: open pipeline, weighted forecast, won and win-rate tiles, owner filters, Lead → Qualified → Proposal → Negotiation → Won columns with totals and win probability, deal cards with value, owner and close date (stale ones flagged), drag and drop with a lost drop zone, a celebration burst on won deals, keyboard moves and undo.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/deals-pipeline-board/deals-pipeline-board.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type DealStage = \"lead\" | \"qualified\" | \"proposal\" | \"negotiation\" | \"won\";\n\nexport interface Deal {\n  id: string;\n  company: string;\n  title: string;\n  value: number;\n  stage: DealStage;\n  owner: string;\n  close: string;\n  color: string;\n  stale?: boolean;\n}\n\nexport interface DealsPipelineBoardProps {\n  deals?: Deal[];\n  currency?: string;\n  onMove?: (id: string, stage: DealStage | \"lost\") => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", col: \"#101010\", card: \"#171717\", cardHi: \"#1C1C1C\", border: \"rgba(255,255,255,0.08)\", track: \"rgba(255,255,255,0.08)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", good: \"#4ADE80\", bad: \"#F87171\", warn: \"#FBBF24\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", col: \"#F2F1EE\", card: \"#FFFFFF\", cardHi: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", track: \"rgba(10,10,10,0.08)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", good: \"#15803D\", bad: \"#DC2626\", warn: \"#B45309\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst STAGES: { id: DealStage; label: string; prob: number }[] = [\n  { id: \"lead\", label: \"Lead\", prob: 0.1 },\n  { id: \"qualified\", label: \"Qualified\", prob: 0.25 },\n  { id: \"proposal\", label: \"Proposal\", prob: 0.5 },\n  { id: \"negotiation\", label: \"Negotiation\", prob: 0.75 },\n  { id: \"won\", label: \"Won\", prob: 1 },\n];\nconst OWNERS: Record<string, string> = { LH: \"#F472B6\", BC: \"#60A5FA\", MP: \"#FBBF24\", IM: \"#34D399\" };\nconst D = (id: string, company: string, title: string, value: number, stage: DealStage, owner: string, close: string, color: string, stale = false): Deal => ({ id, company, title, value, stage, owner, close, color, stale });\nconst DEALS: Deal[] = [\n  D(\"d1\", \"Lumio\", \"Team plan · 40 seats\", 9600, \"lead\", \"BC\", \"Dec 12\", \"#A78BFA\"),\n  D(\"d2\", \"Northwind\", \"Analytics add-on\", 4200, \"lead\", \"IM\", \"Dec 20\", \"#60A5FA\"),\n  D(\"d3\", \"Pellucid\", \"Enterprise pilot\", 18000, \"qualified\", \"LH\", \"Dec 18\", \"#22D3EE\"),\n  D(\"d4\", \"Orbitly\", \"Annual upgrade\", 7800, \"qualified\", \"MP\", \"Nov 30\", \"#FB923C\", true),\n  D(\"d5\", \"Kiteworks\", \"Platform license\", 32000, \"proposal\", \"LH\", \"Dec 5\", \"#34D399\"),\n  D(\"d6\", \"Halden\", \"Design team · 25 seats\", 6000, \"proposal\", \"BC\", \"Dec 9\", \"#F472B6\"),\n  D(\"d7\", \"Marktplatz\", \"Multi-store rollout\", 24500, \"negotiation\", \"MP\", \"Nov 28\", \"#FBBF24\"),\n  D(\"d8\", \"Velo Rides\", \"Fleet dashboard\", 11200, \"negotiation\", \"IM\", \"Dec 2\", \"#F87171\", true),\n  D(\"d9\", \"Skyline Air\", \"Ops suite\", 15400, \"won\", \"LH\", \"Nov 14\", \"#93C5FD\"),\n];\n\ntype Drag = { id: string; x: number; y: number; offX: number; offY: number; w: number; sx: number; sy: number; active: boolean; over: DealStage | \"lost\" | null };\n\nexport function DealsPipelineBoard({ deals: initial = DEALS, currency = \"€\", onMove, theme = \"dark\", className }: DealsPipelineBoardProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const [deals, setDeals] = React.useState(initial);\n  const [lost, setLost] = React.useState(2);\n  const [owner, setOwner] = React.useState<string | null>(null);\n  const [drag, setDrag] = React.useState<Drag | null>(null);\n  const [burst, setBurst] = React.useState<string | null>(null);\n  const [toast, setToast] = React.useState<{ text: string; undo: { deals: Deal[]; lost: number } } | null>(null);\n  const boardRef = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => {\n    if (!toast) return;\n    const t = setTimeout(() => setToast(null), 3500);\n    return () => clearTimeout(t);\n  }, [toast]);\n  React.useEffect(() => {\n    if (!burst) return;\n    const t = setTimeout(() => setBurst(null), 1200);\n    return () => clearTimeout(t);\n  }, [burst]);\n\n  const money = (n: number) => `${currency}${n >= 1000 ? `${(n / 1000).toFixed(n % 1000 ? 1 : 0)}k` : n}`;\n  const shown = deals.filter((d) => !owner || d.owner === owner);\n  const open = deals.filter((d) => d.stage !== \"won\");\n  const pipeline = open.reduce((a, d) => a + d.value, 0);\n  const weighted = open.reduce((a, d) => a + d.value * STAGES.find((s) => s.id === d.stage)!.prob, 0);\n  const wonCount = deals.filter((d) => d.stage === \"won\").length;\n  const winRate = wonCount + lost ? wonCount / (wonCount + lost) : 0;\n\n  const move = (id: string, to: DealStage | \"lost\") => {\n    const d = deals.find((x) => x.id === id);\n    if (!d || d.stage === to) return;\n    const undo = { deals, lost };\n    if (to === \"lost\") {\n      setDeals((l) => l.filter((x) => x.id !== id));\n      setLost((n) => n + 1);\n      setToast({ text: `${d.company} marked as lost`, undo });\n    } else {\n      setDeals((l) => [{ ...d, stage: to, stale: false }, ...l.filter((x) => x.id !== id)]);\n      if (to === \"won\") setBurst(id);\n      setToast({ text: to === \"won\" ? `🎉 ${d.company} won · ${money(d.value)}` : `${d.company} moved to ${STAGES.find((s) => s.id === to)!.label}`, undo });\n    }\n    onMove?.(id, to);\n  };\n\n  const local = (cx: number, cy: number) => {\n    const b = boardRef.current;\n    if (!b) return { x: cx, y: cy, s: 1 };\n    const r = b.getBoundingClientRect();\n    const s = r.width / b.offsetWidth || 1;\n    return { x: (cx - r.left) / s + b.scrollLeft, y: (cy - r.top) / s, s };\n  };\n  const onDown = (e: React.PointerEvent<HTMLElement>, d: Deal) => {\n    if (e.button !== 0 || e.pointerType === \"touch\") return;\n    const rect = e.currentTarget.getBoundingClientRect();\n    const pt = local(e.clientX, e.clientY);\n    e.currentTarget.setPointerCapture(e.pointerId);\n    setDrag({ id: d.id, x: pt.x, y: pt.y, offX: (e.clientX - rect.left) / pt.s, offY: (e.clientY - rect.top) / pt.s, w: rect.width / pt.s, sx: e.clientX, sy: e.clientY, active: false, over: d.stage });\n  };\n  const onMoveP = (e: React.PointerEvent<HTMLElement>) => {\n    if (!drag) return;\n    const pt = local(e.clientX, e.clientY);\n    const active = drag.active || Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) > 5;\n    const el = document.elementFromPoint(e.clientX, e.clientY)?.closest<HTMLElement>(\"[data-drop]\");\n    setDrag({ ...drag, x: pt.x, y: pt.y, active, over: (el?.dataset.drop as DealStage | \"lost\") ?? null });\n  };\n  const onUp = (d: Deal) => {\n    if (drag?.active && drag.over) move(d.id, drag.over);\n    setDrag(null);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.col } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const dragged = drag?.active ? deals.find((d) => d.id === drag.id) : null;\n  const stageIdx = (s: DealStage) => STAGES.findIndex((x) => x.id === s);\n\n  const body = (d: Deal) => (\n    <>\n      <div className=\"flex items-center gap-2\">\n        <span className=\"grid h-6 w-6 shrink-0 place-items-center rounded-md text-[11px] font-bold text-[#0A0A0A]\" style={{ background: d.color }} aria-hidden=\"true\">\n          {d.company[0]}\n        </span>\n        <span className=\"min-w-0 flex-1 truncate text-[13px] font-medium\">{d.company}</span>\n        <span className=\"grid h-5 w-5 shrink-0 place-items-center rounded-full text-[8.5px] font-bold text-[#0A0A0A]\" style={{ background: OWNERS[d.owner] ?? p.muted }} title={`Owner ${d.owner}`}>\n          {d.owner}\n        </span>\n      </div>\n      <p className=\"m-0 mt-1.5 truncate text-[11.5px]\" style={{ color: p.faint }}>\n        {d.title}\n      </p>\n      <div className=\"mt-2 flex items-baseline justify-between gap-2\">\n        <span className=\"text-[14px] font-semibold tabular-nums\">{money(d.value)}</span>\n        <span className=\"text-[11px] tabular-nums\" style={{ color: d.stale ? p.warn : p.faint }}>\n          {d.stale ? \"▲ \" : \"\"}\n          {d.stage === \"won\" ? `Won ${d.close}` : `Close ${d.close}`}\n        </span>\n      </div>\n    </>\n  );\n\n  return (\n    <section className={cn(\"@container relative w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-7xl px-4 py-10 @[640px]:px-6\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em]\">Deals</h2>\n            <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }}>\n              Q4 pipeline · {open.length} open deals\n            </p>\n          </div>\n          <div role=\"group\" aria-label=\"Filter by owner\" className=\"flex items-center gap-1\">\n            {Object.keys(OWNERS).map((o) => (\n              <button key={o} type=\"button\" aria-pressed={owner === o} onClick={() => setOwner((x) => (x === o ? null : o))} className={cn(\"grid h-8 w-8 cursor-pointer place-items-center rounded-full border-2 text-[10.5px] font-bold text-[#0A0A0A] transition-opacity\", focus)} style={{ background: OWNERS[o], borderColor: owner === o ? p.text : \"transparent\", opacity: owner && owner !== o ? 0.4 : 1, ...ring }} aria-label={`Only ${o}'s deals`}>\n                {o}\n              </button>\n            ))}\n          </div>\n        </div>\n\n        <dl className=\"mt-4 grid grid-cols-2 gap-2.5 @[640px]:grid-cols-4\">\n          {[\n            [\"Open pipeline\", `${currency}${pipeline.toLocaleString(\"en-US\")}`],\n            [\"Weighted forecast\", `${currency}${Math.round(weighted).toLocaleString(\"en-US\")}`],\n            [\"Won this quarter\", `${currency}${deals.filter((d) => d.stage === \"won\").reduce((a, d) => a + d.value, 0).toLocaleString(\"en-US\")}`],\n            [\"Win rate\", `${Math.round(winRate * 100)}%`],\n          ].map(([k, v]) => (\n            <div key={k} className=\"rounded-xl border px-3.5 py-3\" style={{ borderColor: p.border, background: p.col }}>\n              <dt className=\"text-[11.5px]\" style={{ color: p.muted }}>\n                {k}\n              </dt>\n              <motion.dd key={v} initial={reduce ? false : { opacity: 0.4, y: 3 }} animate={{ opacity: 1, y: 0 }} className=\"m-0 mt-1 text-[19px] font-semibold tracking-[-0.02em] tabular-nums\">\n                {v}\n              </motion.dd>\n            </div>\n          ))}\n        </dl>\n\n        <div ref={boardRef} className=\"relative mt-4 -mx-4 overflow-x-auto px-4 pb-2 [scrollbar-width:thin] @[640px]:-mx-6 @[640px]:px-6\">\n          <div className=\"grid min-w-[900px] grid-cols-5 gap-3\">\n            {STAGES.map((s) => {\n              const list = shown.filter((d) => d.stage === s.id);\n              const total = deals.filter((d) => d.stage === s.id).reduce((a, d) => a + d.value, 0);\n              const isOver = drag?.active && drag.over === s.id && dragged?.stage !== s.id;\n              const won = s.id === \"won\";\n              return (\n                <div key={s.id} data-drop={s.id} role=\"group\" aria-label={`${s.label}, ${money(total)}`} className=\"flex min-h-[380px] flex-col rounded-xl border p-2 transition-colors\" style={{ background: isOver ? (won ? `${p.good}14` : p.cardHi) : p.col, borderColor: isOver ? (won ? p.good : p.ring.replace(/[\\d.]+\\)$/, \"0.4)\")) : p.border }}>\n                  <div className=\"px-1.5 pt-1 pb-2.5\">\n                    <div className=\"flex items-center gap-2\">\n                      <span className=\"text-[12.5px] font-semibold\" style={{ color: won ? p.good : p.text }}>\n                        {s.label}\n                      </span>\n                      <span className=\"rounded-full px-1.5 text-[11px] tabular-nums\" style={{ background: p.track, color: p.muted }}>\n                        {deals.filter((d) => d.stage === s.id).length}\n                      </span>\n                      <span className=\"ml-auto text-[11px] tabular-nums\" style={{ color: p.faint }}>\n                        {Math.round(s.prob * 100)}%\n                      </span>\n                    </div>\n                    <motion.p key={total} initial={reduce ? false : { scale: 1.08 }} animate={{ scale: 1 }} className=\"m-0 mt-1 origin-left text-[13px] font-semibold tabular-nums\" style={{ color: p.muted }}>\n                      {money(total)}\n                    </motion.p>\n                    <span className=\"mt-1.5 block h-1 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                      <motion.span className=\"block h-full rounded-full\" initial={false} animate={{ width: `${(total / Math.max(1, deals.reduce((a, x) => a + x.value, 0))) * 100}%` }} style={{ background: won ? p.good : p.muted }} />\n                    </span>\n                  </div>\n                  <ul className=\"m-0 flex flex-1 list-none flex-col gap-2 p-0\">\n                    <AnimatePresence initial={false}>\n                      {list.map((d) => {\n                        const lifted = drag?.active && drag.id === d.id;\n                        return (\n                          <motion.li key={d.id} layout={reduce ? false : \"position\"} initial={reduce ? false : { opacity: 0, scale: 0.96 }} animate={{ opacity: lifted ? 0.35 : 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.96 }} transition={{ duration: 0.2 }} className=\"relative\">\n                            <div\n                              role=\"button\"\n                              tabIndex={0}\n                              aria-label={`${d.company}, ${d.title}, ${money(d.value)}, ${s.label}. Shift and arrow keys move it.`}\n                              onPointerDown={(e) => onDown(e, d)}\n                              onPointerMove={onMoveP}\n                              onPointerUp={() => onUp(d)}\n                              onPointerCancel={() => setDrag(null)}\n                              onKeyDown={(e) => {\n                                if (!e.shiftKey) return;\n                                const i = stageIdx(d.stage);\n                                if (e.key === \"ArrowRight\" && i < STAGES.length - 1) move(d.id, STAGES[i + 1].id);\n                                if (e.key === \"ArrowLeft\" && i > 0) move(d.id, STAGES[i - 1].id);\n                              }}\n                              className={cn(\"cursor-grab rounded-lg border p-2.5 select-none active:cursor-grabbing\", focus)}\n                              style={{ background: p.card, borderColor: won ? `${p.good}44` : p.border, ...ring }}\n                            >\n                              {body(d)}\n                            </div>\n                            <AnimatePresence>\n                              {burst === d.id && !reduce && (\n                                <motion.span key=\"burst\" className=\"pointer-events-none absolute inset-0\" aria-hidden=\"true\">\n                                  {Array.from({ length: 10 }, (_, k) => {\n                                    const a = (k / 10) * Math.PI * 2;\n                                    return <motion.span key={k} className=\"absolute top-1/2 left-1/2 h-1.5 w-1.5 rounded-full\" style={{ background: k % 2 ? p.good : \"#FBBF24\" }} initial={{ x: 0, y: 0, opacity: 1 }} animate={{ x: Math.cos(a) * 70, y: Math.sin(a) * 44, opacity: 0 }} transition={{ duration: 0.8, ease: \"easeOut\" }} />;\n                                  })}\n                                </motion.span>\n                              )}\n                            </AnimatePresence>\n                          </motion.li>\n                        );\n                      })}\n                    </AnimatePresence>\n                    {list.length === 0 && (\n                      <li className=\"grid flex-1 place-items-center rounded-lg border border-dashed text-[11.5px]\" style={{ borderColor: p.border, color: p.faint }}>\n                        {owner ? \"No deals for this owner\" : \"Drop deals here\"}\n                      </li>\n                    )}\n                  </ul>\n                </div>\n              );\n            })}\n          </div>\n\n          <AnimatePresence>\n            {drag?.active && (\n              <motion.div key=\"lost\" data-drop=\"lost\" initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: 8 }} className=\"mt-3 grid h-14 min-w-[900px] place-items-center rounded-xl border border-dashed text-[12.5px] font-medium transition-colors\" style={{ borderColor: drag.over === \"lost\" ? p.bad : p.border, background: drag.over === \"lost\" ? `${p.bad}14` : \"transparent\", color: drag.over === \"lost\" ? p.bad : p.faint }}>\n                Drop here to mark as lost\n              </motion.div>\n            )}\n          </AnimatePresence>\n\n          {dragged && drag && (\n            <div className=\"pointer-events-none absolute top-0 left-0 z-20 rounded-lg border p-2.5 shadow-2xl\" style={{ width: drag.w, transform: `translate(${drag.x - drag.offX}px, ${drag.y - drag.offY}px) rotate(2deg)`, background: p.cardHi, borderColor: p.ring.replace(/[\\d.]+\\)$/, \"0.4)\"), color: p.text }} aria-hidden=\"true\">\n              {body(dragged)}\n            </div>\n          )}\n        </div>\n        <p className=\"m-0 mt-2 text-[11.5px]\" style={{ color: p.faint }}>\n          Drag deals between stages. Focus a card and press Shift + ← / → to move it with the keyboard.\n        </p>\n      </div>\n\n      <AnimatePresence>\n        {toast && (\n          <motion.div key={toast.text} role=\"status\" initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"absolute bottom-5 left-1/2 z-30 flex -translate-x-1/2 items-center gap-3 rounded-full border py-1.5 pr-1.5 pl-3.5 text-[12.5px] whitespace-nowrap shadow-xl\" style={{ background: p.card, borderColor: p.border }}>\n            {toast.text}\n            <button\n              type=\"button\"\n              onClick={() => {\n                setDeals(toast.undo.deals);\n                setLost(toast.undo.lost);\n                setToast(null);\n              }}\n              className={cn(\"h-6 cursor-pointer rounded-full border-0 px-2.5 text-[12px] font-medium\", focus)}\n              style={{ background: p.on, color: p.onText, ...ring }}\n            >\n              Undo\n            </button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default DealsPipelineBoard;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}