{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "human-review-desk",
  "title": "Human Review Desk",
  "description": "A workspace for checking what AI wants to do: a queue, the proposal with its checks and confidence, edit in place, and approve or reject from the keyboard.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/human-review-desk/human-review-desk.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ReviewDecision = \"approved\" | \"edited\" | \"rejected\";\n\nexport interface ReviewCheck {\n  label: string;\n  pass: boolean;\n}\n\nexport interface ReviewItem {\n  id: string;\n  title: string;\n  /** Where it came from, e.g. \"Refund request\". */\n  source: string;\n  /** How sure the model is, from 0 to 100. */\n  confidence: number;\n  /** What the model wants to do or send. */\n  proposal: string;\n  checks: ReviewCheck[];\n}\n\nexport interface HumanReviewDeskProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  items?: ReviewItem[];\n  /** Items under this confidence show up in the \"Needs a look\" filter. */\n  lowConfidence?: number;\n  onDecide?: (item: ReviewItem, decision: ReviewDecision, text: string) => 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 RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\n\nconst PALETTES = {\n  dark: {\n    card: \"#0F1011\",\n    inset: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    tab: \"rgba(255,255,255,0.08)\",\n    row: \"rgba(255,255,255,0.05)\",\n    track: \"rgba(255,255,255,0.1)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    keyOnBtn: \"rgba(8,9,10,0.1)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    inset: \"#F7F8F8\",\n    border: \"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.05)\",\n    tab: \"#FFFFFF\",\n    row: \"rgba(8,9,10,0.04)\",\n    track: \"rgba(8,9,10,0.1)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    keyOnBtn: \"rgba(255,255,255,0.16)\",\n  },\n};\n\nconst DEFAULT_ITEMS: ReviewItem[] = [\n  {\n    id: \"refund\",\n    title: \"Refund for a damaged lamp\",\n    source: \"Refund request\",\n    confidence: 64,\n    proposal:\n      \"Hi Noor, sorry the lamp arrived broken. I've refunded $84 to your card, and you don't need to send it back.\",\n    checks: [\n      { label: \"Order found\", pass: true },\n      { label: \"Photo attached\", pass: true },\n      { label: \"Under the $50 auto-refund limit\", pass: false },\n    ],\n  },\n  {\n    id: \"address\",\n    title: \"Change a delivery address\",\n    source: \"Support reply\",\n    confidence: 91,\n    proposal:\n      \"Done. Your order will now go to the new address, and it should still arrive on Thursday.\",\n    checks: [\n      { label: \"Not yet shipped\", pass: true },\n      { label: \"Same country\", pass: true },\n      { label: \"Customer verified\", pass: true },\n    ],\n  },\n  {\n    id: \"listing\",\n    title: \"Take down a seller listing\",\n    source: \"Trust report\",\n    confidence: 58,\n    proposal:\n      \"Remove the listing and tell the seller that its photos match another shop's. They can appeal within 14 days.\",\n    checks: [\n      { label: \"Image match found\", pass: true },\n      { label: \"First report on this seller\", pass: false },\n      { label: \"Appeal text included\", pass: true },\n    ],\n  },\n  {\n    id: \"invoice\",\n    title: \"Resend a March invoice\",\n    source: \"Billing reply\",\n    confidence: 96,\n    proposal:\n      \"Here's your March invoice again. I've also added your new VAT number, so it's ready for your records.\",\n    checks: [\n      { label: \"Invoice found\", pass: true },\n      { label: \"VAT number is valid\", pass: true },\n      { label: \"Sent to the billing contact\", pass: true },\n    ],\n  },\n  {\n    id: \"cancel\",\n    title: \"Cancel a yearly plan\",\n    source: \"Support reply\",\n    confidence: 72,\n    proposal:\n      \"Your plan is set to end on 30 June. You'll keep access until then, and we won't charge you again.\",\n    checks: [\n      { label: \"Account owner asked\", pass: true },\n      { label: \"No open invoices\", pass: true },\n      { label: \"Retention offer shown\", pass: false },\n    ],\n  },\n  {\n    id: \"promo\",\n    title: \"Extend a trial by a week\",\n    source: \"Sales reply\",\n    confidence: 83,\n    proposal:\n      \"Happy to help. I've added seven days to your trial, so you now have until the 21st to try it with your team.\",\n    checks: [\n      { label: \"First extension\", pass: true },\n      { label: \"Within the sales policy\", pass: true },\n      { label: \"Account is active\", pass: true },\n    ],\n  },\n];\n\nconst DECIDED: Record<ReviewDecision, { label: string; color: string }> = {\n  approved: { label: \"Approved\", color: GREEN },\n  edited: { label: \"Approved with edits\", color: ACCENT },\n  rejected: { label: \"Rejected\", color: RED },\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\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\nfunction Mark({ pass, faint }: { pass: boolean; faint: string }) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 16 16\"\n      width=\"16\"\n      height=\"16\"\n      fill=\"none\"\n      className=\"block shrink-0\"\n    >\n      <path\n        d={pass ? \"m3.5 8.5 3 3 6-7\" : \"M8 4v5m0 3v.01\"}\n        stroke={pass ? faint : ORANGE}\n        strokeWidth=\"1.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function HumanReviewDesk({\n  theme = \"dark\",\n  title = \"Review desk\",\n  items = DEFAULT_ITEMS,\n  lowConfidence = 70,\n  onDecide,\n  className,\n  style,\n  ...rest\n}: HumanReviewDeskProps) {\n  const c = PALETTES[theme];\n  const [selected, setSelected] = React.useState(items[0]?.id ?? \"\");\n  const [filter, setFilter] = React.useState<\"all\" | \"low\">(\"all\");\n  const [decisions, setDecisions] = React.useState<\n    Record<string, ReviewDecision>\n  >({});\n  const [drafts, setDrafts] = React.useState<Record<string, string>>({});\n  const [editing, setEditing] = React.useState<string | null>(null);\n  const editor = React.useRef<HTMLTextAreaElement>(null);\n\n  const visible = items.filter(\n    (i) => filter === \"all\" || i.confidence < lowConfidence,\n  );\n  const lowCount = items.filter((i) => i.confidence < lowConfidence).length;\n  const at = Math.max(\n    0,\n    visible.findIndex((i) => i.id === selected),\n  );\n  const decided = Object.keys(decisions).length;\n  const agreed = Object.values(decisions).filter((d) => d === \"approved\").length;\n\n  React.useEffect(() => {\n    if (editing) editor.current?.focus();\n  }, [editing]);\n\n  const go = (step: number) => {\n    const next = visible[at + step];\n    if (!next) return;\n    setSelected(next.id);\n    setEditing(null);\n  };\n\n  const decide = (item: ReviewItem, decision: ReviewDecision) => {\n    const next = { ...decisions, [item.id]: decision };\n    setDecisions(next);\n    setEditing(null);\n    onDecide?.(item, decision, drafts[item.id] ?? item.proposal);\n    // Carry on with the next item nobody has looked at yet.\n    const start = visible.findIndex((i) => i.id === item.id);\n    const after = [...visible.slice(start + 1), ...visible.slice(0, start)];\n    const open = after.find((i) => !next[i.id]);\n    if (open) setSelected(open.id);\n  };\n\n  const reopen = (item: ReviewItem) => {\n    const next = { ...decisions };\n    delete next[item.id];\n    setDecisions(next);\n  };\n\n  const changeFilter = (value: \"all\" | \"low\") => {\n    setFilter(value);\n    setEditing(null);\n    const list = items.filter(\n      (i) => value === \"all\" || i.confidence < lowConfidence,\n    );\n    if (!list.some((i) => i.id === selected) && list[0]) setSelected(list[0].id);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (e.target instanceof HTMLTextAreaElement) {\n      if (e.key === \"Escape\") setEditing(null);\n      return;\n    }\n    if (e.metaKey || e.ctrlKey || e.altKey) return;\n    const item = visible[at];\n    if (!item) return;\n    if (e.key === \"ArrowDown\" || e.key === \"j\") {\n      e.preventDefault();\n      go(1);\n    } else if (e.key === \"ArrowUp\" || e.key === \"k\") {\n      e.preventDefault();\n      go(-1);\n    } else if (!decisions[item.id]) {\n      if (e.key === \"a\") decide(item, drafts[item.id] ? \"edited\" : \"approved\");\n      if (e.key === \"r\") decide(item, \"rejected\");\n      if (e.key === \"e\") {\n        e.preventDefault();\n        setEditing(item.id);\n      }\n    }\n  };\n\n  const key = (letter: string, onButton = false) => (\n    <kbd\n      className=\"hidden size-5 items-center justify-center rounded-full text-[11px] leading-[14px] font-[510] @3xl:flex\"\n      style={{\n        fontFamily: \"inherit\",\n        background: onButton ? c.keyOnBtn : c.tab,\n      }}\n    >\n      {letter}\n    </kbd>\n  );\n  const action =\n    \"flex h-9 flex-1 cursor-pointer items-center justify-center gap-2 rounded-full border-0 px-3.5 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] @3xl:flex-none\";\n\n  return (\n    <section\n      aria-label={title}\n      onKeyDown={onKeyDown}\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      <header className=\"p-5 pb-4\">\n        <div className=\"flex flex-wrap items-center justify-between gap-x-4 gap-y-2\">\n          <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.018em]\">\n            {title}\n          </h3>\n          <p\n            aria-live=\"polite\"\n            className=\"m-0 flex gap-4 text-[12.5px] leading-[18px] tracking-[-0.008em] tabular-nums\"\n            style={{ color: c.sub }}\n          >\n            <span>\n              {decided} of {items.length} reviewed\n            </span>\n            <span>\n              Agreement{\" \"}\n              {decided ? `${Math.round((agreed / decided) * 100)}%` : \"–\"}\n            </span>\n          </p>\n        </div>\n        <div\n          aria-hidden=\"true\"\n          className=\"mt-3 h-1 overflow-hidden rounded-full\"\n          style={{ background: c.track }}\n        >\n          <div\n            className=\"h-full origin-left rounded-full motion-safe:transition-transform motion-safe:duration-300\"\n            style={{\n              background: ACCENT,\n              transform: `scaleX(${items.length ? decided / items.length : 0})`,\n            }}\n          />\n        </div>\n      </header>\n\n      <div\n        className=\"grid border-t @3xl:grid-cols-[272px_minmax(0,1fr)]\"\n        style={{ borderColor: c.border }}\n      >\n        <div\n          className=\"flex flex-col gap-2 border-b p-3 @3xl:border-r @3xl:border-b-0\"\n          style={{ borderColor: c.border }}\n        >\n          <div\n            role=\"group\"\n            aria-label=\"Filter\"\n            className=\"relative grid h-8 grid-cols-2 rounded-full p-0.5\"\n            style={{ background: c.chip }}\n          >\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute top-0.5 bottom-0.5 left-0.5 w-[calc(50%-2px)] rounded-full motion-safe:transition-transform motion-safe:duration-300\"\n              style={{\n                background: c.tab,\n                transform: filter === \"low\" ? \"translateX(100%)\" : \"none\",\n              }}\n            />\n            {(\n              [\n                [\"all\", `All ${items.length}`],\n                [\"low\", `Needs a look ${lowCount}`],\n              ] as const\n            ).map(([value, label]) => (\n              <button\n                key={value}\n                type=\"button\"\n                data-filter={value}\n                aria-pressed={filter === value}\n                onClick={() => changeFilter(value)}\n                className={`relative cursor-pointer truncate rounded-full border-0 bg-transparent px-2 text-[12.5px] leading-[18px] font-[510] tracking-[-0.011em] tabular-nums motion-safe:transition-colors motion-safe:duration-200 ${RING}`}\n                style={{ color: filter === value ? c.text : c.sub }}\n              >\n                {label}\n              </button>\n            ))}\n          </div>\n\n          {/* Wide cards list the queue. Phones step through it instead. */}\n          <ul className=\"m-0 hidden h-[328px] list-none flex-col gap-0.5 overflow-y-auto p-0 @3xl:flex\">\n            {visible.map((item) => {\n              const d = decisions[item.id];\n              const low = item.confidence < lowConfidence;\n              return (\n                <li key={item.id}>\n                  <button\n                    type=\"button\"\n                    data-item={item.id}\n                    aria-current={item.id === selected ? \"true\" : undefined}\n                    onClick={() => {\n                      setSelected(item.id);\n                      setEditing(null);\n                    }}\n                    className={`flex w-full cursor-pointer items-center gap-2.5 rounded-lg border-0 bg-transparent px-2.5 py-2 text-left motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                    style={{\n                      background:\n                        item.id === selected ? c.row : \"transparent\",\n                    }}\n                  >\n                    <Dot\n                      size={8}\n                      color={d ? DECIDED[d].color : low ? ORANGE : c.track}\n                    />\n                    <span className=\"min-w-0 flex-1\">\n                      <span\n                        className=\"block truncate text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                        style={{ color: d ? c.sub : c.text }}\n                      >\n                        {item.title}\n                      </span>\n                      <span\n                        className=\"block truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                        style={{ color: c.faint }}\n                      >\n                        {item.source}\n                      </span>\n                    </span>\n                    <span\n                      className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                      style={{ color: c.faint }}\n                    >\n                      {item.confidence}%\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n\n          <div className=\"flex items-center justify-between gap-2 @3xl:hidden\">\n            <button\n              type=\"button\"\n              onClick={() => go(-1)}\n              disabled={at === 0}\n              className={`h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] disabled:cursor-default ${RING}`}\n              style={{ background: c.chip, color: at === 0 ? c.faint : c.soft }}\n            >\n              Previous\n            </button>\n            <span\n              className=\"text-[12.5px] leading-[18px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              {at + 1} of {visible.length}\n            </span>\n            <button\n              type=\"button\"\n              onClick={() => go(1)}\n              disabled={at >= visible.length - 1}\n              className={`h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] disabled:cursor-default ${RING}`}\n              style={{\n                background: c.chip,\n                color: at >= visible.length - 1 ? c.faint : c.soft,\n              }}\n            >\n              Next\n            </button>\n          </div>\n        </div>\n\n        {/* Every item shares one cell, so moving through the queue never changes the height. */}\n        <div className=\"grid p-5\">\n          {items.map((item) => {\n            const on = item.id === selected;\n            const d = decisions[item.id];\n            const text = drafts[item.id] ?? item.proposal;\n            const isEditing = editing === item.id;\n            const failed = item.checks.filter((k) => !k.pass).length;\n            return (\n              <article\n                key={item.id}\n                aria-hidden={!on}\n                inert={!on}\n                className={`flex min-w-0 flex-col [grid-area:1/1] motion-safe:transition-[opacity,visibility] motion-safe:duration-200 ${on ? \"visible opacity-100\" : \"invisible opacity-0\"}`}\n              >\n                <p\n                  className=\"m-0 text-[12px] leading-[16px] tracking-[-0.005em]\"\n                  style={{ color: c.faint }}\n                >\n                  {item.source}\n                </p>\n                <h4 className=\"m-0 mt-1 text-[16px] leading-[22px] font-[590] tracking-[-0.014em]\">\n                  {item.title}\n                </h4>\n\n                <div\n                  className=\"mt-3 grid rounded-xl border\"\n                  style={{\n                    background: c.inset,\n                    borderColor: isEditing ? ACCENT : c.border,\n                  }}\n                >\n                  <p\n                    className={`m-0 p-3.5 text-[13.5px] leading-[20px] tracking-[-0.011em] [grid-area:1/1] ${isEditing ? \"invisible\" : \"\"}`}\n                    style={{ color: c.soft }}\n                  >\n                    {text}\n                  </p>\n                  {isEditing && (\n                    <textarea\n                      ref={editor}\n                      aria-label=\"Edit the proposal\"\n                      value={text}\n                      onChange={(e) =>\n                        setDrafts((prev) => ({\n                          ...prev,\n                          [item.id]: e.target.value,\n                        }))\n                      }\n                      className=\"size-full resize-none rounded-xl border-0 bg-transparent p-3.5 text-[16px] leading-[20px] tracking-[-0.011em] outline-none [grid-area:1/1] @3xl:text-[13.5px]\"\n                      style={{ color: c.text }}\n                    />\n                  )}\n                </div>\n\n                <ul className=\"m-0 mt-3 list-none p-0\">\n                  {item.checks.map((check) => (\n                    <li\n                      key={check.label}\n                      className=\"flex items-center gap-2 py-[3px] text-[13px] leading-[20px] tracking-[-0.011em]\"\n                      style={{ color: check.pass ? c.sub : c.text }}\n                    >\n                      <Mark pass={check.pass} faint={c.faint} />\n                      <span className=\"truncate\">{check.label}</span>\n                    </li>\n                  ))}\n                </ul>\n\n                <div className=\"mt-3 flex items-center gap-3\">\n                  <span\n                    className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em]\"\n                    style={{ color: c.sub }}\n                  >\n                    Confidence\n                  </span>\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"h-1 min-w-0 flex-1 overflow-hidden rounded-full\"\n                    style={{ background: c.track }}\n                  >\n                    <span\n                      className=\"block h-full rounded-full\"\n                      style={{\n                        width: `${item.confidence}%`,\n                        background:\n                          item.confidence < lowConfidence ? ORANGE : ACCENT,\n                      }}\n                    />\n                  </span>\n                  <span\n                    className=\"shrink-0 text-[12px] leading-[16px] font-[510] tracking-[-0.005em] tabular-nums\"\n                    style={{ color: c.soft }}\n                  >\n                    {item.confidence}%\n                  </span>\n                </div>\n\n                <div className=\"mt-auto grid pt-4\">\n                  <div\n                    className={`flex items-center justify-end gap-2 [grid-area:1/1] ${d ? \"invisible\" : \"\"}`}\n                  >\n                    <p\n                      className=\"m-0 mr-auto hidden text-[12.5px] leading-[18px] tracking-[-0.008em] @3xl:block\"\n                      style={{ color: failed ? ORANGE : c.faint }}\n                    >\n                      {failed\n                        ? `${failed} ${failed === 1 ? \"check needs\" : \"checks need\"} you`\n                        : \"All checks passed\"}\n                    </p>\n                    <button\n                      type=\"button\"\n                      tabIndex={d ? -1 : 0}\n                      data-action=\"reject\"\n                      onClick={() => decide(item, \"rejected\")}\n                      className={`${action} ${RING}`}\n                      style={{ background: c.chip, color: c.soft }}\n                    >\n                      Reject {key(\"R\")}\n                    </button>\n                    <button\n                      type=\"button\"\n                      tabIndex={d ? -1 : 0}\n                      data-action=\"edit\"\n                      onClick={() => setEditing(isEditing ? null : item.id)}\n                      className={`${action} ${RING}`}\n                      style={{ background: c.chip, color: c.soft }}\n                    >\n                      {isEditing ? \"Done\" : \"Edit\"} {key(\"E\")}\n                    </button>\n                    <button\n                      type=\"button\"\n                      tabIndex={d ? -1 : 0}\n                      data-action=\"approve\"\n                      onClick={() =>\n                        decide(\n                          item,\n                          drafts[item.id] !== undefined &&\n                            drafts[item.id] !== item.proposal\n                            ? \"edited\"\n                            : \"approved\",\n                        )\n                      }\n                      className={`${action} ${RING}`}\n                      style={{ background: c.btn, color: c.btnText }}\n                    >\n                      Approve {key(\"A\", true)}\n                    </button>\n                  </div>\n                  <div\n                    className={`flex items-center justify-between gap-3 [grid-area:1/1] ${d ? \"\" : \"invisible\"}`}\n                  >\n                    <p className=\"m-0 flex min-w-0 items-center gap-2 text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                      <Dot size={8} color={d ? DECIDED[d].color : c.track} />\n                      <span className=\"truncate\">{d && DECIDED[d].label}</span>\n                    </p>\n                    <button\n                      type=\"button\"\n                      tabIndex={d ? 0 : -1}\n                      onClick={() => reopen(item)}\n                      className={`h-9 shrink-0 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n                      style={{ background: c.chip, color: c.soft }}\n                    >\n                      Reopen\n                    </button>\n                  </div>\n                </div>\n              </article>\n            );\n          })}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}