{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "threaded-replies",
  "title": "Threaded Replies",
  "description": "A contextual discussion thread with nested replies, reversible reactions, collapsible branches and resolve/reopen controls.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/threaded-replies/threaded-replies.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  Layers,\n  MessageSquare,\n  ThumbsUp,\n  Reply,\n  Check,\n  X,\n  Send,\n} from \"lucide-react\";\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction Frame({\n  name,\n  title,\n  description,\n  theme,\n  className,\n  toolbar,\n  sidebar,\n  children,\n}: {\n  name: string;\n  title: string;\n  description: string;\n  theme: \"dark\" | \"light\";\n  className?: string;\n  toolbar?: React.ReactNode;\n  sidebar?: React.ReactNode;\n  children: React.ReactNode;\n}) {\n  const dark = theme === \"dark\";\n  return (\n    <section\n      aria-label={name}\n      className={twMerge(\n        clsx(\n          \"mx-auto w-full max-w-[1100px] overflow-hidden rounded-xl border font-sans antialiased shadow-[0_12px_60px_#00000012]\",\n          className,\n        ),\n      )}\n      style={\n        {\n          background: dark ? \"#151517\" : \"#fff\",\n          color: dark ? \"#e9e9ed\" : \"#28282d\",\n          borderColor: dark ? \"#ffffff14\" : \"#18181b18\",\n          \"--board-panel\": dark ? \"#1b1b1f\" : \"#fafafa\",\n          \"--board-canvas\": dark ? \"#151517\" : \"#ffffff\",\n          \"--board-input\": dark ? \"#242428\" : \"#f1f1f3\",\n          \"--board-accent\": dark ? \"#aaa1ee\" : \"#6854b5\",\n        } as React.CSSProperties\n      }\n    >\n      <header className=\"flex h-12 items-center justify-between gap-3 border-b border-current/[0.07] px-4 text-[11px]\">\n        <div className=\"flex items-center gap-2\">\n          <span className=\"flex size-5 items-center justify-center rounded bg-[#6e67d4] text-[10px] font-semibold text-white\">\n            a\n          </span>\n          <span className=\"font-medium\">Acme</span>\n          <span className=\"px-2 opacity-20\">/</span>\n          <Layers size={12} className=\"opacity-45\" />\n          <span className=\"opacity-65\">{name}</span>\n        </div>\n        <div className=\"flex items-center gap-2\">\n          <span className=\"hidden text-[10px] opacity-35 sm:block\">\n            Product workspace\n          </span>\n          <span className=\"flex size-5 items-center justify-center rounded-full bg-current/5 text-[8px] opacity-60\">\n            AL\n          </span>\n        </div>\n      </header>\n      <div\n        className={\n          sidebar\n            ? \"grid min-w-0 md:grid-cols-[184px_minmax(0,1fr)]\"\n            : \"min-w-0\"\n        }\n      >\n        {sidebar && (\n          <aside className=\"border-b border-current/[0.07] bg-black/[0.025] px-3 py-4 md:border-b-0 md:border-r\">\n            {sidebar}\n          </aside>\n        )}\n        <div className=\"min-w-0\">\n          <div className=\"px-5 pb-4 pt-5 sm:px-7\">\n            <h2 className=\"text-[17px] font-semibold tracking-[-0.025em]\">\n              {title}\n            </h2>\n            <p className=\"mt-1 text-[11px] leading-relaxed opacity-45\">\n              {description}\n            </p>\n          </div>\n          {toolbar && (\n            <div className=\"flex flex-wrap items-center justify-between gap-2 border-b border-current/[0.07] px-5 pb-3 sm:px-7\">\n              {toolbar}\n            </div>\n          )}\n          {children}\n        </div>\n      </div>\n    </section>\n  );\n}\nconst button =\n  \"inline-flex items-center justify-center gap-1.5 rounded-md border border-current/10 px-2.5 py-1.5 text-[11px] transition-colors hover:bg-current/5 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-25\";\nconst primary =\n  \"inline-flex items-center justify-center gap-1.5 rounded-md border border-white/15 bg-[#6e67d4] px-3 py-1.5 text-[11px] font-medium text-white hover:bg-[#7a73df] disabled:cursor-not-allowed disabled:opacity-40 focus-visible:outline-2 focus-visible:outline-offset-2\";\nconst input =\n  \"min-w-0 rounded-md border border-current/10 bg-[var(--board-input)] px-3 py-2 text-xs outline-none focus:border-[#9690da]\";\n\nfunction Avatar({ name, color = \"#9690da\" }: { name: string; color?: string }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"flex size-7 shrink-0 items-center justify-center rounded-md border text-[9px] font-medium\"\n      style={{ color, background: `${color}18`, borderColor: `${color}20` }}\n    >\n      {name\n        .split(\" \")\n        .map((part) => part[0])\n        .slice(0, 2)\n        .join(\"\")}\n    </span>\n  );\n}\n\nexport interface ThreadMessage {\n  id: string;\n  parentId?: string;\n  author: string;\n  text: string;\n  time: string;\n  likes: number;\n}\nexport interface ThreadedRepliesProps {\n  title?: string;\n  theme?: \"dark\" | \"light\";\n  initialMessages?: ThreadMessage[];\n  onMessagesChange?: (messages: ThreadMessage[]) => void;\n  initialResolved?: boolean;\n  onResolvedChange?: (resolved: boolean) => void;\n  currentUser?: string;\n  className?: string;\n}\nconst seed: ThreadMessage[] = [\n  {\n    id: \"t1\",\n    author: \"Sofia Kim\",\n    text: \"The quieter direction is starting to feel right. Can we keep the primary action visible, but let the content do more of the talking?\",\n    time: \"24 min ago\",\n    likes: 3,\n  },\n  {\n    id: \"t2\",\n    parentId: \"t1\",\n    author: \"Maya Chen\",\n    text: \"Agreed. I reduced the contrast on the secondary controls and tightened the spacing. The updated frame is ready for another look.\",\n    time: \"18 min ago\",\n    likes: 2,\n  },\n  {\n    id: \"t3\",\n    parentId: \"t2\",\n    author: \"James Davis\",\n    text: \"This also makes the keyboard order much clearer. I'll check the focus states in both themes.\",\n    time: \"12 min ago\",\n    likes: 1,\n  },\n  {\n    id: \"t4\",\n    parentId: \"t1\",\n    author: \"Alex Lee\",\n    text: \"Let's ship the smaller version first and learn from the next round of feedback.\",\n    time: \"5 min ago\",\n    likes: 2,\n  },\n];\nexport function ThreadedReplies({\n  title = \"Workspace navigation\",\n  theme = \"dark\",\n  initialMessages = seed,\n  onMessagesChange,\n  initialResolved = false,\n  onResolvedChange,\n  currentUser = \"You\",\n  className,\n}: ThreadedRepliesProps) {\n  const [messages, setMessages] = React.useState(() =>\n    initialMessages.map((message) => ({ ...message })),\n  );\n  const [resolved, setResolved] = React.useState(initialResolved);\n  const [liked, setLiked] = React.useState<string[]>([]);\n  const [collapsed, setCollapsed] = React.useState<string[]>([]);\n  const [replyTo, setReplyTo] = React.useState<string | null>(null);\n  const [draft, setDraft] = React.useState(\"\");\n  const textarea = React.useRef<HTMLTextAreaElement>(null);\n  const current = React.useRef(messages);\n  const update = (next: ThreadMessage[]) => {\n    current.current = next;\n    setMessages(next);\n    onMessagesChange?.(next);\n  };\n  const toggleResolved = () => {\n    setResolved(!resolved);\n    onResolvedChange?.(!resolved);\n  };\n  const reply = (message: ThreadMessage) => {\n    setReplyTo(message.id);\n    setCollapsed((values) => values.filter((id) => id !== message.id));\n    textarea.current?.focus();\n  };\n  const like = (message: ThreadMessage) => {\n    const has = liked.includes(message.id);\n    update(\n      current.current.map((item) =>\n        item.id === message.id\n          ? { ...item, likes: Math.max(0, item.likes + (has ? -1 : 1)) }\n          : item,\n      ),\n    );\n    setLiked((values) =>\n      has ? values.filter((id) => id !== message.id) : [...values, message.id],\n    );\n  };\n  const ids = new Set(messages.map((message) => message.id));\n  const roots = messages.filter(\n    (message) => !message.parentId || !ids.has(message.parentId),\n  );\n  const target = messages.find((message) => message.id === replyTo);\n  const render = (\n    message: ThreadMessage,\n    depth: number,\n    ancestors: string[],\n  ): React.ReactNode => {\n    if (ancestors.includes(message.id)) return null;\n    const children = messages.filter((item) => item.parentId === message.id);\n    return (\n      <article\n        key={message.id}\n        aria-label={`Message by ${message.author}`}\n        className={\n          depth\n            ? depth <= 3\n              ? \"mt-4 border-l border-current/10 pl-3 sm:pl-5\"\n              : \"mt-4\"\n            : \"py-5\"\n        }\n      >\n        <div className=\"flex items-start gap-2.5\">\n          <Avatar\n            name={message.author}\n            color={depth % 2 ? \"#79a798\" : \"#9690da\"}\n          />\n          <div className=\"min-w-0 flex-1\">\n            <div className=\"flex flex-wrap items-center gap-2\">\n              <h3 className=\"text-[11px] font-medium\">{message.author}</h3>\n              {message.author === currentUser && (\n                <span className=\"text-[9px] text-[var(--board-accent)]\">\n                  You\n                </span>\n              )}\n              <span className=\"text-[10px] opacity-30\">{message.time}</span>\n            </div>\n            <p className=\"mt-2 whitespace-pre-wrap break-words text-[12px] leading-[1.8] opacity-75\">\n              {message.text}\n            </p>\n            <div className=\"mt-3 flex flex-wrap items-center gap-3\">\n              <button\n                aria-label={`${liked.includes(message.id) ? \"Unlike\" : \"Like\"} message by ${message.author}`}\n                aria-pressed={liked.includes(message.id)}\n                onClick={() => like(message)}\n                className=\"flex items-center gap-1.5 rounded border border-current/10 px-2 py-1 text-[10px]\"\n                style={{\n                  color: liked.includes(message.id)\n                    ? \"var(--board-accent)\"\n                    : undefined,\n                }}\n              >\n                <ThumbsUp size={11} />\n                {message.likes}\n              </button>\n              <button\n                disabled={resolved}\n                onClick={() => reply(message)}\n                aria-label={`Reply to ${message.author}`}\n                className=\"flex items-center gap-1 text-[10px] opacity-45 hover:opacity-100 disabled:opacity-20\"\n              >\n                <Reply size={11} /> Reply\n              </button>\n              {children.length > 0 && (\n                <button\n                  aria-expanded={!collapsed.includes(message.id)}\n                  onClick={() =>\n                    setCollapsed((values) =>\n                      values.includes(message.id)\n                        ? values.filter((id) => id !== message.id)\n                        : [...values, message.id],\n                    )\n                  }\n                  className=\"text-[10px] opacity-40\"\n                >\n                  {collapsed.includes(message.id) ? \"Show\" : \"Hide\"}{\" \"}\n                  {children.length}{\" \"}\n                  {children.length === 1 ? \"reply\" : \"replies\"}\n                </button>\n              )}\n              {message.author === currentUser && (\n                <button\n                  aria-label=\"Delete your reply\"\n                  onClick={() => {\n                    update(\n                      current.current\n                        .filter((item) => item.id !== message.id)\n                        .map((item) =>\n                          item.parentId === message.id\n                            ? { ...item, parentId: message.parentId }\n                            : item,\n                        ),\n                    );\n                    if (replyTo === message.id) setReplyTo(null);\n                  }}\n                  className=\"text-[10px] opacity-35\"\n                >\n                  Delete\n                </button>\n              )}\n            </div>\n            {!collapsed.includes(message.id) &&\n              children.map((child) =>\n                render(child, depth + 1, [...ancestors, message.id]),\n              )}\n          </div>\n        </div>\n      </article>\n    );\n  };\n  return (\n    <Frame\n      name=\"Discussion\"\n      title={title}\n      description=\"DES-142 · Design review · Product experience\"\n      theme={theme}\n      className={className}\n      toolbar={\n        <>\n          <div className=\"flex items-center gap-2 text-[10px]\">\n            <MessageSquare size={13} className=\"opacity-45\" />\n            <span>Design review</span>\n            <span className=\"ml-1 rounded border border-current/10 px-1.5 py-0.5 opacity-40\">\n              {messages.length} messages\n            </span>\n          </div>\n          <button\n            className={resolved ? button : primary}\n            aria-pressed={resolved}\n            onClick={toggleResolved}\n          >\n            <Check size={12} />\n            {resolved ? \"Reopen discussion\" : \"Resolve discussion\"}\n          </button>\n        </>\n      }\n    >\n      <div className=\"bg-[var(--board-canvas)] px-5 sm:px-8\">\n        <div className=\"border-b border-current/[0.07] py-6\">\n          <div className=\"mb-3 flex flex-wrap items-center gap-2 text-[10px]\">\n            <span className=\"flex items-center gap-1.5 rounded border border-current/10 px-2 py-1\">\n              <span className=\"size-1.5 rounded-full bg-[#bda478]\" /> In review\n            </span>\n            <span className=\"rounded border border-current/10 px-2 py-1 opacity-50\">\n              Improvement\n            </span>\n          </div>\n          <h3 className=\"text-[21px] font-semibold tracking-[-0.035em]\">\n            Make room for the work.\n          </h3>\n          <p className=\"mt-3 max-w-xl text-[12px] leading-[1.8] opacity-60\">\n            Refine the navigation hierarchy so projects feel easier to find and\n            secondary actions stay out of the way.\n          </p>\n          <div className=\"mt-5 flex items-center gap-2 text-[10px]\">\n            <span className=\"opacity-35\">Assignee</span>\n            <Avatar name=\"Maya Chen\" />\n            <span className=\"opacity-65\">Maya Chen</span>\n            <span className=\"mx-2 opacity-15\">/</span>\n            <span className=\"opacity-35\">Project</span>\n            <span className=\"opacity-65\">Workspace v2</span>\n          </div>\n        </div>\n        <div className=\"flex items-center gap-3 pt-5 text-[11px]\">\n          <span className=\"font-medium\">Activity</span>\n          <span className=\"text-[10px] opacity-30\">\n            {messages.length} messages\n          </span>\n        </div>\n        {roots.map((message) => render(message, 0, []))}\n        {!messages.length && (\n          <p className=\"py-10 text-center text-xs opacity-40\">\n            Start a thoughtful conversation.\n          </p>\n        )}\n      </div>\n      {resolved ? (\n        <div\n          role=\"status\"\n          className=\"flex items-center justify-between border-t border-current/10 px-6 py-4 text-[11px]\"\n        >\n          <span className=\"flex items-center gap-2 text-[#79a798]\">\n            <Check size={13} /> This discussion is resolved.\n          </span>\n          <button className={button} onClick={toggleResolved}>\n            Reopen\n          </button>\n        </div>\n      ) : (\n        <form\n          className=\"px-5 pb-5 pt-2 sm:px-8\"\n          onSubmit={(event) => {\n            event.preventDefault();\n            if (!draft.trim()) return;\n            const id = crypto.randomUUID();\n            const parentId = target?.id ?? roots[0]?.id;\n            update([\n              ...current.current,\n              {\n                id,\n                parentId,\n                author: currentUser,\n                text: draft.trim(),\n                time: \"Just now\",\n                likes: 0,\n              },\n            ]);\n            setCollapsed([]);\n            setDraft(\"\");\n            setReplyTo(null);\n          }}\n        >\n          {target && (\n            <div className=\"mb-2 flex items-center justify-between text-[10px] text-[var(--board-accent)]\">\n              <span>Replying to {target.author}</span>\n              <button\n                aria-label=\"Cancel reply target\"\n                type=\"button\"\n                onClick={() => setReplyTo(null)}\n              >\n                <X size={12} />\n              </button>\n            </div>\n          )}\n          <div className=\"flex items-start gap-3\">\n            <Avatar name={currentUser} />\n            <div className=\"min-w-0 flex-1 rounded-lg border border-current/10 bg-transparent p-3 focus-within:border-[#9690da60]\">\n              <textarea\n                ref={textarea}\n                aria-label=\"Write a reply\"\n                required\n                maxLength={2000}\n                value={draft}\n                onChange={(event) => setDraft(event.target.value)}\n                placeholder=\"Add your perspective…\"\n                className={\n                  input +\n                  \" min-h-20 w-full resize-y border-0 bg-transparent px-0 py-0\"\n                }\n              />\n              <div className=\"mt-2 flex items-center justify-between border-t border-current/[0.07] pt-3\">\n                <span className=\"text-[9px] opacity-30\">\n                  Keep it thoughtful. Keep it moving.\n                </span>\n                <button\n                  className={primary}\n                  type=\"submit\"\n                  disabled={!draft.trim()}\n                >\n                  <Send size={11} /> Send reply\n                </button>\n              </div>\n            </div>\n          </div>\n        </form>\n      )}\n    </Frame>\n  );\n}\nexport default ThreadedReplies;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}