{"version":3,"file":"ChannelHeader.mjs","names":[],"sources":["../../../../src/components/ChannelHeader/ChannelHeader.tsx"],"sourcesContent":["import React from 'react';\nimport type { Channel } from 'stream-chat';\n\nimport { type ChannelAvatarProps, ChannelAvatar as DefaultAvatar } from '../Avatar';\nimport { TypingIndicatorHeader } from '../TypingIndicator/TypingIndicatorHeader';\nimport { useTypingUsers } from '../TypingIndicator/hooks/useTypingUsers';\nimport { useChannelHeaderOnlineStatus } from './hooks/useChannelHeaderOnlineStatus';\nimport { useChannelPreviewInfo } from '../ChannelListItem/hooks/useChannelPreviewInfo';\nimport { useChannel } from '../../context';\nimport { WorkspaceNavigationBackButton, WorkspaceNavigationCloseButton } from '../Button';\n\nexport type ChannelHeaderTitleProps = {\n  /** The channel the header belongs to. */\n  channel: Channel;\n  /** The title to show: the `title` passed to `ChannelHeader`, else the channel display name. */\n  displayTitle?: string;\n};\n\n/** Default title of `ChannelHeader`: the display title in a `div`. */\nexport const ChannelHeaderTitle = ({ displayTitle }: ChannelHeaderTitleProps) => (\n  <div className='str-chat__channel-header__data__title'>{displayTitle}</div>\n);\n\n/**\n * Default subtitle of `ChannelHeader`, for the channel in context. Shows the typing indicator while\n * other users type, otherwise the online status from `useChannelHeaderOnlineStatus`, and\n * transitions between the two. Renders nothing when there is neither.\n */\nexport const ChannelHeaderSubtitle = () => {\n  const channel = useChannel();\n  const onlineStatusText = useChannelHeaderOnlineStatus();\n  const hasTyping = useTypingUsers(channel).length > 0;\n\n  if (!hasTyping && !onlineStatusText) return null;\n\n  return (\n    <div className='str-chat__channel-header__data__subtitle'>\n      <span\n        className='str-chat__subtitle-content-transition'\n        key={hasTyping ? 'typing' : 'default'}\n      >\n        {hasTyping ? <TypingIndicatorHeader /> : onlineStatusText}\n      </span>\n    </div>\n  );\n};\n\nexport type ChannelHeaderProps = {\n  /** Avatar component. Defaults to `ChannelAvatar`. */\n  Avatar?: React.ComponentType<ChannelAvatarProps>;\n  /**\n   * Rendered at the end of the header, after the avatar. Defaults to\n   * `WorkspaceNavigationCloseButton`; a component passed here replaces it and can render that\n   * 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  /**\n   * Replaces the subtitle below the title. Defaults to `ChannelHeaderSubtitle`. Read the channel\n   * with `useChannel()` and the status text with `useChannelHeaderOnlineStatus()`.\n   */\n  Subtitle?: React.ComponentType;\n  /**\n   * Replaces the title. Defaults to `ChannelHeaderTitle`. Receives the channel and its display\n   * title, so it can render the title as a button, for example. The subtitle stays below it.\n   */\n  Title?: React.ComponentType<ChannelHeaderTitleProps>;\n  /** Overrides the channel image. */\n  image?: string;\n  /** Overrides the channel title. */\n  title?: string;\n};\n\n/** Header of the bound channel: avatar, title, and online status or typing indicator. */\nexport const ChannelHeader = (props: ChannelHeaderProps) => {\n  const {\n    Avatar = DefaultAvatar,\n    EndContent = WorkspaceNavigationCloseButton,\n    image: overrideImage,\n    StartContent = WorkspaceNavigationBackButton,\n    Subtitle = ChannelHeaderSubtitle,\n    Title = ChannelHeaderTitle,\n    title: overrideTitle,\n  } = props;\n\n  const channel = useChannel();\n  const { displayImage, displayTitle, groupChannelDisplayInfo } = useChannelPreviewInfo({\n    channel,\n    overrideImage,\n    overrideTitle,\n  });\n\n  return (\n    <div className='str-chat__channel-header'>\n      <div className='str-chat__channel-header__start'>\n        <StartContent />\n      </div>\n      <div className='str-chat__channel-header__data'>\n        <Title channel={channel} displayTitle={displayTitle} />\n        <Subtitle />\n      </div>\n      <div className='str-chat__channel-header__end'>\n        <Avatar\n          className='str-chat__avatar--channel-header'\n          displayMembers={groupChannelDisplayInfo?.members}\n          imageUrl={displayImage}\n          size='lg'\n          userName={displayTitle}\n        />\n        <EndContent />\n      </div>\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;AAmBA,IAAa,sBAAsB,EAAE,mBACnC,oBAAC,OAAD;CAAK,WAAU;WAAyC;AAAkB,CAAA;;;;;;AAQ5E,IAAa,8BAA8B;CACzC,MAAM,UAAU,WAAW;CAC3B,MAAM,mBAAmB,6BAA6B;CACtD,MAAM,YAAY,eAAe,OAAO,CAAC,CAAC,SAAS;CAEnD,IAAI,CAAC,aAAa,CAAC,kBAAkB,OAAO;CAE5C,OACE,oBAAC,OAAD;EAAK,WAAU;YACb,oBAAC,QAAD;GACE,WAAU;aAGT,YAAY,oBAAC,uBAAD,CAAwB,CAAA,IAAI;EACrC,GAHC,YAAY,WAAW,SAGxB;CACH,CAAA;AAET;;AAiCA,IAAa,iBAAiB,UAA8B;CAC1D,MAAM,EACJ,SAAS,eACT,aAAa,gCACb,OAAO,eACP,eAAe,+BACf,WAAW,uBACX,QAAQ,oBACR,OAAO,kBACL;CAEJ,MAAM,UAAU,WAAW;CAC3B,MAAM,EAAE,cAAc,cAAc,4BAA4B,sBAAsB;EACpF;EACA;EACA;CACF,CAAC;CAED,OACE,qBAAC,OAAD;EAAK,WAAU;YAAf;GACE,oBAAC,OAAD;IAAK,WAAU;cACb,oBAAC,cAAD,CAAe,CAAA;GACZ,CAAA;GACL,qBAAC,OAAD;IAAK,WAAU;cAAf,CACE,oBAAC,OAAD;KAAgB;KAAuB;IAAe,CAAA,GACtD,oBAAC,UAAD,CAAW,CAAA,CACR;;GACL,qBAAC,OAAD;IAAK,WAAU;cAAf,CACE,oBAAC,QAAD;KACE,WAAU;KACV,gBAAgB,yBAAyB;KACzC,UAAU;KACV,MAAK;KACL,UAAU;IACX,CAAA,GACD,oBAAC,YAAD,CAAa,CAAA,CACV;;EACF;;AAET"}