{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comments-04",
  "description": "A support ticket conversation with replies emailed to the customer and internal notes only the team sees.",
  "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/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/comments/comments-04.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  CommentComposer,\n  CommentItem,\n  getMentions,\n  type ThreadComment,\n  toggleReaction,\n  updateComment,\n} from '@/registry/components/dashboardblocks/comments'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { startTransition, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'\n\ntype MessageKind = 'customer' | 'reply' | 'note'\n\ninterface TicketMessage extends ThreadComment {\n  kind: MessageKind\n}\n\ntype Mode = 'reply' | 'note'\n\ninterface Comments4Props extends BlockStateProps {\n  currentUser: CommentAuthor\n  customer: { company: string; email: string; name: string }\n  /** Oldest first. Leave out, or pass none, to show the empty state. */\n  messages?: TicketMessage[]\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  onReact?: (messageId: string, emoji: string) => void\n  onSubmit?: (body: string, options: { internal: boolean }) => Promise<void>\n  people: CommentAuthor[]\n  ticketId: string\n  title: string\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 hannah = { avatar: '/images/avatar-18.webp', name: 'Hannah Becker' }\nconst lena = { avatar: '/images/avatar-03.webp', name: 'Lena Fischer' }\nconst mateo = { name: 'Mateo Silva' }\n\nconst exampleProps: Comments4Props = {\n  currentUser: { name: 'Amara Okafor' },\n  customer: {\n    company: 'Northwind Traders',\n    email: 'hannah@northwind.example',\n    name: 'Hannah Becker',\n  },\n  messages: [\n    {\n      at: hoursAgo(50),\n      author: hannah,\n      body: 'Our customers on Safari can’t finish checkout. The payment sheet goes blank and the order never goes through. It started on Monday.',\n      id: 'm1',\n      kind: 'customer',\n    },\n    {\n      at: hoursAgo(49),\n      author: lena,\n      body: 'Thanks Hannah, we can reproduce it and we’re on it. I’ll update you here as soon as a fix ships.',\n      id: 'm2',\n      kind: 'reply',\n    },\n    {\n      at: hoursAgo(20),\n      author: lena,\n      body: 'Reproduced on Safari 17.4: the payment sheet closes before the 3-D Secure frame loads. @Mateo Silva can you check the iframe sandbox flags?',\n      id: 'm3',\n      kind: 'note',\n      reactions: [{ count: 1, emoji: '👀', reacted: false }],\n    },\n    {\n      at: hoursAgo(18),\n      author: mateo,\n      body: 'Found it, the frame can’t navigate the top window. The fix is in review and ships tomorrow morning.',\n      id: 'm4',\n      kind: 'note',\n      reactions: [{ count: 2, emoji: '👍', reacted: true }],\n    },\n    {\n      at: hoursAgo(3),\n      author: hannah,\n      body: 'Any update? We’re losing about 40 orders a day.',\n      id: 'm5',\n      kind: 'customer',\n    },\n  ],\n  now: exampleNow,\n  people: [lena, mateo, { name: 'Priya Nair' }, { name: 'Jonas Weber' }],\n  ticketId: 'TCK-381',\n  title: 'Conversation',\n}\n\nconst noMessages: TicketMessage[] = []\n\nasync function saveMessage() {\n  await new Promise((resolve) => setTimeout(resolve, 500))\n}\n\nconst lockIcon = (\n  <IconPlaceholder\n    lucide='LockIcon'\n    tabler='IconLock'\n    hugeicons='SquareLock02Icon'\n    phosphor='LockIcon'\n    remixicon='RiLockLine'\n  />\n)\n\nconst Comments4 = (props: Comments4Props) => {\n  const {\n    currentUser,\n    customer,\n    messages: initialMessages = noMessages,\n    now,\n    onReact = () => {},\n    onSubmit = saveMessage,\n    people,\n    errorMessage,\n    status,\n    ticketId,\n    title,\n  } = props\n  const [messages, setMessages] = useState(initialMessages)\n  const [loaded, setLoaded] = useState(initialMessages)\n  if (initialMessages !== loaded) {\n    setLoaded(initialMessages)\n    setMessages(initialMessages)\n  }\n  const [mode, setMode] = useState<Mode>('reply')\n  const [drafts, setDrafts] = useState({ note: '', reply: '' })\n  const [announcement, setAnnouncement] = useState('')\n  const state = getBlockState(status, messages)\n  const unavailable = state === 'loading' || state === 'error'\n  const mentioned = getMentions(\n    drafts.note,\n    people.map((person) => person.name),\n  )\n\n  async function send(body: string, kind: Mode) {\n    await onSubmit(body, { internal: kind === 'note' })\n    startTransition(() => {\n      setMessages((current) => [\n        ...current,\n        { at: now, author: currentUser, body, id: `${Date.now()}`, kind },\n      ])\n      setAnnouncement(kind === 'note' ? 'Note added' : `Reply sent to ${customer.name}`)\n    })\n  }\n\n  function badge(kind: MessageKind) {\n    if (kind === 'customer')\n      return (\n        <StatusLabel variant='text' className='text-xs' tone='info'>\n          Customer\n        </StatusLabel>\n      )\n    if (kind === 'note')\n      return (\n        <StatusLabel\n          variant='text'\n          className='flex items-center gap-1 text-xs [&_svg]:size-3'\n          tone='warning'\n        >\n          {lockIcon}\n          Internal\n        </StatusLabel>\n      )\n    return null\n  }\n\n  const last = messages[messages.length - 1]\n  const waitingHours =\n    last?.kind === 'customer'\n      ? Math.max(0, Math.round((now.getTime() - last.at.getTime()) / 3_600_000))\n      : null\n  const waiting =\n    waitingHours === null\n      ? 'Waiting on the customer.'\n      : `${customer.name.split(' ')[0]} has waited ${waitingHours < 1 ? 'under an hour' : `${waitingHours} ${waitingHours === 1 ? 'hour' : 'hours'}`} for a reply.`\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>\n                {ticketId} with {customer.name}, {customer.company}.{' '}\n                <BlockReady>{waiting}</BlockReady>\n              </p>\n            </header>\n            <div>\n              {state && (\n                <div className='border-t'>\n                  <BlockStateRows rows={3} />\n                </div>\n              )}\n              {!state && (\n                <ol\n                  aria-label={`Conversation on ${ticketId}`}\n                  className='flex flex-col gap-4 border-t pt-4'\n                >\n                  {messages.map((message) => (\n                    <li\n                      key={message.id}\n                      className={\n                        message.kind === 'note'\n                          ? 'border-l-2 border-orange-500/60 bg-orange-500/5 py-3 pr-3 pl-[calc(0.75rem-2px)]'\n                          : 'px-3'\n                      }\n                    >\n                      <CommentItem\n                        comment={message}\n                        now={now}\n                        people={message.kind === 'note' ? people : undefined}\n                        badge={badge(message.kind)}\n                        onReact={\n                          message.kind === 'note'\n                            ? (emoji) => {\n                                onReact(message.id, emoji)\n                                setMessages((current) =>\n                                  updateComment(current, message.id, (item) => ({\n                                    ...item,\n                                    reactions: toggleReaction(item.reactions, emoji),\n                                  })),\n                                )\n                              }\n                            : undefined\n                        }\n                      />\n                    </li>\n                  ))}\n                </ol>\n              )}\n              <p aria-live='polite' className='sr-only'>\n                {announcement}\n              </p>\n            </div>\n            <div className='border-t pt-4'>\n              <Tabs\n                value={mode}\n                onValueChange={(value) => setMode(value as Mode)}\n                className='w-full'\n              >\n                <TabsList>\n                  <TabsTrigger value='reply'>Reply</TabsTrigger>\n                  <TabsTrigger value='note'>Internal note</TabsTrigger>\n                </TabsList>\n                <TabsContent value='reply'>\n                  <CommentComposer\n                    label={`Reply to ${customer.name}`}\n                    placeholder={`Reply to ${customer.name.split(' ')[0]}`}\n                    submitLabel='Send reply'\n                    pendingLabel='Sending'\n                    disabled={unavailable}\n                    value={drafts.reply}\n                    footer={\n                      <span className='text-muted-foreground block truncate'>\n                        Emailed to {customer.email}\n                      </span>\n                    }\n                    onValueChange={(reply) =>\n                      setDrafts((current) => ({ ...current, reply }))\n                    }\n                    onSubmit={(body) => send(body, 'reply')}\n                  />\n                </TabsContent>\n                <TabsContent value='note'>\n                  <CommentComposer\n                    className='*:data-[slot=input-group]:bg-orange-500/5'\n                    label='Internal note'\n                    placeholder='Add a note for your team. Type @ to mention someone.'\n                    submitLabel='Add note'\n                    pendingLabel='Adding'\n                    disabled={unavailable}\n                    people={people}\n                    value={drafts.note}\n                    footer={\n                      <span className='flex min-w-0 items-center gap-1.5 text-orange-700 dark:text-orange-400 [&_svg]:size-3.5 [&_svg]:shrink-0'>\n                        {lockIcon}\n                        <span className='truncate'>\n                          {mentioned.length > 0\n                            ? `Only your team sees this. Notifies ${mentioned.join(', ')}.`\n                            : 'Only your team sees this'}\n                        </span>\n                      </span>\n                    }\n                    onValueChange={(note) =>\n                      setDrafts((current) => ({ ...current, note }))\n                    }\n                    onSubmit={(body) => send(body, 'note')}\n                  />\n                </TabsContent>\n              </Tabs>\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Comments4, exampleProps as comments4ExampleProps, type Comments4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/comments/comments-04.tsx"
    }
  ],
  "meta": {
    "shows": "A support ticket conversation with replies emailed to the customer and internal notes only the team sees.",
    "size": "half",
    "usedWith": [
      "record-detail-01",
      "kanban-03"
    ],
    "component": "Comments4",
    "props": "{ currentUser: { avatar?: string; name: string }; customer: { company: string; email: string; name: string }; messages?: { kind: \"customer\" | \"reply\" | \"note\"; 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 }[]; now: Date; onReact?: (messageId: string, emoji: string) => void; onSubmit?: (body: string, options: { internal: boolean }) => Promise<void>; people: { avatar?: string; name: string }[]; ticketId: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
