{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kanban",
  "title": "Kanban",
  "description": "Primitives for kanban boards: a board of columns with drag and drop by mouse, touch and keyboard and announced moves, columns with counts, WIP limits that warn or block and collapsing, cards with a move menu, labels, assignees, due dates, priorities, stats and subtasks, an inline add-card form and a helper that moves a card in your array.",
  "registryDependencies": [
    "avatar",
    "button",
    "dropdown-menu",
    "input",
    "kbd",
    "https://www.dashboardblocks.com/r/radix/activity-feed.json",
    "https://www.dashboardblocks.com/r/radix/schedule.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/kanban.tsx",
      "content": "'use client'\n\nimport type { ActivityTone } from '@/registry/components/dashboardblocks/activity-feed'\nimport {\n  BlockStateText,\n  Skeleton,\n  useBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  UrgencyLabel,\n  getDay,\n  getDayOffset,\n  getUrgency,\n} from '@/registry/components/dashboardblocks/schedule'\nimport { statusToneClasses } from '@/registry/components/dashboardblocks/status-label'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatDate, formatList } from '@/registry/lib/dashboardblocks/format'\nimport {\n  type FormEvent,\n  type KeyboardEvent,\n  type MouseEvent,\n  type PointerEvent,\n  type ReactNode,\n  createContext,\n  useContext,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport {\n  Avatar,\n  AvatarFallback,\n  AvatarGroup,\n  AvatarGroupCount,\n} from '@/components/ui/avatar'\nimport { Button } from '@/components/ui/button'\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuLabel,\n  DropdownMenuSeparator,\n  DropdownMenuTrigger,\n} from '@/components/ui/dropdown-menu'\nimport { Input } from '@/components/ui/input'\nimport { Kbd } from '@/components/ui/kbd'\n\nimport { cn } from '@/lib/utils'\n\ninterface KanbanColumnDef {\n  color?: string\n  /** Drawn before the title, such as a status's icon. */\n  icon?: ReactNode\n  id: string\n  title: string\n  wipLimit?: number\n}\n\ninterface KanbanItem {\n  column: string\n  id: string\n  title: string\n}\n\n/** `warn` lets cards into a column at its WIP limit and flags the column when it goes over. */\ntype KanbanWipLimitMode = 'block' | 'warn'\n\ninterface KanbanTarget {\n  blocked?: boolean\n  column: string\n  index: number\n}\n\ninterface KanbanDrag {\n  id: string\n  mode: 'keyboard' | 'pointer'\n  origin: KanbanTarget\n  /** The lifted card's height, which its landing slot takes. */\n  size: number\n  target: KanbanTarget | null\n}\n\nfunction getSlot(drag: KanbanDrag | null): KanbanTarget | null {\n  if (!drag) return null\n  const { mode, origin, target } = drag\n  const open = target && !target.blocked ? target : null\n  if (mode === 'pointer') return open ?? origin\n  return open && !isSameTarget(open, origin) ? open : null\n}\n\nfunction getColumnItems<T extends KanbanItem>(\n  items: T[],\n  column: string,\n  without?: string,\n) {\n  return items.filter((item) => item.column === column && item.id !== without)\n}\n\nfunction moveItem<T extends KanbanItem>(\n  items: T[],\n  id: string,\n  column: string,\n  index: number,\n): T[] {\n  const item = items.find((candidate) => candidate.id === id)\n  if (!item) return items\n  const rest = items.filter((candidate) => candidate.id !== id)\n  const siblings = rest.filter((candidate) => candidate.column === column)\n  const before = siblings[Math.max(0, index)]\n  const at = before\n    ? rest.indexOf(before)\n    : siblings.length > 0\n      ? rest.indexOf(siblings[siblings.length - 1]) + 1\n      : rest.length\n  return [...rest.slice(0, at), { ...item, column }, ...rest.slice(at)]\n}\n\ninterface KanbanState {\n  columns: KanbanColumnDef[]\n  items: KanbanItem[]\n  onMove: KanbanMove\n  onOpen?: (id: string) => void\n  wipLimitMode: KanbanWipLimitMode\n}\n\nfunction canDrop(state: KanbanState, id: string, column: string) {\n  const item = state.items.find((candidate) => candidate.id === id)\n  const limit = state.columns.find((candidate) => candidate.id === column)?.wipLimit\n  if (!item || item.column === column || limit === undefined) return true\n  return (\n    state.wipLimitMode !== 'block' || getColumnItems(state.items, column).length < limit\n  )\n}\n\nfunction exceedsLimit(state: KanbanState, id: string, column: string) {\n  const item = state.items.find((candidate) => candidate.id === id)\n  const limit = state.columns.find((candidate) => candidate.id === column)?.wipLimit\n  return (\n    item !== undefined &&\n    item.column !== column &&\n    limit !== undefined &&\n    getColumnItems(state.items, column).length >= limit\n  )\n}\n\nfunction describePosition(state: KanbanState, id: string, target: KanbanTarget) {\n  const column = state.columns.find((candidate) => candidate.id === target.column)\n  const count = getColumnItems(state.items, target.column, id).length + 1\n  return `${column?.title ?? target.column}, position ${target.index + 1} of ${count}`\n}\n\nfunction isSameTarget(a: KanbanTarget | null, b: KanbanTarget | null) {\n  return a?.column === b?.column && a?.index === b?.index && a?.blocked === b?.blocked\n}\n\n/** Return `false` to refuse the move: the card stays where it was, and a screen reader hears that it's back. Say why yourself, with a toast or a dialog. */\ntype KanbanMove = (id: string, column: string, index: number) => boolean | void\n\ninterface KanbanContextValue {\n  canDrop: (id: string, column: string) => boolean\n  columns: KanbanColumnDef[]\n  drag: KanbanDrag | null\n  exceedsLimit: (id: string, column: string) => boolean\n  instructionsId: string\n  itemName: KanbanItemName\n  items: KanbanItem[]\n  moveFromMenu: (id: string, column: string, index: number) => void\n  onHandleBlur: (id: string) => void\n  onHandleClick: (event: MouseEvent<HTMLButtonElement>, id: string) => void\n  onHandleKeyDown: (event: KeyboardEvent<HTMLButtonElement>, id: string) => void\n  onPointerDown: (event: PointerEvent<HTMLElement>, id: string) => void\n  opens: boolean\n  registerHandle: (id: string, element: HTMLButtonElement | null) => void\n}\n\nconst KanbanContext = createContext<KanbanContextValue | null>(null)\n\nfunction useKanban() {\n  const context = useContext(KanbanContext)\n  if (!context) throw new Error('Kanban parts must be inside a KanbanBoard.')\n  return context\n}\n\nconst KanbanCardContext = createContext<KanbanItem | null>(null)\n\nfunction useKanbanCard() {\n  const item = useContext(KanbanCardContext)\n  if (!item) throw new Error('Kanban card parts must be inside a KanbanCard.')\n  return item\n}\n\ninterface KanbanItemName {\n  one: string\n  other: string\n}\n\ninterface PointerSession {\n  active: boolean\n  frame: number\n  id: string\n  offsetX: number\n  offsetY: number\n  pointerId: number\n  removeListeners: () => void\n  startX: number\n  startY: number\n  surface: HTMLElement\n  timer?: ReturnType<typeof setTimeout>\n  x: number\n  y: number\n}\n\nconst MOUSE_DRAG_DISTANCE_PX = 4\nconst TOUCH_HOLD_MS = 250\nconst TOUCH_SCROLL_TOLERANCE_PX = 8\nconst SCROLL_EDGE_PX = 56\nconst MOVE_MS = 300\nconst MOVE_EASING = 'cubic-bezier(0.2, 0, 0, 1)'\n\nconst INTERACTIVE =\n  'a, button, input, select, textarea, [contenteditable], [role=\"button\"], [role=\"menuitem\"]'\n\ninterface KanbanBoardProps {\n  /** `KanbanColumn`s, one per column in `columns`, in the same order. */\n  children: ReactNode\n  className?: string\n  columns: KanbanColumnDef[]\n  itemName?: KanbanItemName\n  items: KanbanItem[]\n  label: string\n  onMove: KanbanMove\n  /** Opens a card: a click or tap on it, or Enter on its title. Space then picks a card up to move it. */\n  onOpen?: (id: string) => void\n  /** @default 'warn' */\n  wipLimitMode?: KanbanWipLimitMode\n}\n\nfunction KanbanBoard({\n  children,\n  className,\n  columns,\n  itemName = { one: 'card', other: 'cards' },\n  items,\n  label,\n  onMove,\n  onOpen,\n  wipLimitMode = 'warn',\n}: KanbanBoardProps) {\n  const id = useId()\n  const instructionsId = `${id}-instructions`\n  const scrollerRef = useRef<HTMLDivElement>(null)\n  const handles = useRef(new Map<string, HTMLButtonElement>())\n  const [drag, setDragState] = useState<KanbanDrag | null>(null)\n  const [announcement, setAnnouncement] = useState('')\n  const dragRef = useRef<KanbanDrag | null>(null)\n  const session = useRef<PointerSession | null>(null)\n  const pendingFocus = useRef<{ id: string; onlyIfLost: boolean } | null>(null)\n  const latest = useRef<KanbanState>({ columns, items, onMove, onOpen, wipLimitMode })\n  const wasDragging = useRef(false)\n  const places = useRef(new Map<string, { x: number; y: number }>())\n  const landing = useRef<{ id: string; x: number; y: number } | null>(null)\n  const moves = useRef(new Map<string, Animation>())\n\n  useEffect(() => {\n    latest.current = { columns, items, onMove, onOpen, wipLimitMode }\n  })\n\n  useLayoutEffect(() => {\n    const root = scrollerRef.current\n    const dragged = wasDragging.current\n    wasDragging.current = drag !== null\n    placeSurface()\n    if (!root) return\n    const before = places.current\n    const after = measurePlaces()\n    places.current = after\n    const from = landing.current\n    landing.current = null\n    if (\n      (!drag && !dragged) ||\n      window.matchMedia('(prefers-reduced-motion: reduce)').matches\n    )\n      return\n    for (const card of root.querySelectorAll<HTMLElement>('[data-kanban-card]')) {\n      const cardId = card.dataset.kanbanCard ?? ''\n      const surface = card.firstElementChild\n      if (!(surface instanceof HTMLElement)) continue\n      if (drag?.mode === 'pointer' && drag.id === cardId) continue\n      const running = moves.current.get(cardId)\n      let offsetX = 0\n      let offsetY = 0\n      if (running) {\n        const shown = surface.getBoundingClientRect()\n        const place = card.getBoundingClientRect()\n        offsetX = shown.left - place.left\n        offsetY = shown.top - place.top\n        running.cancel()\n        moves.current.delete(cardId)\n      }\n      const start =\n        from?.id === cardId\n          ? from\n          : (() => {\n              const place = before.get(cardId)\n              return place && { x: place.x + offsetX, y: place.y + offsetY }\n            })()\n      const end = after.get(cardId)\n      if (!start || !end) continue\n      const x = start.x - end.x\n      const y = start.y - end.y\n      if (Math.abs(x) < 1 && Math.abs(y) < 1) continue\n      const animation = surface.animate(\n        [{ transform: `translate(${x}px, ${y}px)` }, { transform: 'none' }],\n        { duration: MOVE_MS, easing: MOVE_EASING },\n      )\n      moves.current.set(cardId, animation)\n      animation.onfinish = () => {\n        if (moves.current.get(cardId) === animation) moves.current.delete(cardId)\n      }\n    }\n  }, [drag, items])\n\n  useEffect(() => {\n    const pending = pendingFocus.current\n    if (!pending) return\n    pendingFocus.current = null\n    const frame = requestAnimationFrame(() => {\n      const active = document.activeElement\n      if (pending.onlyIfLost && active && active !== document.body) return\n      const handle = handles.current.get(pending.id)\n      if (handle) {\n        handle.focus()\n        return\n      }\n      const column = items.find((item) => item.id === pending.id)?.column\n      const collapsed =\n        column &&\n        scrollerRef.current?.querySelector<HTMLElement>(\n          `[data-kanban-column=\"${CSS.escape(column)}\"][data-collapsed]`,\n        )\n      if (collapsed) (collapsed.querySelector('button') ?? collapsed).focus()\n    })\n    return () => cancelAnimationFrame(frame)\n  }, [items])\n\n  useEffect(() => {\n    if (drag?.mode !== 'keyboard' || !drag.target) return\n    const root = scrollerRef.current\n    const target =\n      root?.querySelector('[data-kanban-indicator]') ??\n      root?.querySelector(\n        `[data-kanban-column=\"${CSS.escape(drag.target.column)}\"][data-collapsed]`,\n      ) ??\n      root?.querySelector(`[data-kanban-card=\"${CSS.escape(drag.id)}\"]`)\n    target?.scrollIntoView({ block: 'nearest', inline: 'nearest' })\n  }, [drag])\n\n  useEffect(\n    () => () => {\n      const current = session.current\n      if (!current) return\n      cancelAnimationFrame(current.frame)\n      clearTimeout(current.timer)\n      current.removeListeners()\n    },\n    [],\n  )\n\n  function toPlace(rect: DOMRect) {\n    const root = scrollerRef.current\n    const bounds = root?.getBoundingClientRect()\n    return {\n      x: rect.left - (bounds?.left ?? 0) + (root?.scrollLeft ?? 0),\n      y: rect.top - (bounds?.top ?? 0),\n    }\n  }\n\n  function measurePlaces() {\n    const next = new Map<string, { x: number; y: number }>()\n    const root = scrollerRef.current\n    if (!root) return next\n    for (const card of root.querySelectorAll<HTMLElement>('[data-kanban-card]'))\n      next.set(card.dataset.kanbanCard ?? '', toPlace(card.getBoundingClientRect()))\n    return next\n  }\n\n  function measureSize(cardId: string) {\n    const surface = scrollerRef.current?.querySelector(\n      `[data-kanban-card=\"${CSS.escape(cardId)}\"] > *`,\n    )\n    return surface instanceof HTMLElement ? surface.offsetHeight : 0\n  }\n\n  function setDrag(next: KanbanDrag | null) {\n    dragRef.current = next\n    setDragState(next)\n  }\n\n  function announce(text: string) {\n    setAnnouncement((current) => (current === text ? `${text}\\u00a0` : text))\n  }\n\n  function titleOf(cardId: string) {\n    return latest.current.items.find((item) => item.id === cardId)?.title ?? 'Card'\n  }\n\n  function limitNote(cardId: string, column: string) {\n    const state = latest.current\n    if (!exceedsLimit(state, cardId, column)) return ''\n    const def = state.columns.find((candidate) => candidate.id === column)\n    return ` That puts ${def?.title} over its limit of ${def?.wipLimit}.`\n  }\n\n  function lift(cardId: string) {\n    const state = latest.current\n    const item = state.items.find((candidate) => candidate.id === cardId)\n    if (!item) return\n    const origin = {\n      column: item.column,\n      index: getColumnItems(state.items, item.column).indexOf(item),\n    }\n    places.current = measurePlaces()\n    setDrag({\n      id: cardId,\n      mode: 'keyboard',\n      origin,\n      size: measureSize(cardId),\n      target: origin,\n    })\n    announce(\n      `Picked up ${item.title}. ${describePosition(state, cardId, origin)}. Use the arrow keys to move it, Space or Enter to drop it, Escape to cancel.`,\n    )\n  }\n\n  function drop() {\n    const current = dragRef.current\n    if (!current) return\n    const state = latest.current\n    const title = titleOf(current.id)\n    setDrag(null)\n    const { origin, target } = current\n    if (!target || target.blocked) {\n      const def = state.columns.find((candidate) => candidate.id === target?.column)\n      announce(\n        `${target?.blocked ? `${def?.title} is at its limit of ${def?.wipLimit}. ` : ''}${title} is back in ${describePosition(state, current.id, origin)}.`,\n      )\n      return\n    }\n    if (isSameTarget(target, origin)) {\n      announce(\n        `Dropped ${title} where it was, ${describePosition(state, current.id, origin)}.`,\n      )\n      return\n    }\n    const note = `Dropped ${title} in ${describePosition(state, current.id, target)}.${limitNote(current.id, target.column)}`\n    if (state.onMove(current.id, target.column, target.index) === false) {\n      announce(`${title} is back in ${describePosition(state, current.id, origin)}.`)\n      return\n    }\n    if (current.mode === 'keyboard')\n      pendingFocus.current = { id: current.id, onlyIfLost: false }\n    announce(note)\n  }\n\n  function cancel() {\n    const current = dragRef.current\n    if (!current) return\n    setDrag(null)\n    announce(\n      `Move cancelled. ${titleOf(current.id)} is back in ${describePosition(latest.current, current.id, current.origin)}.`,\n    )\n  }\n\n  function moveKeyboardTarget(key: string) {\n    const current = dragRef.current\n    if (!current?.target) return\n    const state = latest.current\n    const { target } = current\n    let next: KanbanTarget = target\n    let skipped: string[] = []\n    if (key === 'ArrowUp' || key === 'ArrowDown') {\n      const count = getColumnItems(state.items, target.column, current.id).length\n      const index = target.index + (key === 'ArrowUp' ? -1 : 1)\n      next = { ...target, index: Math.max(0, Math.min(count, index)) }\n    } else {\n      const step = key === 'ArrowLeft' ? -1 : 1\n      let position =\n        state.columns.findIndex((column) => column.id === target.column) + step\n      const passed: string[] = []\n      while (\n        position >= 0 &&\n        position < state.columns.length &&\n        !canDrop(state, current.id, state.columns[position].id)\n      ) {\n        passed.push(state.columns[position].title)\n        position += step\n      }\n      const column = state.columns[position]\n      if (column) {\n        const count = getColumnItems(state.items, column.id, current.id).length\n        next = { column: column.id, index: Math.min(target.index, count) }\n        skipped = passed\n      }\n    }\n    setDrag({ ...current, target: next })\n    const title = titleOf(current.id)\n    const edge =\n      isSameTarget(next, target) && key !== 'ArrowUp' && key !== 'ArrowDown'\n        ? `${title} can't move further ${key === 'ArrowLeft' ? 'left' : 'right'}. `\n        : ''\n    const skip =\n      skipped.length > 0\n        ? `Skipped ${skipped.join(' and ')}, at ${skipped.length === 1 ? 'its' : 'their'} limit. `\n        : ''\n    announce(\n      `${edge}${skip}${describePosition(state, current.id, next)}.${limitNote(current.id, next.column)}`,\n    )\n  }\n\n  function onHandleClick(event: MouseEvent<HTMLButtonElement>, cardId: string) {\n    if (event.detail !== 0) return\n    event.preventDefault()\n    const current = dragRef.current\n    if (!current) lift(cardId)\n    else if (current.mode === 'keyboard' && current.id === cardId) drop()\n  }\n\n  function onHandleKeyDown(event: KeyboardEvent<HTMLButtonElement>, cardId: string) {\n    const current = dragRef.current\n    const open = latest.current.onOpen\n    if (!current && open && event.key === 'Enter') {\n      event.preventDefault()\n      open(cardId)\n      return\n    }\n    if (current?.mode !== 'keyboard' || current.id !== cardId) return\n    if (event.key === 'Escape') {\n      event.preventDefault()\n      event.stopPropagation()\n      cancel()\n    } else if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {\n      event.preventDefault()\n      moveKeyboardTarget(event.key)\n    }\n  }\n\n  function onHandleBlur(cardId: string) {\n    const current = dragRef.current\n    if (current?.mode === 'keyboard' && current.id === cardId) cancel()\n  }\n\n  function moveFromMenu(cardId: string, column: string, index: number) {\n    const state = latest.current\n    const note = `Moved ${titleOf(cardId)} to ${describePosition(state, cardId, { column, index })}.${limitNote(cardId, column)}`\n    if (state.onMove(cardId, column, index) === false) return\n    pendingFocus.current = { id: cardId, onlyIfLost: true }\n    announce(note)\n  }\n\n  function findTarget(cardId: string, x: number, y: number): KanbanTarget | null {\n    const root = scrollerRef.current\n    if (!root) return null\n    const bounds = root.getBoundingClientRect()\n    if (y < bounds.top - SCROLL_EDGE_PX || y > bounds.bottom + SCROLL_EDGE_PX) return null\n    const clampedX = Math.max(bounds.left + 1, Math.min(bounds.right - 1, x))\n    let closest: HTMLElement | null = null\n    let distance = Infinity\n    for (const element of root.querySelectorAll<HTMLElement>('[data-kanban-column]')) {\n      const rect = element.getBoundingClientRect()\n      const gap =\n        clampedX < rect.left ? rect.left - clampedX : Math.max(0, clampedX - rect.right)\n      if (gap < distance) {\n        closest = element\n        distance = gap\n      }\n    }\n    const column = closest?.dataset.kanbanColumn\n    if (!closest || column === undefined) return null\n    if (!canDrop(latest.current, cardId, column))\n      return { blocked: true, column, index: 0 }\n    if (closest.dataset.collapsed !== undefined) return { column, index: 0 }\n    let index = 0\n    for (const card of closest.querySelectorAll<HTMLElement>('[data-kanban-card]')) {\n      if (card.dataset.kanbanCard === cardId) continue\n      const rect = card.getBoundingClientRect()\n      if (rect.top + rect.height / 2 < y) index++\n    }\n    return { column, index }\n  }\n\n  function endPointer(commit: boolean, released = false) {\n    const current = session.current\n    if (!current) return\n    session.current = null\n    cancelAnimationFrame(current.frame)\n    clearTimeout(current.timer)\n    current.removeListeners()\n    if (current.active)\n      landing.current = {\n        id: current.id,\n        ...toPlace(current.surface.getBoundingClientRect()),\n      }\n    current.surface.style.transform = ''\n    if (!current.active) {\n      if (released) latest.current.onOpen?.(current.id)\n      return\n    }\n    if (commit) drop()\n    else cancel()\n  }\n\n  function tick() {\n    const current = session.current\n    const root = scrollerRef.current\n    if (!current?.active || !root) return\n    const { x, y } = current\n    const bounds = root.getBoundingClientRect()\n\n    const edge = Math.min(SCROLL_EDGE_PX, bounds.width / 5)\n    const speed = (depth: number) => Math.min(20, Math.ceil((depth / edge) * 14))\n    if (x < bounds.left + edge) root.scrollLeft -= speed(bounds.left + edge - x)\n    else if (x > bounds.right - edge) root.scrollLeft += speed(x - bounds.right + edge)\n    if (y < SCROLL_EDGE_PX) window.scrollBy(0, -speed(SCROLL_EDGE_PX - y))\n    else if (y > window.innerHeight - SCROLL_EDGE_PX)\n      window.scrollBy(0, speed(y - window.innerHeight + SCROLL_EDGE_PX))\n\n    placeSurface()\n\n    const target = findTarget(current.id, x, y)\n    const drag = dragRef.current\n    if (drag && !isSameTarget(drag.target, target)) setDrag({ ...drag, target })\n    current.frame = requestAnimationFrame(tick)\n  }\n\n  function placeSurface() {\n    const current = session.current\n    const root = scrollerRef.current\n    if (!current?.active || !root) return\n    const bounds = root.getBoundingClientRect()\n    const anchor = (\n      current.surface.parentElement ?? current.surface\n    ).getBoundingClientRect()\n    const inset = 6\n    const left = Math.max(\n      bounds.left + inset,\n      Math.min(\n        bounds.left + root.clientWidth - current.surface.offsetWidth - inset,\n        current.x - current.offsetX,\n      ),\n    )\n    const top = Math.max(\n      bounds.top + inset,\n      Math.min(\n        bounds.top + root.clientHeight - current.surface.offsetHeight - inset,\n        current.y - current.offsetY,\n      ),\n    )\n    current.surface.style.transform = `translate(${left - anchor.left}px, ${top - anchor.top}px)`\n  }\n\n  function activate() {\n    const current = session.current\n    const state = latest.current\n    const item = state.items.find((candidate) => candidate.id === current?.id)\n    if (!current || !item) return\n    current.active = true\n    const rect = current.surface.getBoundingClientRect()\n    current.offsetX = current.startX - rect.left\n    current.offsetY = current.startY - rect.top\n    const origin = {\n      column: item.column,\n      index: getColumnItems(state.items, item.column).indexOf(item),\n    }\n    const height = measureSize(item.id)\n    places.current = measurePlaces()\n    setDrag({ id: item.id, mode: 'pointer', origin, size: height, target: origin })\n    announce(`Picked up ${item.title}.`)\n    current.frame = requestAnimationFrame(tick)\n  }\n\n  function onPointerDown(event: PointerEvent<HTMLElement>, cardId: string) {\n    if (event.button !== 0 || dragRef.current || session.current) return\n    const target = event.target as HTMLElement\n    if (!target.closest('[data-kanban-handle]') && target.closest(INTERACTIVE)) return\n    const isTouch = event.pointerType === 'touch'\n\n    const onPointerMove = (moveEvent: globalThis.PointerEvent) => {\n      const current = session.current\n      if (!current || moveEvent.pointerId !== current.pointerId) return\n      if (moveEvent.pointerType === 'mouse' && moveEvent.buttons === 0) {\n        endPointer(true)\n        return\n      }\n      current.x = moveEvent.clientX\n      current.y = moveEvent.clientY\n      if (current.active) return\n      const distance = Math.hypot(current.x - current.startX, current.y - current.startY)\n      if (isTouch && distance > TOUCH_SCROLL_TOLERANCE_PX) endPointer(false)\n      else if (!isTouch && distance > MOUSE_DRAG_DISTANCE_PX) activate()\n    }\n    const onUp = (upEvent: globalThis.PointerEvent) => {\n      if (upEvent.pointerId === session.current?.pointerId) endPointer(true, true)\n    }\n    const onCancel = (cancelEvent: globalThis.PointerEvent) => {\n      if (cancelEvent.pointerId === session.current?.pointerId) endPointer(false)\n    }\n    const onKey = (keyEvent: globalThis.KeyboardEvent) => {\n      if (keyEvent.key !== 'Escape' || !session.current?.active) return\n      keyEvent.preventDefault()\n      endPointer(false)\n    }\n    const onTouchMove = (touchEvent: TouchEvent) => {\n      if (session.current?.active && touchEvent.cancelable) touchEvent.preventDefault()\n    }\n    const onContextMenu = (menuEvent: Event) => menuEvent.preventDefault()\n    const onBlur = () => endPointer(false)\n\n    window.addEventListener('pointermove', onPointerMove)\n    window.addEventListener('pointerup', onUp)\n    window.addEventListener('pointercancel', onCancel)\n    window.addEventListener('keydown', onKey, { capture: true })\n    window.addEventListener('touchmove', onTouchMove, { passive: false })\n    window.addEventListener('contextmenu', onContextMenu)\n    window.addEventListener('blur', onBlur)\n\n    session.current = {\n      active: false,\n      frame: 0,\n      id: cardId,\n      offsetX: 0,\n      offsetY: 0,\n      pointerId: event.pointerId,\n      removeListeners: () => {\n        window.removeEventListener('pointermove', onPointerMove)\n        window.removeEventListener('pointerup', onUp)\n        window.removeEventListener('pointercancel', onCancel)\n        window.removeEventListener('keydown', onKey, { capture: true })\n        window.removeEventListener('touchmove', onTouchMove)\n        window.removeEventListener('contextmenu', onContextMenu)\n        window.removeEventListener('blur', onBlur)\n      },\n      startX: event.clientX,\n      startY: event.clientY,\n      surface: event.currentTarget,\n      timer: isTouch ? setTimeout(activate, TOUCH_HOLD_MS) : undefined,\n      x: event.clientX,\n      y: event.clientY,\n    }\n  }\n\n  function registerHandle(cardId: string, element: HTMLButtonElement | null) {\n    if (element) handles.current.set(cardId, element)\n    else handles.current.delete(cardId)\n  }\n\n  const context: KanbanContextValue = {\n    canDrop: (cardId, column) =>\n      canDrop({ columns, items, onMove, wipLimitMode }, cardId, column),\n    columns,\n    drag,\n    exceedsLimit: (cardId, column) =>\n      exceedsLimit({ columns, items, onMove, wipLimitMode }, cardId, column),\n    instructionsId,\n    itemName,\n    items,\n    moveFromMenu,\n    onHandleBlur,\n    onHandleClick,\n    onHandleKeyDown,\n    onPointerDown,\n    opens: onOpen !== undefined,\n    registerHandle,\n  }\n\n  return (\n    <KanbanContext.Provider value={context}>\n      <div className='relative min-w-0'>\n        <p id={instructionsId} className='sr-only'>\n          {onOpen\n            ? `Press Enter to open a ${itemName.one}. To move it, press Space, use the arrow keys to choose a column and a position, then press Space to drop it, or Escape to cancel.`\n            : `To move a ${itemName.one} with the keyboard, press Space or Enter on it, use the arrow keys to choose a column and a position, then press Space or Enter to drop it, or Escape to cancel. Each ${itemName.one} also has a Move menu.`}\n        </p>\n        <p role='status' className='sr-only'>\n          {announcement}\n        </p>\n        <div\n          ref={scrollerRef}\n          role='region'\n          aria-label={label}\n          data-dragging={drag?.mode}\n          // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- a scrolling region must be focusable so keyboard users can reach the columns that don't fit\n          tabIndex={0}\n          className={cn(\n            'focus-visible:ring-ring/50 @container relative flex snap-x snap-proximity items-start gap-4 overflow-x-auto outline-none [scrollbar-width:thin] focus-visible:ring-3 focus-visible:ring-inset data-dragging:snap-none data-dragging:select-none data-[dragging=pointer]:**:cursor-grabbing',\n            className,\n          )}\n        >\n          <BlockStateText className='sr-only' />\n          {children}\n        </div>\n        {drag?.mode === 'keyboard' && (\n          <div aria-hidden className='pointer-events-none sticky bottom-4 z-20 h-0'>\n            <div className='bg-popover text-popover-foreground absolute inset-x-4 bottom-4 mx-auto flex w-fit max-w-[calc(100%-2rem)] flex-wrap items-center justify-center gap-x-3 gap-y-1 rounded-lg px-3 py-2 text-xs shadow-md ring-1 ring-foreground/10'>\n              <span className='flex items-center gap-1'>\n                <Kbd>←</Kbd>\n                <Kbd>→</Kbd>\n                Column\n              </span>\n              <span className='flex items-center gap-1'>\n                <Kbd>↑</Kbd>\n                <Kbd>↓</Kbd>\n                Position\n              </span>\n              <span className='flex items-center gap-1'>\n                <Kbd>Space</Kbd>\n                Drop\n              </span>\n              <span className='flex items-center gap-1'>\n                <Kbd>Esc</Kbd>\n                Cancel\n              </span>\n            </div>\n          </div>\n        )}\n      </div>\n    </KanbanContext.Provider>\n  )\n}\n\nfunction KanbanCount({\n  className,\n  count,\n  itemName = { one: 'card', other: 'cards' },\n  limit,\n}: {\n  className?: string\n  count: number\n  itemName?: KanbanItemName\n  limit?: number\n}) {\n  const state =\n    limit === undefined\n      ? 'none'\n      : count > limit\n        ? 'over'\n        : count === limit\n          ? 'at'\n          : 'under'\n  return (\n    <Tag\n      data-state={state}\n      className={cn('[&_svg]:size-3.5 [&_svg]:shrink-0', className)}\n      indicator={\n        state === 'over' && (\n          <IconPlaceholder\n            lucide='TriangleAlertIcon'\n            tabler='IconAlertTriangle'\n            hugeicons='Alert02Icon'\n            phosphor='WarningIcon'\n            remixicon='RiErrorWarningLine'\n            aria-hidden\n          />\n        )\n      }\n      tone={state === 'over' ? 'bad' : state === 'at' ? 'warning' : 'neutral'}\n    >\n      <span aria-hidden>{limit === undefined ? count : `${count} / ${limit}`}</span>\n      <span className='sr-only'>\n        {count} {count === 1 ? itemName.one : itemName.other}\n        {limit !== undefined && `, limit ${limit}`}\n        {state === 'over' && ', over the limit'}\n        {state === 'at' && ', at the limit'}\n      </span>\n    </Tag>\n  )\n}\n\ninterface KanbanColumnProps {\n  action?: ReactNode\n  children?: ReactNode\n  className?: string\n  collapsed?: boolean\n  column: KanbanColumnDef\n  empty?: ReactNode\n  footer?: ReactNode\n  /** Adds a button that collapses and expands the column. */\n  onCollapsedChange?: (collapsed: boolean) => void\n  summary?: ReactNode\n}\n\nfunction KanbanColumn({\n  action,\n  children,\n  className,\n  collapsed = false,\n  column,\n  empty,\n  footer,\n  onCollapsedChange,\n  summary,\n}: KanbanColumnProps) {\n  const headingId = useId()\n  const { drag, exceedsLimit: exceeds, items, itemName } = useKanban()\n  const loading = useBlockState() === 'loading'\n  const count = getColumnItems(items, column.id).length\n  const target = drag?.target?.column === column.id ? drag.target : null\n  const slot = getSlot(drag)\n  const slotAtEnd =\n    drag !== null &&\n    slot?.column === column.id &&\n    slot.index >= getColumnItems(items, column.id, drag.id).length\n  const isOver =\n    target !== null && !target.blocked && !isSameTarget(target, drag?.origin ?? null)\n  const dot = column.color && (\n    <span\n      aria-hidden\n      className='size-2.5 shrink-0 rounded-full'\n      style={{ backgroundColor: column.color }}\n    />\n  )\n  const icon = column.icon && (\n    <span aria-hidden className='flex shrink-0 [&_svg]:size-4'>\n      {column.icon}\n    </span>\n  )\n  const toggle = onCollapsedChange && (\n    <Button\n      aria-expanded={!collapsed}\n      aria-label={`${collapsed ? 'Expand' : 'Collapse'} ${column.title}`}\n      size='icon-xs'\n      variant='ghost'\n      onClick={() => onCollapsedChange(!collapsed)}\n    >\n      {collapsed ? (\n        <IconPlaceholder\n          lucide='UnfoldHorizontalIcon'\n          tabler='IconArrowsHorizontal'\n          hugeicons='ArrowExpandIcon'\n          phosphor='ArrowsOutLineHorizontalIcon'\n          remixicon='RiExpandLeftRightLine'\n        />\n      ) : (\n        <IconPlaceholder\n          lucide='FoldHorizontalIcon'\n          tabler='IconArrowsMinimize'\n          hugeicons='ArrowShrinkIcon'\n          phosphor='ArrowsInLineHorizontalIcon'\n          remixicon='RiContractLeftRightLine'\n        />\n      )}\n    </Button>\n  )\n  const columnClassName =\n    'flex shrink-0 snap-start flex-col border-t pt-3 transition-colors data-over:border-sidebar-accent data-blocked:border-red-500'\n\n  if (collapsed) {\n    return (\n      <section\n        aria-labelledby={headingId}\n        data-kanban-column={column.id}\n        data-collapsed=''\n        tabIndex={-1}\n        data-over={isOver ? '' : undefined}\n        data-blocked={target?.blocked ? '' : undefined}\n        className={cn(columnClassName, 'w-9 items-center gap-3', className)}\n      >\n        {toggle}\n        {!loading && (\n          <KanbanCount count={count} itemName={itemName} limit={column.wipLimit} />\n        )}\n        <h3\n          id={headingId}\n          className='flex items-center gap-2 text-sm font-medium whitespace-nowrap [writing-mode:vertical-rl]'\n        >\n          {dot}\n          {icon}\n          {column.title}\n        </h3>\n      </section>\n    )\n  }\n\n  return (\n    <section\n      aria-labelledby={headingId}\n      data-kanban-column={column.id}\n      data-over={isOver ? '' : undefined}\n      data-blocked={target?.blocked ? '' : undefined}\n      className={cn(columnClassName, 'w-72 max-w-[calc(100cqw-2.5rem)] gap-3', className)}\n    >\n      <div className='flex min-h-7 items-center gap-2'>\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <h3\n            id={headingId}\n            className='flex min-w-0 items-center gap-2 text-sm font-medium'\n          >\n            {dot}\n            {icon}\n            <span className='truncate'>{column.title}</span>\n          </h3>\n          {summary && !loading && (\n            <div\n              className={cn(\n                'text-muted-foreground text-xs tabular-nums',\n                dot && 'pl-4.5',\n              )}\n            >\n              {summary}\n            </div>\n          )}\n        </div>\n        {!loading && (\n          <KanbanCount count={count} itemName={itemName} limit={column.wipLimit} />\n        )}\n        {(action || toggle) && (\n          <div className='-my-1 flex shrink-0 items-center'>\n            {action}\n            {toggle}\n          </div>\n        )}\n      </div>\n      {target?.blocked && (\n        <p aria-hidden className='text-xs text-red-700 dark:text-red-400'>\n          At its limit of {column.wipLimit}\n        </p>\n      )}\n      {loading ? (\n        <div aria-hidden className='flex flex-col gap-2'>\n          <Skeleton className='h-24 rounded-xl' />\n          <Skeleton className='h-24 rounded-xl' />\n        </div>\n      ) : count > 0 ? (\n        <ul aria-labelledby={headingId} className='flex flex-col gap-2'>\n          {children}\n          {slotAtEnd && (\n            <DropSlot height={drag.size} over={exceeds(drag.id, column.id)} />\n          )}\n        </ul>\n      ) : (\n        <div\n          data-kanban-indicator={isOver ? '' : undefined}\n          style={isOver && drag ? { minHeight: drag.size } : undefined}\n          className={cn(\n            'text-muted-foreground flex min-h-20 items-center justify-center rounded-xl border border-dashed px-3 py-6 text-center text-xs transition-colors',\n            isOver &&\n              drag &&\n              (exceeds(drag.id, column.id)\n                ? 'border-red-500/60 bg-red-500/5'\n                : 'border-foreground/25 bg-muted/60'),\n          )}\n        >\n          {empty ?? `No ${itemName.other}`}\n        </div>\n      )}\n      {!loading && footer}\n    </section>\n  )\n}\n\nfunction DropSlot({ height, over }: { height: number; over: boolean }) {\n  return (\n    <li\n      aria-hidden\n      data-kanban-indicator=''\n      style={{ height }}\n      className={cn(\n        'animate-in fade-in rounded-xl border border-dashed duration-200 motion-reduce:animate-none',\n        over ? 'border-red-500/60 bg-red-500/5' : 'border-foreground/25 bg-muted/60',\n      )}\n    />\n  )\n}\n\ninterface KanbanCardProps {\n  children: ReactNode\n  className?: string\n  item: KanbanItem\n}\n\nfunction KanbanCard({ children, className, item }: KanbanCardProps) {\n  const { drag, exceedsLimit: exceeds, items, onPointerDown, opens } = useKanban()\n  const lifted = drag?.id === item.id ? drag.mode : undefined\n  const slot = getSlot(drag)\n  const slotBefore =\n    drag !== null &&\n    !lifted &&\n    slot?.column === item.column &&\n    getColumnItems(items, item.column, drag.id).findIndex(\n      (sibling) => sibling.id === item.id,\n    ) === slot.index\n\n  return (\n    <>\n      {slotBefore && <DropSlot height={drag.size} over={exceeds(drag.id, item.column)} />}\n      <li\n        data-kanban-card={item.id}\n        data-lifted={lifted}\n        className={cn('relative', lifted === 'pointer' && '-mb-2 h-0')}\n      >\n        <KanbanCardContext.Provider value={item}>\n          <div\n            onPointerDown={(event) => onPointerDown(event, item.id)}\n            className={cn(\n              'bg-muted/50 relative flex cursor-grab flex-col gap-2.5 rounded-xl p-3 text-sm transition-[box-shadow,translate,scale] select-none [--kanban-card-surface:color-mix(in_oklab,var(--color-muted)_50%,var(--color-background))] [-webkit-touch-callout:none]',\n              lifted === 'pointer' &&\n                'bg-muted pointer-events-none [--kanban-card-surface:var(--color-muted)] z-30 scale-[1.02] shadow-lg ring-1 ring-foreground/10 transition-none',\n              lifted === 'keyboard' && '-translate-y-0.5 ring-2 ring-primary',\n              !lifted &&\n                'has-[[data-kanban-handle]:focus-visible]:ring-3 has-[[data-kanban-handle]:focus-visible]:ring-ring/50',\n              opens &&\n                !lifted &&\n                'hover:bg-muted cursor-pointer hover:[--kanban-card-surface:var(--color-muted)]',\n              className,\n            )}\n          >\n            {children}\n          </div>\n        </KanbanCardContext.Provider>\n      </li>\n    </>\n  )\n}\n\nfunction KanbanCardTitle({\n  children,\n  className,\n}: {\n  /** @default the item's `title` */\n  children?: ReactNode\n  className?: string\n}) {\n  const item = useKanbanCard()\n  const { instructionsId, onHandleBlur, onHandleClick, onHandleKeyDown, registerHandle } =\n    useKanban()\n  return (\n    <p className={cn('leading-snug font-medium', className)}>\n      <button\n        ref={(element) => registerHandle(item.id, element)}\n        type='button'\n        data-kanban-handle=''\n        aria-describedby={instructionsId}\n        onBlur={() => onHandleBlur(item.id)}\n        onClick={(event) => onHandleClick(event, item.id)}\n        onKeyDown={(event) => onHandleKeyDown(event, item.id)}\n        className='cursor-[inherit] text-left outline-none'\n      >\n        {children ?? item.title}\n      </button>\n    </p>\n  )\n}\n\nfunction KanbanCardMenu({ className }: { className?: string }) {\n  const item = useKanbanCard()\n  const { canDrop: canMoveTo, columns, items, moveFromMenu } = useKanban()\n  const siblings = getColumnItems(items, item.column)\n  const index = siblings.findIndex((sibling) => sibling.id === item.id)\n  return (\n    <DropdownMenu modal={false}>\n      <DropdownMenuTrigger asChild>\n        <Button\n          aria-label={`Move ${item.title}`}\n          className={className}\n          size='icon-xs'\n          variant='ghost'\n        >\n          <IconPlaceholder\n            lucide='EllipsisIcon'\n            tabler='IconDots'\n            hugeicons='MoreHorizontalCircle01Icon'\n            phosphor='DotsThreeOutlineIcon'\n            remixicon='RiMoreLine'\n          />\n        </Button>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent align='end' className='w-auto min-w-44'>\n        <DropdownMenuGroup>\n          <DropdownMenuLabel>Move to</DropdownMenuLabel>\n          {columns\n            .filter((column) => column.id !== item.column)\n            .map((column) => {\n              const full = !canMoveTo(item.id, column.id)\n              return (\n                <DropdownMenuItem\n                  key={column.id}\n                  disabled={full}\n                  onClick={() => moveFromMenu(item.id, column.id, 0)}\n                >\n                  {column.title}\n                  {full && (\n                    <span className='text-muted-foreground ml-auto pl-4 text-xs'>\n                      Full\n                    </span>\n                  )}\n                </DropdownMenuItem>\n              )\n            })}\n        </DropdownMenuGroup>\n        <DropdownMenuSeparator />\n        <DropdownMenuItem\n          disabled={index <= 0}\n          onClick={() => moveFromMenu(item.id, item.column, index - 1)}\n        >\n          Move up\n        </DropdownMenuItem>\n        <DropdownMenuItem\n          disabled={index === siblings.length - 1}\n          onClick={() => moveFromMenu(item.id, item.column, index + 1)}\n        >\n          Move down\n        </DropdownMenuItem>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\ninterface KanbanLabelDef {\n  name: string\n  /** @default 'neutral' */\n  tone?: ActivityTone\n}\n\nconst labelDotClasses: Record<ActivityTone, string> = {\n  accent: 'bg-chart-2',\n  danger: 'bg-red-500',\n  info: 'bg-sky-500',\n  neutral: 'bg-muted-foreground',\n  success: 'bg-emerald-500',\n  warning: 'bg-orange-500',\n}\n\nfunction KanbanLabel({ label }: { label: KanbanLabelDef }) {\n  return (\n    <Tag\n      className='gap-1.5'\n      indicator={\n        <span\n          aria-hidden\n          className={cn(\n            'size-1.5 shrink-0 rounded-full',\n            labelDotClasses[label.tone ?? 'neutral'],\n          )}\n        />\n      }\n    >\n      {label.name}\n    </Tag>\n  )\n}\n\nfunction KanbanLabels({\n  className,\n  labels,\n}: {\n  className?: string\n  labels: KanbanLabelDef[]\n}) {\n  return (\n    <ul aria-label='Labels' className={cn('flex flex-wrap gap-1.5 text-xs', className)}>\n      {labels.map((label) => (\n        <li key={label.name} className='flex'>\n          <KanbanLabel label={label} />\n        </li>\n      ))}\n    </ul>\n  )\n}\n\nfunction getInitials(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part[0]?.toUpperCase())\n    .join('')\n}\n\nfunction KanbanAssignees({\n  className,\n  max = 3,\n  names,\n}: {\n  className?: string\n  /** @default 3 */\n  max?: number\n  names: string[]\n}) {\n  if (names.length === 0) return null\n  const shown = names.length > max ? names.slice(0, max - 1) : names\n  const rest = names.length - shown.length\n  return (\n    <span className={cn('inline-flex', className)}>\n      <AvatarGroup\n        aria-hidden\n        className='-space-x-1 *:data-[slot=avatar]:ring-[var(--kanban-card-surface,var(--color-background))]'\n      >\n        {shown.map((name) => (\n          <Avatar key={name} size='sm' title={name}>\n            <AvatarFallback>{getInitials(name)}</AvatarFallback>\n          </Avatar>\n        ))}\n        {rest > 0 && (\n          <AvatarGroupCount\n            // Not the primitive's colour: the ring cuts the count out of the card behind it\n            className='ring-[var(--kanban-card-surface,var(--color-background))]'\n          >\n            +{rest}\n          </AvatarGroupCount>\n        )}\n      </AvatarGroup>\n      <span className='sr-only'>Assigned to {formatList(names)}</span>\n    </span>\n  )\n}\n\n/** How a due date reads on a card: `Today`, `Tomorrow`, `Yesterday`, else `Nov 6`. */\nfunction getDueDateLabel(date: Date, now: Date, timeZone = 'UTC') {\n  const offset = getDayOffset(date, now, timeZone)\n  if (offset === 0) return 'Today'\n  if (offset === 1) return 'Tomorrow'\n  if (offset === -1) return 'Yesterday'\n  return formatDate(getDay(date, timeZone), 'day')\n}\n\nfunction KanbanDueDate({\n  className,\n  date,\n  done = false,\n  now,\n  soonDays = 2,\n  timeZone = 'UTC',\n}: {\n  className?: string\n  date: Date\n  done?: boolean\n  /** Pass a fixed date, so the label renders the same on the server and in the browser. */\n  now: Date\n  /** @default 2 */\n  soonDays?: number\n  /** @default 'UTC' */\n  timeZone?: string\n}) {\n  const label = getDueDateLabel(date, now, timeZone)\n  const urgency = done ? 'later' : getUrgency(date, now, timeZone, soonDays)\n  return (\n    <span className={cn('inline-flex', className)}>\n      <span className='sr-only'>Due </span>\n      <UrgencyLabel className='text-xs' urgency={urgency} label={label} />\n      {urgency === 'overdue' && <span className='sr-only'>, overdue</span>}\n    </span>\n  )\n}\n\ntype KanbanPriorityLevel = 'high' | 'low' | 'medium' | 'urgent'\n\nconst priorityConfig: Record<\n  KanbanPriorityLevel,\n  { className: string; icon: ReactNode; label: string }\n> = {\n  high: {\n    className: 'text-orange-700 dark:text-orange-400',\n    icon: (\n      <IconPlaceholder\n        lucide='ChevronUpIcon'\n        tabler='IconChevronUp'\n        hugeicons='ArrowUp01Icon'\n        phosphor='CaretUpIcon'\n        remixicon='RiArrowUpSLine'\n        aria-hidden\n      />\n    ),\n    label: 'High',\n  },\n  low: {\n    className: 'text-muted-foreground',\n    icon: (\n      <IconPlaceholder\n        lucide='ChevronDownIcon'\n        tabler='IconChevronDown'\n        hugeicons='ArrowDown01Icon'\n        phosphor='CaretDownIcon'\n        remixicon='RiArrowDownSLine'\n        aria-hidden\n      />\n    ),\n    label: 'Low',\n  },\n  medium: {\n    className: 'text-muted-foreground',\n    icon: (\n      <IconPlaceholder\n        lucide='MinusIcon'\n        tabler='IconMinus'\n        hugeicons='MinusSignIcon'\n        phosphor='MinusIcon'\n        remixicon='RiSubtractLine'\n        aria-hidden\n      />\n    ),\n    label: 'Medium',\n  },\n  urgent: {\n    className: 'text-red-700 dark:text-red-400',\n    icon: (\n      <IconPlaceholder\n        lucide='ChevronsUpIcon'\n        tabler='IconChevronsUp'\n        hugeicons='ArrowUpDoubleIcon'\n        phosphor='CaretDoubleUpIcon'\n        remixicon='RiArrowUpDoubleLine'\n        aria-hidden\n      />\n    ),\n    label: 'Urgent',\n  },\n}\n\nfunction KanbanPriority({\n  className,\n  priority,\n  showLabel = false,\n}: {\n  className?: string\n  priority: KanbanPriorityLevel\n  showLabel?: boolean\n}) {\n  const config = priorityConfig[priority]\n  return (\n    <span\n      title={showLabel ? undefined : `${config.label} priority`}\n      className={cn(\n        'inline-flex items-center gap-1 text-xs font-medium [&_svg]:size-4 [&_svg]:shrink-0',\n        config.className,\n        className,\n      )}\n    >\n      {config.icon}\n      <span className={cn(!showLabel && 'sr-only')}>\n        {config.label}\n        <span className='sr-only'> priority</span>\n      </span>\n    </span>\n  )\n}\n\nfunction KanbanCardStat({\n  className,\n  icon,\n  label,\n  value,\n}: {\n  className?: string\n  icon: ReactNode\n  label: string\n  value: ReactNode\n}) {\n  return (\n    <span\n      className={cn(\n        'text-muted-foreground inline-flex items-center gap-1 text-xs tabular-nums [&_svg]:size-3.5 [&_svg]:shrink-0',\n        className,\n      )}\n    >\n      {icon}\n      <span aria-hidden>{value}</span>\n      <span className='sr-only'>{label}</span>\n    </span>\n  )\n}\n\nfunction KanbanComments({ className, count }: { className?: string; count: number }) {\n  return (\n    <KanbanCardStat\n      className={className}\n      icon={\n        <IconPlaceholder\n          lucide='MessageSquareIcon'\n          tabler='IconMessage'\n          hugeicons='MessageIcon'\n          phosphor='ChatCircleIcon'\n          remixicon='RiChat1Line'\n          aria-hidden\n        />\n      }\n      label={`${count} ${count === 1 ? 'comment' : 'comments'}`}\n      value={count}\n    />\n  )\n}\n\nfunction KanbanAttachments({ className, count }: { className?: string; count: number }) {\n  return (\n    <KanbanCardStat\n      className={className}\n      icon={\n        <IconPlaceholder\n          lucide='PaperclipIcon'\n          tabler='IconPaperclip'\n          hugeicons='Attachment01Icon'\n          phosphor='PaperclipIcon'\n          remixicon='RiAttachment2'\n          aria-hidden\n        />\n      }\n      label={`${count} ${count === 1 ? 'attachment' : 'attachments'}`}\n      value={count}\n    />\n  )\n}\n\nfunction KanbanSubtasks({\n  className,\n  done,\n  total,\n}: {\n  className?: string\n  done: number\n  total: number\n}) {\n  return (\n    <KanbanCardStat\n      className={cn(done === total && statusToneClasses.good, className)}\n      icon={\n        <IconPlaceholder\n          lucide='ListChecksIcon'\n          tabler='IconListCheck'\n          hugeicons='CheckListIcon'\n          phosphor='ListChecksIcon'\n          remixicon='RiListCheck3'\n          aria-hidden\n        />\n      }\n      label={`${done} of ${total} subtasks done`}\n      value={`${done}/${total}`}\n    />\n  )\n}\n\ninterface KanbanAddCardProps {\n  className?: string\n  /** @default 'Add card' */\n  label?: string\n  /** Called with the trimmed title. */\n  onAdd: (title: string) => void\n  /** @default 'Title' */\n  placeholder?: string\n}\n\nfunction KanbanAddCard({\n  className,\n  label = 'Add card',\n  onAdd,\n  placeholder = 'Title',\n}: KanbanAddCardProps) {\n  const [open, setOpen] = useState(false)\n  const [value, setValue] = useState('')\n  const [status, setStatus] = useState('')\n  const inputRef = useRef<HTMLInputElement>(null)\n  const buttonRef = useRef<HTMLButtonElement>(null)\n  const wasOpen = useRef(false)\n\n  useEffect(() => {\n    if (open) inputRef.current?.focus()\n    else if (wasOpen.current) buttonRef.current?.focus()\n    wasOpen.current = open\n  }, [open])\n\n  function close() {\n    setOpen(false)\n    setValue('')\n  }\n\n  function submit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault()\n    const title = value.trim()\n    if (!title) return inputRef.current?.focus()\n    onAdd(title)\n    setValue('')\n    setStatus(`Added ${title}`)\n  }\n\n  if (!open) {\n    return (\n      <Button\n        ref={buttonRef}\n        variant='ghost'\n        size='sm'\n        className={cn('justify-start', className)}\n        onClick={() => setOpen(true)}\n      >\n        <IconPlaceholder\n          lucide='PlusIcon'\n          tabler='IconPlus'\n          hugeicons='PlusSignIcon'\n          phosphor='PlusIcon'\n          remixicon='RiAddLine'\n        />\n        {label}\n      </Button>\n    )\n  }\n\n  return (\n    <form\n      method='post'\n      onSubmit={submit}\n      className={cn('flex flex-col gap-2', className)}\n    >\n      <Input\n        ref={inputRef}\n        aria-label={label}\n        placeholder={placeholder}\n        value={value}\n        onChange={(event) => setValue(event.target.value)}\n        onKeyDown={(event) => {\n          if (event.key !== 'Escape') return\n          event.preventDefault()\n          close()\n        }}\n      />\n      <p role='status' className='sr-only'>\n        {status}\n      </p>\n      <div className='flex items-center gap-2'>\n        <Button type='submit' size='sm'>\n          {label}\n        </Button>\n        <Button type='button' variant='ghost' size='sm' onClick={close}>\n          Cancel\n        </Button>\n      </div>\n    </form>\n  )\n}\n\nexport {\n  KanbanAddCard,\n  KanbanAssignees,\n  KanbanAttachments,\n  KanbanBoard,\n  KanbanCard,\n  KanbanCardMenu,\n  KanbanCardStat,\n  KanbanCardTitle,\n  KanbanColumn,\n  KanbanComments,\n  KanbanCount,\n  KanbanDueDate,\n  KanbanLabel,\n  KanbanLabels,\n  KanbanPriority,\n  KanbanSubtasks,\n  getColumnItems,\n  getDueDateLabel,\n  labelDotClasses,\n  moveItem,\n}\n\nexport type {\n  KanbanAddCardProps,\n  KanbanBoardProps,\n  KanbanCardProps,\n  KanbanColumnDef,\n  KanbanColumnProps,\n  KanbanItem,\n  KanbanItemName,\n  KanbanLabelDef,\n  KanbanMove,\n  KanbanPriorityLevel,\n  KanbanWipLimitMode,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/kanban.tsx"
    }
  ],
  "type": "registry:component"
}
