{"version":3,"file":"ThreadHeader.mjs","names":[],"sources":["../../../../src/components/Thread/ThreadHeader.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useChannel } from '../../context';\nimport { useTranslationContext } from '../../context/TranslationContext';\nimport { useStateStore } from '../../store';\nimport { useChannelPreviewInfo } from '../ChannelListItem/hooks/useChannelPreviewInfo';\nimport { TypingIndicatorHeader } from '../TypingIndicator/TypingIndicatorHeader';\nimport { useTypingUsers } from '../TypingIndicator/hooks/useTypingUsers';\nimport { useThreadContext } from '../Threads';\n\nimport type { LocalMessage, ThreadState } from 'stream-chat';\nimport { WorkspaceNavigationBackButton, WorkspaceNavigationCloseButton } from '../Button';\n\nconst threadStateSelector = ({ parentMessage, replyCount }: ThreadState) => ({\n  parentMessage,\n  replyCount,\n});\n\n/** Name of the parent message author, if it has one. */\nconst displayNameFromParentMessage = (message: LocalMessage): string | undefined =>\n  message.user?.name ?? undefined;\n\n/** Shows the reply count after the thread name; typing activity in the thread replaces it. */\nconst ThreadHeaderSubtitle = ({\n  replyCount,\n  threadDisplayName,\n  threadList,\n}: {\n  replyCount: number | undefined;\n  threadDisplayName: string | undefined;\n  threadList: boolean;\n}) => {\n  const { t } = useTranslationContext();\n  const channel = useChannel();\n  const threadInstance = useThreadContext();\n  const hasTyping = useTypingUsers(channel, threadInstance?.id).length > 0;\n  const replyCountText = t('common.replyCount.label', {\n    count: replyCount ?? 0,\n    defaultValue_one: '1 reply',\n    defaultValue_other: '{{ count }} replies',\n  });\n  const defaultSubtitle = threadDisplayName\n    ? `${threadDisplayName} · ${replyCountText}`\n    : replyCountText;\n  return (\n    <div className='str-chat__thread-header-subtitle'>\n      <span\n        className='str-chat__subtitle-content-transition'\n        key={hasTyping ? 'typing' : 'default'}\n      >\n        {hasTyping ? (\n          <TypingIndicatorHeader threadList={threadList} />\n        ) : (\n          <>{defaultSubtitle}</>\n        )}\n      </span>\n    </div>\n  );\n};\n\nexport type ThreadHeaderProps = {\n  /**\n   * Rendered at the end of the header. Defaults to `WorkspaceNavigationCloseButton`; a component\n   * passed here replaces it and can render that button to keep it.\n   */\n  EndContent?: React.ComponentType;\n  /**\n   * Rendered at the start of the header. Defaults to `WorkspaceNavigationBackButton`; a component\n   * passed here replaces it and can render that button to keep it.\n   */\n  StartContent?: React.ComponentType;\n  /** Overrides the name shown before the reply count in the subtitle. */\n  overrideTitle?: string;\n};\n\nexport const ThreadHeader = ({\n  EndContent = WorkspaceNavigationCloseButton,\n  overrideTitle,\n  StartContent = WorkspaceNavigationBackButton,\n}: ThreadHeaderProps) => {\n  const { t } = useTranslationContext();\n  const channel = useChannel();\n  const { displayTitle: channelDisplayTitle } = useChannelPreviewInfo({ channel });\n\n  const threadInstance = useThreadContext();\n  const { parentMessage, replyCount: replyCountThreadInstance } =\n    useStateStore(threadInstance?.state, threadStateSelector) ?? {};\n\n  const replyCount = replyCountThreadInstance ?? 0;\n\n  // Falls back from the override to the channel display title, then the parent message author.\n  const threadDisplayName =\n    overrideTitle ??\n    channelDisplayTitle ??\n    (parentMessage && displayNameFromParentMessage(parentMessage)) ??\n    undefined;\n\n  return (\n    <div className='str-chat__thread-header'>\n      <div className='str-chat__thread-header__start'>\n        <StartContent />\n      </div>\n      <div className='str-chat__thread-header-details'>\n        <div className='str-chat__thread-header-title'>\n          {t('thread.header.thread.text', 'Thread')}\n        </div>\n        <ThreadHeaderSubtitle\n          replyCount={replyCount}\n          threadDisplayName={threadDisplayName}\n          threadList\n        />\n      </div>\n      <div className='str-chat__thread-header__end'>\n        <EndContent />\n      </div>\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,uBAAuB,EAAE,eAAe,kBAA+B;CAC3E;CACA;AACF;;AAGA,IAAM,gCAAgC,YACpC,QAAQ,MAAM,QAAQ,KAAA;;AAGxB,IAAM,wBAAwB,EAC5B,YACA,mBACA,iBAKI;CACJ,MAAM,EAAE,MAAM,sBAAsB;CAGpC,MAAM,YAAY,eAFF,WAEiB,GADV,iBACmB,CAAA,EAAg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