{"version":3,"file":"chat-item.cjs","sources":["../../../components/chat/chat-item.tsx"],"sourcesContent":["'use client';\n\nimport { useMergedRefs } from '@base-ui/utils/useMergedRefs';\nimport { cx } from 'class-variance-authority';\nimport { ComponentProps, useContext, useLayoutEffect, useRef } from 'react';\nimport styles from './chat.module.css';\nimport { ChatMessagesRegistryContext } from './chat-context';\n\nexport interface ChatItemProps extends ComponentProps<'div'> {\n  /**\n   * Stable id registered with the enclosing `Chat.Messages`, enabling\n   * visibility tracking and `scrollToMessage`.\n   */\n  messageId?: string;\n  /**\n   * Marks the item as a scroll anchor: when it mounts inside\n   * `Chat.Messages`, the viewport scrolls it near the top so the reply can\n   * stream in below — set it on the latest user message.\n   * @defaultValue false\n   */\n  scrollAnchor?: boolean;\n}\n\nexport function ChatItem({\n  className,\n  messageId,\n  scrollAnchor = false,\n  ref,\n  ...props\n}: ChatItemProps) {\n  const registry = useContext(ChatMessagesRegistryContext);\n  const localRef = useRef<HTMLDivElement | null>(null);\n  const mergedRef = useMergedRefs(localRef, ref);\n\n  useLayoutEffect(() => {\n    const element = localRef.current;\n    if (!registry || !element) return;\n    return registry.register(element, { id: messageId, scrollAnchor });\n  }, [registry, messageId, scrollAnchor]);\n\n  return (\n    <div\n      ref={mergedRef}\n      data-message-id={messageId}\n      className={cx(styles.item, className)}\n      data-slot='chat-item'\n      {...props}\n    />\n  );\n}\n\nChatItem.displayName = 'Chat.Item';\n"],"names":[],"mappings":";;;;;;;;;;;AA8BE;AACA;;;AAIE;AACA;;AACA;;;AAYJ;AAEA;;"}