{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comments-03",
  "description": "Comments in a column beside a document, each quoting the words it is about, that move to Resolved when closed.",
  "registryDependencies": [
    "card",
    "tabs",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/comments.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/comments/comments-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type CommentAuthor,\n  CommentThread,\n  type ThreadComment,\n  toggleReaction,\n  updateComment,\n} from '@/registry/components/dashboardblocks/comments'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport { Fragment, type ReactNode, startTransition, useId, useRef, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'\n\ninterface ReviewComment extends ThreadComment {\n  quote: string\n}\n\ntype Filter = 'open' | 'resolved'\n\ntype DocumentStatusTone = 'success' | 'warning' | 'info' | 'neutral'\n\nconst statusTones: Record<DocumentStatusTone, StatusTone> = {\n  info: 'info',\n  neutral: 'neutral',\n  success: 'good',\n  warning: 'warning',\n}\n\ninterface Comments3Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  comments?: ReviewComment[]\n  currentUser: CommentAuthor\n  document: {\n    paragraphs: string[]\n    status: string\n    /** @default 'warning' */\n    statusTone?: DocumentStatusTone\n    title: string\n    updated: string\n  }\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  onReact?: (commentId: string, emoji: string) => void\n  onResolve?: (commentId: string, resolved: boolean) => void\n  onSubmit?: (body: string, options: { parentId: string }) => Promise<void>\n  people: CommentAuthor[]\n}\n\nconst exampleNow = new Date(Date.UTC(2026, 8, 26, 12))\nconst hoursAgo = (hours: number) => new Date(exampleNow.getTime() - hours * 3_600_000)\n\nconst amara = { name: 'Amara Okafor' }\nconst priya = { avatar: '/images/avatar-02.webp', name: 'Priya Nair' }\nconst lena = { avatar: '/images/avatar-03.webp', name: 'Lena Fischer' }\nconst mateo = { name: 'Mateo Silva' }\nconst jonas = { avatar: '/images/avatar-07.webp', name: 'Jonas Weber' }\n\nconst exampleProps: Comments3Props = {\n  comments: [\n    {\n      at: hoursAgo(4),\n      author: priya,\n      body: 'Legal asked for “No card required” so it matches the checkout page.',\n      id: 'r1',\n      quote: 'No credit card needed',\n      reactions: [{ count: 1, emoji: '👍', reacted: false }],\n      replies: [\n        {\n          at: hoursAgo(3),\n          author: lena,\n          body: '@Priya Nair checkout says “No card required” too, so let’s use that everywhere.',\n          id: 'r1-1',\n        },\n      ],\n    },\n    {\n      at: hoursAgo(2),\n      author: mateo,\n      body: 'Support’s response time on Growth is one business day. Four hours is Enterprise only.',\n      id: 'r2',\n      quote: 'a four-hour response time',\n      reactions: [{ count: 2, emoji: '👀', reacted: false }],\n    },\n    {\n      at: hoursAgo(30),\n      author: jonas,\n      body: 'SSO is only on Enterprise. Listing it here will turn into support tickets.',\n      id: 'r3',\n      quote: 'SSO and audit logs',\n      replies: [\n        {\n          at: hoursAgo(26),\n          author: amara,\n          body: 'Moved SSO to the Enterprise column and kept audit logs here.',\n          id: 'r3-1',\n        },\n      ],\n      resolved: true,\n    },\n  ],\n  currentUser: amara,\n  document: {\n    paragraphs: [\n      'Start free for 14 days. No credit card needed, and you can cancel any time from Settings.',\n      'Teams on the annual plan save 20% and get priority support with a four-hour response time.',\n      'Every plan includes unlimited dashboards, scheduled reports, SSO and audit logs.',\n      'Need more than 200 seats? Talk to sales about volume pricing and invoicing.',\n    ],\n    status: 'In review',\n    title: 'Pricing page copy',\n    updated: 'Edited 2 hours ago by Sofia Rossi',\n  },\n  now: exampleNow,\n  people: [\n    priya,\n    lena,\n    mateo,\n    jonas,\n    { avatar: '/images/avatar-01.webp', name: 'Sofia Rossi' },\n  ],\n}\n\nconst noComments: ReviewComment[] = []\n\nasync function saveReply() {\n  await new Promise((resolve) => setTimeout(resolve, 500))\n}\n\nfunction highlight(paragraph: string, comments: ReviewComment[], activeId?: string) {\n  const parts: ReactNode[] = []\n  let rest = paragraph\n  let pending = comments.filter((comment) => comment.quote)\n  for (;;) {\n    const next = pending\n      .map((comment) => ({ comment, index: rest.indexOf(comment.quote) }))\n      .filter((found) => found.index >= 0)\n      .sort((a, b) => a.index - b.index)[0]\n    if (!next) break\n    parts.push(rest.slice(0, next.index))\n    parts.push(\n      <mark\n        key={next.comment.id}\n        data-active={next.comment.id === activeId || undefined}\n        className='text-foreground data-active:ring-amber-500/60 rounded-sm bg-amber-500/20 transition-colors data-active:bg-amber-500/35 data-active:ring-1'\n      >\n        {next.comment.quote}\n      </mark>,\n    )\n    rest = rest.slice(next.index + next.comment.quote.length)\n    pending = pending.filter((comment) => comment !== next.comment)\n  }\n  parts.push(rest)\n  return parts.map((part, index) => <Fragment key={index}>{part}</Fragment>)\n}\n\nconst Comments3 = (props: Comments3Props) => {\n  const {\n    comments: initialComments = noComments,\n    currentUser,\n    document,\n    now,\n    onReact = () => {},\n    onResolve = () => {},\n    onSubmit = saveReply,\n    people,\n    errorMessage,\n    status,\n  } = props\n  const [comments, setComments] = useState(initialComments)\n  const [loaded, setLoaded] = useState(initialComments)\n  if (initialComments !== loaded) {\n    setLoaded(initialComments)\n    setComments(initialComments)\n  }\n  const [filter, setFilter] = useState<Filter>('open')\n  const [activeId, setActiveId] = useState<string>()\n  const [announcement, setAnnouncement] = useState('')\n  const state = getBlockState(status, comments)\n  const headingId = useId()\n  const listRef = useRef<HTMLDivElement>(null)\n  const open = comments.filter((comment) => !comment.resolved)\n  const resolved = comments.filter((comment) => comment.resolved)\n\n  function update(id: string, change: (comment: ThreadComment) => ThreadComment) {\n    setComments((current) => updateComment(current, id, change))\n  }\n\n  function resolve(comment: ReviewComment, next: boolean) {\n    onResolve(comment.id, next)\n    update(comment.id, (item) => ({ ...item, resolved: next }))\n    setActiveId(undefined)\n    setAnnouncement(\n      next\n        ? `Resolved. ${open.length - 1} open ${open.length - 1 === 1 ? 'comment' : 'comments'} left.`\n        : 'Reopened. It’s under Open.',\n    )\n    requestAnimationFrame(() => listRef.current?.focus())\n  }\n\n  const filters = [\n    { items: open, label: 'Open', value: 'open' as const },\n    { items: resolved, label: 'Resolved', value: 'resolved' as const },\n  ]\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container'>\n            <div className='grid gap-6 @3xl:grid-cols-[minmax(0,1fr)_22rem] @3xl:gap-8'>\n              <article className='flex flex-col gap-4 self-start'>\n                <header className='flex flex-col gap-0.5'>\n                  <h2 className='font-semibold tracking-tight'>{document.title}</h2>\n                  <Details className='text-muted-foreground text-sm'>\n                    <StatusLabel\n                      variant='text'\n                      tone={statusTones[document.statusTone ?? 'warning']}\n                    >\n                      {document.status}\n                    </StatusLabel>\n                    {document.updated}\n                  </Details>\n                </header>\n                <div className='flex flex-col gap-4 border-t pt-4 text-sm leading-relaxed'>\n                  {document.paragraphs.map((paragraph) => (\n                    <p key={paragraph}>\n                      {state ? paragraph : highlight(paragraph, open, activeId)}\n                    </p>\n                  ))}\n                </div>\n              </article>\n              <section\n                aria-labelledby={headingId}\n                className='flex flex-col gap-3 self-start border-t pt-4 @3xl:border-t-0 @3xl:border-l @3xl:pt-0 @3xl:pl-6'\n              >\n                <header className='flex flex-col gap-0.5'>\n                  <h3 id={headingId} className='text-sm font-medium'>\n                    Comments\n                  </h3>\n                  <BlockReady className='text-sm'>\n                    <p className='text-muted-foreground text-sm'>\n                      {open.length === 0\n                        ? 'Everything is resolved.'\n                        : `${open.length} open, ${resolved.length} resolved.`}\n                    </p>\n                  </BlockReady>\n                </header>\n                <Tabs\n                  value={filter}\n                  onValueChange={(value) => setFilter(value as Filter)}\n                >\n                  <TabsList className='w-full'>\n                    {filters.map((item) => (\n                      <TabsTrigger key={item.value} value={item.value}>\n                        {item.label}\n                        {!state && <Tag>{formatNumber(item.items.length)}</Tag>}\n                      </TabsTrigger>\n                    ))}\n                  </TabsList>\n                  {filters.map((item) => (\n                    <TabsContent key={item.value} value={item.value}>\n                      <div\n                        ref={item.value === filter ? listRef : undefined}\n                        tabIndex={-1}\n                        aria-label={`${item.label} comments`}\n                        className='flex flex-col divide-y outline-none'\n                      >\n                        {state ? (\n                          <BlockStateRows rows={3} />\n                        ) : item.items.length === 0 ? (\n                          <p className='text-muted-foreground py-10 text-center text-sm'>\n                            {item.value === 'open'\n                              ? 'All comments are resolved.'\n                              : 'No resolved comments yet.'}\n                          </p>\n                        ) : (\n                          item.items.map((comment) => (\n                            <div\n                              key={comment.id}\n                              className='py-4 first:pt-2 last:pb-0'\n                              onMouseEnter={() => setActiveId(comment.id)}\n                              onMouseLeave={() => setActiveId(undefined)}\n                              onFocus={() => setActiveId(comment.id)}\n                              onBlur={(event) => {\n                                if (\n                                  !event.currentTarget.contains(\n                                    event.relatedTarget as Node | null,\n                                  )\n                                )\n                                  setActiveId(undefined)\n                              }}\n                            >\n                              <CommentThread\n                                comment={comment}\n                                currentUser={currentUser}\n                                now={now}\n                                people={people}\n                                header={\n                                  <blockquote className='text-muted-foreground border-l-2 border-amber-500/60 pl-3 text-xs'>\n                                    <span className='line-clamp-2'>{comment.quote}</span>\n                                  </blockquote>\n                                }\n                                onReply={async (body) => {\n                                  await onSubmit(body, {\n                                    parentId: comment.id,\n                                  })\n                                  startTransition(() => {\n                                    update(comment.id, (parent) => ({\n                                      ...parent,\n                                      replies: [\n                                        ...(parent.replies ?? []),\n                                        {\n                                          at: now,\n                                          author: currentUser,\n                                          body,\n                                          id: `${Date.now()}`,\n                                        },\n                                      ],\n                                    }))\n                                  })\n                                }}\n                                onReact={(commentId, emoji) => {\n                                  onReact(commentId, emoji)\n                                  update(commentId, (target) => ({\n                                    ...target,\n                                    reactions: toggleReaction(target.reactions, emoji),\n                                  }))\n                                }}\n                                onResolve={(next) => resolve(comment, next)}\n                              />\n                            </div>\n                          ))\n                        )}\n                      </div>\n                    </TabsContent>\n                  ))}\n                </Tabs>\n                <p aria-live='polite' className='sr-only'>\n                  {announcement}\n                </p>\n              </section>\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Comments3,\n  exampleProps as comments3ExampleProps,\n  type Comments3Props,\n  type DocumentStatusTone,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/comments/comments-03.tsx"
    }
  ],
  "meta": {
    "shows": "Comments in a column beside a document, each quoting the words it is about, that move to Resolved when closed.",
    "size": "full",
    "usedWith": [
      "comments-01",
      "activity-feed-01"
    ],
    "component": "Comments3",
    "props": "{ comments?: { quote: string; at: Date; author: { avatar?: string; name: string }; body: string; edited?: boolean; id: string; reactions?: { count: number; emoji: string; reacted: boolean }[]; replies?: { at: Date; author: { avatar?: string; name: string }; body: string; edited?: boolean; id: string; reactions?: { count: number; emoji: string; reacted: boolean }[]; replies?: ThreadComment[]; resolved?: boolean }[]; resolved?: boolean }[]; currentUser: { avatar?: string; name: string }; document: { paragraphs: string[]; status: string; statusTone?: \"success\" | \"warning\" | \"info\" | \"neutral\"; title: string; updated: string }; now: Date; onReact?: (commentId: string, emoji: string) => void; onResolve?: (commentId: string, resolved: boolean) => void; onSubmit?: (body: string, options: { parentId: string }) => Promise<void>; people: { avatar?: string; name: string }[]; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
