{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inbox-01",
  "title": "Inbox",
  "description": "A message list where archive and delete collapse the row in place with an Undo, and a reading pane whose toolbar archives on a second click and deletes on a hold.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@sureui/confirm-button",
    "@sureui/undoable",
    "button",
    "card"
  ],
  "files": [
    {
      "path": "components/blocks/inbox-01/inbox.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArchiveIcon, ArrowLeftIcon, CheckIcon, Trash2Icon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Card, CardTitle } from \"@/components/ui/card\"\nimport { ConfirmButton } from \"@/components/ui/sureui/confirm-button\"\nimport { Undoable } from \"@/components/ui/sureui/undoable\"\n\ntype Message = {\n  id: string\n  from: string\n  subject: string\n  body: string\n  time: string\n  unread?: boolean\n}\n\ntype InboxProps = {\n  initialMessages?: Message[]\n  className?: string\n}\n\nconst sampleMessages: Message[] = [\n  {\n    id: \"msg_1\",\n    from: \"Priya Shah\",\n    subject: \"Launch checklist\",\n    body: \"Final checklist for Thursday. Anything missing before we ship?\",\n    time: \"9:41\",\n    unread: true,\n  },\n  {\n    id: \"msg_2\",\n    from: \"Marcus Chen\",\n    subject: \"Re: Q3 numbers\",\n    body: \"Can you check the churn figures before Monday?\",\n    time: \"8:15\",\n    unread: true,\n  },\n  {\n    id: \"msg_3\",\n    from: \"Lena Fischer\",\n    subject: \"Design review moved to Friday\",\n    body: \"It clashes with the all-hands, so it's now Friday at 2pm.\",\n    time: \"Yesterday\",\n  },\n  {\n    id: \"msg_4\",\n    from: \"Omar Farouk\",\n    subject: \"Offsite venue options\",\n    body: \"Three venues are free the week of the 20th. Vote by Wednesday.\",\n    time: \"Mon\",\n  },\n]\n\nfunction request() {\n  return Promise.resolve()\n}\n\nfunction Inbox({ initialMessages = sampleMessages, className }: InboxProps) {\n  const [messages, setMessages] = React.useState(initialMessages)\n  const [openId, setOpenId] = React.useState(initialMessages[0]?.id ?? null)\n  const [reading, setReading] = React.useState(false)\n  const [leaving, setLeaving] = React.useState<Record<string, string>>({})\n  const rows = React.useRef(new Map<string, HTMLButtonElement>())\n  const readerRef = React.useRef<HTMLDivElement>(null)\n  const titleRef = React.useRef<HTMLHeadingElement>(null)\n\n  const open = messages.find((message) => message.id === openId)\n\n  function neighbour(id: string) {\n    const staying = messages.filter(\n      (message) => message.id === id || !leaving[message.id]\n    )\n    const index = staying.findIndex((message) => message.id === id)\n    return (staying[index + 1] ?? staying[index - 1])?.id ?? null\n  }\n\n  function focusRow(id: string | null) {\n    requestAnimationFrame(() => {\n      const reader = readerRef.current\n      const inReader = reader?.contains(document.activeElement)\n      if (inReader && reader?.checkVisibility?.() !== false) return\n      if (id) rows.current.get(id)?.focus()\n    })\n  }\n\n  function read(id: string) {\n    setOpenId(id)\n    setReading(true)\n    setMessages((prev) =>\n      prev.map((message) =>\n        message.id === id ? { ...message, unread: false } : message\n      )\n    )\n    requestAnimationFrame(() => {\n      if (readerRef.current?.checkVisibility?.() === false) return\n      if (rows.current.get(id)?.checkVisibility?.() === false) {\n        titleRef.current?.focus()\n      }\n    })\n  }\n\n  function leave(id: string, action = \"\") {\n    setLeaving((prev) => ({ ...prev, [id]: action }))\n    if (action && openId === id) setOpenId(neighbour(id))\n  }\n\n  function drop(id: string) {\n    setMessages((prev) => prev.filter((message) => message.id !== id))\n  }\n\n  async function finish(id: string) {\n    await request()\n    const next = neighbour(id)\n    drop(id)\n    setOpenId(next)\n    setReading(false)\n    focusRow(next)\n  }\n\n  return (\n    <Card className={cn(\"@container/inbox w-full py-0 text-sm\", className)}>\n      <div className=\"grid min-h-80 @2xl/inbox:grid-cols-[2fr_3fr]\">\n        <section\n          aria-label=\"Inbox\"\n          className={cn(\n            \"min-w-0 @2xl/inbox:border-r\",\n            reading && \"hidden @2xl/inbox:block\"\n          )}\n        >\n          <div className=\"flex h-12 items-center border-b px-4\">\n            <CardTitle>Inbox</CardTitle>\n          </div>\n          {messages.length === 0 && (\n            <p className=\"p-4 text-muted-foreground\">No messages</p>\n          )}\n          <ul className=\"divide-y\">\n            {messages.map((message) => (\n              <Undoable\n                key={message.id}\n                render={\n                  <li\n                    data-open={message.id === openId || undefined}\n                    className=\"group/row relative has-data-[slot=undoable-strip]:flex has-data-[slot=undoable-strip]:items-center has-data-[slot=undoable-strip]:gap-2 has-data-[slot=undoable-strip]:px-4 has-data-[slot=undoable-strip]:py-2 @2xl/inbox:data-open:bg-muted/60\"\n                  />\n                }\n                label={`${leaving[message.id]}: ${message.subject}`}\n                onConfirm={() => drop(message.id)}\n                onCancel={() => leave(message.id)}\n              >\n                {({ remove }) => (\n                  <>\n                    <button\n                      ref={(node) => {\n                        if (node) rows.current.set(message.id, node)\n                        else rows.current.delete(message.id)\n                      }}\n                      type=\"button\"\n                      aria-current={message.id === openId || undefined}\n                      className=\"grid w-full gap-1 px-4 py-3 text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset\"\n                      onClick={() => read(message.id)}\n                    >\n                      <span className=\"flex items-baseline justify-between gap-3\">\n                        <span\n                          className={cn(\n                            \"truncate\",\n                            message.unread && \"font-semibold\"\n                          )}\n                        >\n                          {message.unread && (\n                            <span className=\"sr-only\">Unread, </span>\n                          )}\n                          {message.from}\n                        </span>\n                        <span className=\"shrink-0 text-xs text-muted-foreground\">\n                          {message.time}\n                        </span>\n                      </span>\n                      <span className=\"truncate pr-16 text-muted-foreground\">\n                        {message.subject}\n                      </span>\n                    </button>\n                    <div className=\"absolute right-2.5 bottom-2 flex gap-1 opacity-0 group-hover/row:opacity-100 group-has-[:focus-visible]/row:opacity-100 pointer-coarse:opacity-100\">\n                      <Button\n                        variant=\"ghost\"\n                        size=\"icon-sm\"\n                        aria-label={`Archive ${message.subject}`}\n                        title=\"Archive\"\n                        onClick={() => {\n                          leave(message.id, \"Archived\")\n                          remove()\n                        }}\n                      >\n                        <ArchiveIcon />\n                      </Button>\n                      <Button\n                        variant=\"ghost\"\n                        size=\"icon-sm\"\n                        aria-label={`Delete ${message.subject}`}\n                        title=\"Delete\"\n                        onClick={() => {\n                          leave(message.id, \"Deleted\")\n                          remove()\n                        }}\n                      >\n                        <Trash2Icon />\n                      </Button>\n                    </div>\n                  </>\n                )}\n              </Undoable>\n            ))}\n          </ul>\n        </section>\n        <div\n          ref={readerRef}\n          role=\"region\"\n          aria-label=\"Message\"\n          className={cn(\"min-w-0\", !reading && \"hidden @2xl/inbox:block\")}\n        >\n          <div className=\"flex h-12 items-center gap-1 border-b px-2\">\n            <Button\n              variant=\"ghost\"\n              size=\"icon-sm\"\n              aria-label=\"Back to inbox\"\n              className=\"@2xl/inbox:hidden\"\n              onClick={() => {\n                setReading(false)\n                focusRow(openId)\n              }}\n            >\n              <ArrowLeftIcon />\n            </Button>\n            {open && (\n              <>\n                <span className=\"hidden px-2 text-xs text-muted-foreground @2xl/inbox:inline\">\n                  {messages.indexOf(open) + 1} of {messages.length}\n                </span>\n                <div className=\"ml-auto flex gap-1\">\n                  <ConfirmButton\n                    gesture=\"click-again\"\n                    variant=\"ghost\"\n                    size=\"icon-sm\"\n                    aria-label=\"Archive\"\n                    title=\"Archive\"\n                    confirmLabel={<CheckIcon />}\n                    announcements={{ armed: \"Click again to archive\" }}\n                    onConfirm={() => finish(open.id)}\n                  >\n                    <ArchiveIcon />\n                  </ConfirmButton>\n                  <ConfirmButton\n                    gesture=\"hold\"\n                    variant=\"ghost\"\n                    size=\"icon-sm\"\n                    aria-label=\"Hold to delete\"\n                    title=\"Hold to delete\"\n                    confirmLabel={<CheckIcon />}\n                    onConfirm={() => finish(open.id)}\n                  >\n                    <Trash2Icon />\n                  </ConfirmButton>\n                </div>\n              </>\n            )}\n          </div>\n          {open ? (\n            <article className=\"grid gap-4 p-4 sm:p-6\">\n              <div className=\"grid gap-1\">\n                <h3\n                  ref={titleRef}\n                  tabIndex={-1}\n                  className=\"font-heading text-lg font-medium outline-none\"\n                >\n                  {open.subject}\n                </h3>\n                <p className=\"text-muted-foreground\">\n                  {open.from} · {open.time}\n                </p>\n              </div>\n              <p className=\"leading-relaxed text-pretty\">{open.body}</p>\n            </article>\n          ) : (\n            <p className=\"p-4 text-muted-foreground\">No message open</p>\n          )}\n        </div>\n      </div>\n    </Card>\n  )\n}\n\nexport { Inbox, type InboxProps, type Message }\n",
      "type": "registry:component",
      "target": "@components/inbox.tsx"
    }
  ],
  "categories": [
    "block",
    "mail"
  ],
  "type": "registry:block"
}