{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bot-message-tray",
  "title": "Bot Message Tray",
  "description": "One inbox for everything your bots say to you: questions that need an answer, one-tap replies, and updates you can read and move on from.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/bot-message-tray/bot-message-tray.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type BotMessageKind = \"question\" | \"update\";\n\nexport interface BotMessage {\n  id: string;\n  bot: string;\n  role: string;\n  /** Short time, e.g. \"14:32\". */\n  time: string;\n  kind: BotMessageKind;\n  text: string;\n  /** One-tap answers. */\n  replies?: string[];\n  /** What the bot says once you've answered. */\n  ack?: string;\n}\n\nexport interface BotMessageTrayProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  messages?: BotMessage[];\n  onReply?: (message: BotMessage, text: string) => void;\n}\n\ntype Filter = \"all\" | BotMessageKind;\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst ORANGE = \"#FC7840\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst ROW = 64;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    tile: \"#161718\",\n    bubble: \"#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    hover: \"rgba(255,255,255,0.03)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    tile: \"#F7F8F8\",\n    bubble: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    hover: \"rgba(8,9,10,0.02)\",\n  },\n};\n\nconst DEFAULT_MESSAGES: BotMessage[] = [\n  {\n    id: \"patch\",\n    bot: \"Patch\",\n    role: \"Code\",\n    time: \"14:32\",\n    kind: \"question\",\n    text: \"I can't reach staging. Should I run the migration on the test database instead?\",\n    replies: [\"Yes, use the test database\", \"No, wait for staging\"],\n    ack: \"Got it. I'll carry on and tell you when it's done.\",\n  },\n  {\n    id: \"tally\",\n    bot: \"Tally\",\n    role: \"Finance\",\n    time: \"14:05\",\n    kind: \"question\",\n    text: \"Invoice 2041 is $12 higher than the order. Pay it, or ask the supplier first?\",\n    replies: [\"Ask the supplier\", \"Pay it\"],\n    ack: \"Understood. I've noted that on the invoice.\",\n  },\n  {\n    id: \"aria\",\n    bot: \"Aria\",\n    role: \"Writer\",\n    time: \"13:48\",\n    kind: \"update\",\n    text: \"The March release notes are ready for you to read.\",\n  },\n  {\n    id: \"sift\",\n    bot: \"Sift\",\n    role: \"Support\",\n    time: \"12:20\",\n    kind: \"question\",\n    text: \"A customer asked for a refund outside the 30 days. Should I make an exception?\",\n    replies: [\"Make an exception\", \"Decline politely\"],\n    ack: \"Thanks. I'll reply to them now.\",\n  },\n  {\n    id: \"relay\",\n    bot: \"Relay\",\n    role: \"Operations\",\n    time: \"11:02\",\n    kind: \"update\",\n    text: \"The warehouse sync finished. All 214 products are up to date.\",\n  },\n];\n\nconst FILTERS: { id: Filter; label: string }[] = [\n  { id: \"all\", label: \"All\" },\n  { id: \"question\", label: \"Questions\" },\n  { id: \"update\", label: \"Updates\" },\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 BotMessageTray({\n  theme = \"dark\",\n  title = \"Messages from bots\",\n  messages = DEFAULT_MESSAGES,\n  onReply,\n  className,\n  style,\n  ...rest\n}: BotMessageTrayProps) {\n  const c = PALETTES[theme];\n  const [filter, setFilter] = React.useState<Filter>(\"all\");\n  const [opened, setOpened] = React.useState(false);\n  const [current, setCurrent] = React.useState(messages[0]?.id ?? \"\");\n  const [replied, setReplied] = React.useState<Record<string, string>>({});\n  const [acked, setAcked] = React.useState<string[]>([]);\n  const [seen, setSeen] = React.useState<string[]>([]);\n  const [draft, setDraft] = React.useState(\"\");\n  const timers = React.useRef<number[]>([]);\n\n  React.useEffect(() => {\n    const running = timers.current;\n    return () => running.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const waiting = messages.filter(\n    (m) => m.kind === \"question\" && !replied[m.id],\n  ).length;\n  const count = (id: Filter) =>\n    id === \"all\"\n      ? messages.length\n      : messages.filter((m) => m.kind === id).length;\n  const shown = messages.filter((m) => filter === \"all\" || m.kind === filter);\n  const message = messages.find((m) => m.id === current);\n\n  const open = (id: string) => {\n    setCurrent(id);\n    setOpened(true);\n    setDraft(\"\");\n    setSeen((prev) => (prev.includes(id) ? prev : [...prev, id]));\n  };\n\n  const send = (text: string) => {\n    const body = text.trim();\n    if (!message || !body || replied[message.id]) return;\n    const id = message.id;\n    setReplied((prev) => ({ ...prev, [id]: body }));\n    setDraft(\"\");\n    onReply?.(message, body);\n    timers.current.push(\n      window.setTimeout(() => setAcked((prev) => [...prev, id]), 700),\n    );\n  };\n\n  const answered = message ? replied[message.id] : undefined;\n\n  return (\n    <section\n      aria-label={title}\n      className={`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\">\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              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {messages.length} today\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p\n              aria-live=\"polite\"\n              className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\"\n            >\n              {waiting}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px]\"\n              style={{ color: c.sub }}\n            >\n              Waiting on you\n            </p>\n          </div>\n        </div>\n        <div role=\"group\" aria-label=\"Filter\" className=\"mt-3 flex gap-1.5\">\n          {FILTERS.map((f) => {\n            const on = filter === f.id;\n            return (\n              <button\n                key={f.id}\n                type=\"button\"\n                data-filter={f.id}\n                aria-pressed={on}\n                tabIndex={opened ? -1 : 0}\n                onClick={() => setFilter(f.id)}\n                className={`flex h-7 cursor-pointer items-center gap-2 rounded-full border-0 px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                style={{\n                  background: on ? c.chip : \"transparent\",\n                  color: on ? c.text : c.sub,\n                }}\n              >\n                {f.label}\n                <span className=\"tabular-nums\" style={{ color: c.sub }}>\n                  {count(f.id)}\n                </span>\n              </button>\n            );\n          })}\n        </div>\n      </div>\n\n      {/* The list and the conversation share one cell, so opening a message never resizes the tray. */}\n      <div\n        className=\"grid overflow-hidden rounded-b-2xl border-t\"\n        style={{ borderColor: c.border, height: messages.length * ROW }}\n      >\n        <ul\n          aria-hidden={opened}\n          inert={opened}\n          className=\"relative m-0 list-none overflow-hidden p-0 [grid-area:1/1] motion-safe:transition-[transform,opacity] motion-safe:duration-300\"\n          style={{\n            transform: opened ? \"translateX(-16%)\" : \"none\",\n            opacity: opened ? 0 : 1,\n          }}\n        >\n          {messages.map((m) => {\n            const at = shown.indexOf(m);\n            const on = at >= 0;\n            const done = replied[m.id];\n            const unread = !seen.includes(m.id) && !done;\n            return (\n              <li\n                key={m.id}\n                aria-hidden={!on}\n                inert={!on}\n                className=\"motion-safe:transition-[transform,opacity] motion-safe:duration-300\"\n                style={{\n                  position: \"absolute\",\n                  top: 0,\n                  left: 0,\n                  right: 0,\n                  height: ROW,\n                  opacity: on ? 1 : 0,\n                  visibility: on ? \"visible\" : \"hidden\",\n                  transform: `translateY(${(on ? at : messages.indexOf(m)) * ROW}px)`,\n                }}\n              >\n                <button\n                  type=\"button\"\n                  data-message={m.id}\n                  onClick={() => open(m.id)}\n                  className={`flex size-full cursor-pointer items-center gap-3 border-0 border-b bg-transparent px-5 text-left ${RING}`}\n                  style={{ borderColor: c.border, borderBottomStyle: \"solid\" }}\n                >\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"flex shrink-0 items-center justify-center rounded-lg text-[13px] leading-[20px] font-[590]\"\n                    style={{\n                      width: 32,\n                      height: 32,\n                      background: c.tile,\n                      color: c.soft,\n                    }}\n                  >\n                    {m.bot.slice(0, 1)}\n                  </span>\n                  <span className=\"min-w-0 flex-1\">\n                    <span className=\"flex items-center justify-between gap-3\">\n                      <span\n                        className=\"truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                        style={{ color: c.text }}\n                      >\n                        {m.bot}\n                      </span>\n                      <span\n                        className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                        style={{ color: c.faint }}\n                      >\n                        {m.time}\n                      </span>\n                    </span>\n                    <span className=\"flex items-center justify-between gap-3\">\n                      <span\n                        className=\"truncate text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n                        style={{ color: done ? c.faint : c.sub }}\n                      >\n                        {done ? `You: ${done}` : m.text}\n                      </span>\n                      {unread && (\n                        <Dot\n                          size={8}\n                          color={m.kind === \"question\" ? ORANGE : ACCENT}\n                        />\n                      )}\n                    </span>\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n\n        <div\n          aria-hidden={!opened}\n          inert={!opened}\n          className=\"flex min-h-0 min-w-0 flex-col [grid-area:1/1] motion-safe:transition-[transform,opacity] motion-safe:duration-300\"\n          style={{\n            transform: opened ? \"none\" : \"translateX(100%)\",\n            opacity: opened ? 1 : 0,\n          }}\n        >\n          <div className=\"flex items-center gap-2 px-3 py-2\">\n            <button\n              type=\"button\"\n              data-back=\"\"\n              aria-label=\"Back to messages\"\n              onClick={() => setOpened(false)}\n              className={`flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 ${RING}`}\n              style={{ background: c.chip, color: c.soft }}\n            >\n              <svg\n                aria-hidden=\"true\"\n                viewBox=\"0 0 16 16\"\n                width=\"16\"\n                height=\"16\"\n                fill=\"none\"\n                className=\"block\"\n              >\n                <path\n                  d=\"M10 3.5 5.5 8l4.5 4.5\"\n                  stroke=\"currentColor\"\n                  strokeWidth=\"1.5\"\n                  strokeLinecap=\"round\"\n                  strokeLinejoin=\"round\"\n                />\n              </svg>\n            </button>\n            <p className=\"m-0 truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n              {message?.bot}\n              <span className=\"font-normal\" style={{ color: c.faint }}>\n                {\" \"}\n                {message?.role}\n              </span>\n            </p>\n          </div>\n\n          <div className=\"flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-5 pb-2\">\n            <p\n              className=\"m-0 max-w-[86%] self-start rounded-xl px-3 py-2 text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n              style={{ background: c.bubble, color: c.soft }}\n            >\n              {message?.text}\n            </p>\n            {answered && (\n              <p\n                className=\"m-0 max-w-[86%] self-end rounded-xl px-3 py-2 text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                style={{ background: ACCENT, color: \"#FFFFFF\" }}\n              >\n                {answered}\n              </p>\n            )}\n            {answered && message?.ack && acked.includes(message.id) && (\n              <p\n                className=\"m-0 max-w-[86%] self-start rounded-xl px-3 py-2 text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                style={{ background: c.bubble, color: c.soft }}\n              >\n                {message.ack}\n              </p>\n            )}\n          </div>\n\n          {message?.kind === \"question\" && !answered ? (\n            <div className=\"px-5 pb-4\">\n              <div className=\"flex flex-wrap gap-1.5\">\n                {message.replies?.map((reply, i) => (\n                  <button\n                    key={reply}\n                    type=\"button\"\n                    data-reply={i}\n                    onClick={() => send(reply)}\n                    className={`h-7 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] ${RING}`}\n                    style={{ background: c.chip, color: c.text }}\n                  >\n                    {reply}\n                  </button>\n                ))}\n              </div>\n              <form\n                className=\"mt-2\"\n                onSubmit={(e) => {\n                  e.preventDefault();\n                  send(draft);\n                }}\n              >\n                <input\n                  value={draft}\n                  onChange={(e) => setDraft(e.target.value)}\n                  aria-label={`Reply to ${message.bot}`}\n                  placeholder=\"Or write your own reply\"\n                  className=\"h-9 w-full rounded-full border px-3.5 text-[16px] tracking-[-0.011em] outline-none focus:border-[#5E6AD2] sm:text-[13px]\"\n                  style={{\n                    background: c.bubble,\n                    borderColor: c.border,\n                    color: c.text,\n                  }}\n                />\n              </form>\n            </div>\n          ) : (\n            <p\n              className=\"m-0 px-5 pb-4 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n              style={{ color: c.faint }}\n            >\n              {answered ? \"Replied\" : \"No reply needed\"}\n            </p>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}