{"version":3,"file":"MessageBubbleContent.mjs","names":[],"sources":["../../../../src/components/Message/MessageBubbleContent.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type { LocalMessage } from 'stream-chat';\n\nimport { useMessageContext } from '../../context/MessageContext';\nimport { defaultMessageBubbleContentSet } from './MessageBubbleContent.defaults';\n\n/**\n * The content types {@link defaultMessageBubbleContentSet} ships, listed for autocomplete. Any\n * string is accepted, so custom content names itself.\n */\nexport type DefaultMessageBubbleContentType =\n  | 'attachments'\n  | 'poll'\n  | 'quotedMessage'\n  | 'text';\n\n/** What decides which parts of a message bubble show. */\nexport type MessageBubbleContentVisibilityFilterParams = {\n  /** Whether `isMessageAIGenerated` marks the message as AI generated (streamed text). */\n  isAIGenerated: boolean;\n  message: LocalMessage;\n};\n\nexport type MessageBubbleContentSetItem = {\n  /** Rendered without props while `isVisible` holds. Read the message with `useMessageContext()`. */\n  Component: React.ComponentType;\n  /** Whether the content shows for the message. */\n  isVisible: (state: MessageBubbleContentVisibilityFilterParams) => boolean;\n  /** Names the content; unique within a set. */\n  type: DefaultMessageBubbleContentType | (string & {});\n};\n\nexport type MessageBubbleContentProps = {\n  /** Content in render order. Defaults to {@link defaultMessageBubbleContentSet}. */\n  messageBubbleContentSet?: MessageBubbleContentSetItem[];\n};\n\n/**\n * Renders what a message bubble holds (quoted message, poll, attachments, text) in the order of\n * `messageBubbleContentSet`, skipping what the message does not have.\n */\nexport const MessageBubbleContent = ({\n  messageBubbleContentSet = defaultMessageBubbleContentSet,\n}: MessageBubbleContentProps) => {\n  const { isMessageAIGenerated, message } = useMessageContext();\n  const isAIGenerated = !!isMessageAIGenerated?.(message);\n\n  const visibleContentSet = useMemo(\n    () =>\n      messageBubbleContentSet.filter((item) =>\n        item.isVisible({ isAIGenerated, message }),\n      ),\n    [isAIGenerated, message, messageBubbleContentSet],\n  );\n\n  return (\n    <>\n      {visibleContentSet.map(({ Component, type }) => (\n        <Component key={type} />\n      ))}\n    </>\n  );\n};\n"],"mappings":";;;;;;;;;AAyCA,IAAa,wBAAwB,EACnC,0BAA0B,qCACK;CAC/B,MAAM,EAAE,sBAAsB,YAAY,kBAAkB;CAC5D,MAAM,gBAAgB,CAAC,CAAC,uBAAuB,OAAO;CAUtD,OACE,oBAAA,YAAA,EAAA,UATwB,cAEtB,wBAAwB,QAAQ,SAC9B,KAAK,UAAU;EAAE;EAAe;CAAQ,CAAC,CAC3C,GACF;EAAC;EAAe;EAAS;CAAuB,CAK7C,CAAA,CAAkB,KAAK,EAAE,WAAW,WACnC,oBAAC,WAAD,CAAuB,GAAP,IAAO,CACxB,EACD,CAAA;AAEN"}