{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "assign-to-bot-board",
  "title": "Assign to Bot Board",
  "description": "Hand out work to AI bots on a small board: drag a task to a bot, see who has the skills and room for it, or let the rest assign themselves.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/assign-to-bot-board/assign-to-bot-board.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BoardTask {\n  id: string;\n  title: string;\n  /** What it needs, matched against a bot's skills. */\n  skill: string;\n  /** Work points. */\n  size: number;\n}\n\nexport interface BoardBot {\n  id: string;\n  name: string;\n  skills: string[];\n  /** Work points it can hold. */\n  capacity: number;\n}\n\nexport interface AssignToBotBoardProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  tasks?: BoardTask[];\n  bots?: BoardBot[];\n  onAssign?: (task: BoardTask, bot: BoardBot | null) => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst QUEUE = \"queue\";\nconst CARD = 54;\nconst SLOTS = 4;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    column: \"#0F1011\",\n    item: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    track: \"rgba(255,255,255,0.1)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    shadow: \"0 10px 28px rgba(0,0,0,0.55)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    column: \"#F7F8F8\",\n    item: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    track: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    shadow: \"0 10px 28px rgba(8,9,10,0.16)\",\n  },\n};\n\nconst DEFAULT_TASKS: BoardTask[] = [\n  { id: \"t1\", title: \"Fix the login redirect\", skill: \"Code\", size: 3 },\n  { id: \"t2\", title: \"Write the March newsletter\", skill: \"Writing\", size: 2 },\n  { id: \"t3\", title: \"Summarise churn interviews\", skill: \"Research\", size: 2 },\n  { id: \"t4\", title: \"Update API examples\", skill: \"Code\", size: 1 },\n];\n\nconst DEFAULT_BOTS: BoardBot[] = [\n  { id: \"patch\", name: \"Patch\", skills: [\"Code\"], capacity: 4 },\n  { id: \"aria\", name: \"Aria\", skills: [\"Writing\"], capacity: 3 },\n  { id: \"scout\", name: \"Scout\", skills: [\"Research\", \"Writing\"], capacity: 3 },\n];\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle cx={r} cy={r} r={r} style={{ fill: color }} />\n    </svg>\n  );\n}\n\nexport function AssignToBotBoard({\n  theme = \"dark\",\n  title = \"Assign this week's work\",\n  tasks = DEFAULT_TASKS,\n  bots = DEFAULT_BOTS,\n  onAssign,\n  className,\n  style,\n  ...rest\n}: AssignToBotBoardProps) {\n  const c = PALETTES[theme];\n  const [place, setPlace] = React.useState<Record<string, string>>({});\n  const [picked, setPicked] = React.useState<string | null>(null);\n  const [drag, setDrag] = React.useState<{\n    id: string;\n    dx: number;\n    dy: number;\n  } | null>(null);\n  const [over, setOver] = React.useState<string | null>(null);\n  const start = React.useRef({ x: 0, y: 0 });\n  const columns = React.useRef(new Map<string, HTMLDivElement>());\n\n  const where = (t: BoardTask) => place[t.id] ?? QUEUE;\n  const inColumn = (id: string) => tasks.filter((t) => where(t) === id);\n  const load = (bot: BoardBot) =>\n    inColumn(bot.id).reduce((sum, t) => sum + t.size, 0);\n  const waiting = inColumn(QUEUE).length;\n  const active = tasks.find((t) => t.id === (drag?.id ?? picked));\n\n  const verdict = (bot: BoardBot, task: BoardTask) => {\n    if (where(task) === bot.id) return \"Assigned\";\n    if (load(bot) + task.size > bot.capacity) return \"Full\";\n    return bot.skills.includes(task.skill) ? \"Good fit\" : \"Wrong skills\";\n  };\n  const allowed = (bot: BoardBot, task: BoardTask) =>\n    verdict(bot, task) === \"Good fit\";\n\n  const assign = (task: BoardTask, target: string) => {\n    const bot = bots.find((b) => b.id === target);\n    if (bot && !allowed(bot, task)) return;\n    setPlace((prev) => ({ ...prev, [task.id]: target }));\n    setPicked(null);\n    onAssign?.(task, bot ?? null);\n  };\n\n  const columnAt = (x: number, y: number) => {\n    for (const [id, el] of columns.current) {\n      const box = el.getBoundingClientRect();\n      if (x >= box.left && x <= box.right && y >= box.top && y <= box.bottom) {\n        return id;\n      }\n    }\n    return null;\n  };\n\n  const autoAssign = () => {\n    const next = { ...place };\n    const used = new Map(bots.map((b) => [b.id, load(b)]));\n    for (const task of inColumn(QUEUE)) {\n      const bot = bots.find(\n        (b) =>\n          b.skills.includes(task.skill) &&\n          (used.get(b.id) ?? 0) + task.size <= b.capacity,\n      );\n      if (!bot) continue;\n      next[task.id] = bot.id;\n      used.set(bot.id, (used.get(bot.id) ?? 0) + task.size);\n      onAssign?.(task, bot);\n    }\n    setPlace(next);\n    setPicked(null);\n  };\n\n  const card = (task: BoardTask) => {\n    const held = drag?.id === task.id;\n    const on = picked === task.id;\n    return (\n      <button\n        key={task.id}\n        type=\"button\"\n        data-task={task.id}\n        aria-pressed={on}\n        onPointerDown={(e) => {\n          e.currentTarget.setPointerCapture(e.pointerId);\n          start.current = { x: e.clientX, y: e.clientY };\n        }}\n        onPointerMove={(e) => {\n          if (!e.currentTarget.hasPointerCapture(e.pointerId)) return;\n          if (e.pointerType !== \"mouse\") return;\n          const dx = e.clientX - start.current.x;\n          const dy = e.clientY - start.current.y;\n          if (!drag && Math.hypot(dx, dy) < 6) return;\n          setDrag({ id: task.id, dx, dy });\n          setOver(columnAt(e.clientX, e.clientY));\n        }}\n        onPointerUp={(e) => {\n          if (drag) {\n            const target = columnAt(e.clientX, e.clientY);\n            if (target && target !== where(task)) assign(task, target);\n            setDrag(null);\n            setOver(null);\n          } else {\n            setPicked(on ? null : task.id);\n          }\n        }}\n        onPointerCancel={() => {\n          setDrag(null);\n          setOver(null);\n        }}\n        onKeyDown={(e) => {\n          if (e.key === \"Enter\" || e.key === \" \") {\n            e.preventDefault();\n            setPicked(on ? null : task.id);\n          }\n        }}\n        className={`block w-full cursor-grab rounded-lg border p-2.5 text-left select-none active:cursor-grabbing ${RING}`}\n        style={{\n          height: CARD - 6,\n          position: \"relative\",\n          zIndex: held ? 5 : 1,\n          background: c.item,\n          borderColor: on || held ? ACCENT : c.border,\n          boxShadow: held ? c.shadow : \"none\",\n          transform: held\n            ? `translate(${drag.dx}px, ${drag.dy}px) rotate(1.5deg)`\n            : \"none\",\n        }}\n      >\n        <span\n          className=\"block truncate text-[12.5px] leading-[16px] font-[510] tracking-[-0.008em]\"\n          style={{ color: c.text }}\n        >\n          {task.title}\n        </span>\n        <span\n          className=\"mt-0.5 block truncate text-[11.5px] leading-[14px] tracking-[-0.005em] tabular-nums\"\n          style={{ color: c.faint }}\n        >\n          {task.skill}, {task.size} {task.size === 1 ? \"pt\" : \"pts\"}\n        </span>\n      </button>\n    );\n  };\n\n  const column = (id: string, head: React.ReactNode, hint?: string) => {\n    const bot = bots.find((b) => b.id === id);\n    const can = Boolean(active && bot && allowed(bot, active));\n    return (\n      <div\n        key={id}\n        data-column={id}\n        ref={(el) => {\n          if (el) columns.current.set(id, el);\n          else columns.current.delete(id);\n        }}\n        onClick={() => {\n          if (picked && active && where(active) !== id) assign(active, id);\n        }}\n        className=\"min-w-0 rounded-xl border p-2 motion-safe:transition-colors motion-safe:duration-150\"\n        style={{\n          background: c.column,\n          borderColor: over === id && can ? ACCENT : c.border,\n          cursor: picked && can ? \"pointer\" : undefined,\n        }}\n      >\n        <div style={{ height: 46 }}>{head}</div>\n        <div className=\"flex flex-col gap-1.5\" style={{ height: SLOTS * CARD }}>\n          {inColumn(id).map(card)}\n        </div>\n        <p\n          className=\"m-0 flex items-center gap-1.5 text-[12px] leading-[16px] tracking-[-0.005em]\"\n          style={{\n            height: 18,\n            color: hint === \"Good fit\" ? GREEN : hint ? ORANGE : c.faint,\n          }}\n        >\n          {hint && (\n            <Dot size={6} color={hint === \"Good fit\" ? GREEN : ORANGE} />\n          )}\n          {hint}\n        </p>\n      </div>\n    );\n  };\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-3 @2xl:p-6 @2xl:pb-3\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <p\n              aria-live=\"polite\"\n              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {picked\n                ? \"Now pick a bot.\"\n                : \"Drag a task to a bot, or tap one and then a bot.\"}\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\">\n              {waiting}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px]\"\n              style={{ color: c.sub }}\n            >\n              Unassigned\n            </p>\n          </div>\n        </div>\n      </div>\n\n      <div className=\"grid grid-cols-2 gap-2 px-3 @2xl:grid-cols-4 @2xl:px-4\">\n        {column(\n          QUEUE,\n          <p className=\"m-0 p-1 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n            To assign\n          </p>,\n        )}\n        {bots.map((bot) => {\n          const used = load(bot);\n          return column(\n            bot.id,\n            <div className=\"p-1\">\n              <p className=\"m-0 flex items-baseline justify-between gap-2 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                <span className=\"truncate\">{bot.name}</span>\n                <span\n                  className=\"shrink-0 text-[12px] leading-[16px] font-normal tabular-nums\"\n                  style={{ color: c.faint }}\n                >\n                  {used}/{bot.capacity}\n                </span>\n              </p>\n              <svg\n                aria-hidden=\"true\"\n                width=\"100%\"\n                height=\"4\"\n                className=\"mt-1.5 block\"\n              >\n                <rect width=\"100%\" height=\"4\" rx=\"2\" fill={c.track} />\n                <rect\n                  width={`${Math.min(100, (used / bot.capacity) * 100)}%`}\n                  height=\"4\"\n                  rx=\"2\"\n                  fill={used >= bot.capacity ? ORANGE : ACCENT}\n                />\n              </svg>\n            </div>,\n            active ? verdict(bot, active) : undefined,\n          );\n        })}\n      </div>\n\n      <footer className=\"flex items-center justify-end gap-2 px-5 py-3.5 @2xl:px-6\">\n        <button\n          type=\"button\"\n          data-reset=\"\"\n          disabled={!Object.keys(place).length}\n          onClick={() => {\n            setPlace({});\n            setPicked(null);\n          }}\n          className={`h-9 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n          style={{\n            background: c.chip,\n            color: Object.keys(place).length ? c.soft : c.faint,\n          }}\n        >\n          Start over\n        </button>\n        <button\n          type=\"button\"\n          data-auto=\"\"\n          disabled={!waiting}\n          onClick={autoAssign}\n          className={`h-9 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n          style={{\n            background: waiting ? c.btn : c.chip,\n            color: waiting ? c.btnText : c.faint,\n          }}\n        >\n          Assign the rest\n        </button>\n      </footer>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}