{"version":3,"file":"ChannelListItemUI.mjs","names":[],"sources":["../../../../src/components/ChannelListItem/ChannelListItemUI.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { ChannelListItemActionButtons as DefaultChannelListItemActionButtons } from './ChannelListItemActionButtons';\nimport { ChannelListItemTimestamp } from './ChannelListItemTimestamp';\n\nimport { ChannelAvatar as DefaultChannelAvatar } from '../Avatar';\nimport { Badge } from '../Badge';\nimport { useInteractionAnnouncements } from '../Accessibility';\nimport {\n  useChatContext,\n  useComponentContext,\n  useComponentContextIcons,\n  useTranslationContext,\n  useWorkspaceNavigation,\n} from '../../context';\nimport type { ChannelListItemUIProps } from './ChannelListItem';\nimport { composeChannelListItemAccessibleLabel } from './utils.a11y';\nimport { SummarizedMessagePreview as DefaultSummarizedMessagePreview } from '../SummarizedMessagePreview';\n\nconst UnMemoizedChannelListItemUI = (props: ChannelListItemUIProps) => {\n  const { IconMute, IconPin } = useComponentContextIcons();\n  const {\n    accessibleLabelConfig,\n    active,\n    channel,\n    className: customClassName = '',\n    displayImage,\n    displayTitle,\n    groupChannelDisplayInfo,\n    messageDeliveryStatus,\n    muted,\n    onSelect: customOnSelectChannel,\n    pinned,\n    previewedMessage,\n    unread,\n  } = props;\n\n  const {\n    Avatar = DefaultChannelAvatar,\n    ChannelListItemActionButtons = DefaultChannelListItemActionButtons,\n    SummarizedMessagePreview = DefaultSummarizedMessagePreview,\n  } = useComponentContext();\n  const { client, isMessageAIGenerated } = useChatContext();\n  const { t, tDateTimeParser, userLanguage } = useTranslationContext();\n  const { openChannel } = useWorkspaceNavigation();\n  const { announceInteraction } = useInteractionAnnouncements();\n\n  const channelPreviewButton = useRef<HTMLButtonElement | null>(null);\n\n  // Built here, in the overridable component, so a custom `ChannelListItemUI` can configure it via\n  // `accessibleLabelConfig`.\n  const accessibleLabel = useMemo(\n    () =>\n      composeChannelListItemAccessibleLabel(\n        {\n          active,\n          channel,\n          client,\n          displayTitle,\n          isMessageAIGenerated,\n          latestMessage: previewedMessage,\n          messageDeliveryStatus,\n          t,\n          tDateTimeParser,\n          unreadCount: unread,\n          userLanguage,\n        },\n        accessibleLabelConfig,\n      ),\n    // `muted` and `pinned` are recompute triggers: the label parts read channel mute and membership\n    // state, which ESLint cannot see and which do not re-render this component by themselves.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [\n      accessibleLabelConfig,\n      active,\n      channel,\n      client,\n      displayTitle,\n      isMessageAIGenerated,\n      messageDeliveryStatus,\n      muted,\n      pinned,\n      previewedMessage,\n      t,\n      tDateTimeParser,\n      unread,\n      userLanguage,\n    ],\n  );\n\n  const avatarName = displayTitle || channel.messagePaginator.latestMessage?.user?.id;\n\n  const onSelectChannel = (e: React.MouseEvent<HTMLButtonElement>) => {\n    if (customOnSelectChannel) {\n      customOnSelectChannel(e);\n    } else {\n      // Forwards the event so an overridden `openChannel` (e.g. via `deriveWorkspaceNavigation`)\n      // can honor ⌘/ctrl-click.\n      openChannel(channel, { event: e });\n      // Announced only when switching channels via the default path; a custom `onSelect` owns its\n      // own feedback. Debounced so it lands after the composer's focus announcement.\n      if (!active && displayTitle) {\n        announceInteraction('channel.opened', { name: displayTitle });\n      }\n    }\n    if (channelPreviewButton?.current) {\n      channelPreviewButton.current.blur();\n    }\n  };\n\n  return (\n    <div className='str-chat__channel-list-item-container'>\n      <button\n        aria-label={accessibleLabel}\n        // Set only on the active row: `false` on every other row makes screen readers announce \"not\n        // selected\" on each one.\n        aria-selected={active || undefined}\n        className={clsx(\n          'str-chat__channel-list-item',\n          {\n            'str-chat__channel-list-item--muted': muted,\n            'str-chat__channel-list-item--pinned': pinned,\n            'str-chat__channel-list-item--unread':\n              typeof unread === 'number' && unread > 0,\n          },\n          customClassName,\n        )}\n        data-testid='channel-list-item-button'\n        onClick={onSelectChannel}\n        ref={channelPreviewButton}\n        role='option'\n      >\n        <Avatar\n          aria-hidden='true'\n          displayMembers={groupChannelDisplayInfo?.members}\n          imageUrl={displayImage}\n          size='xl'\n          userName={avatarName}\n        />\n        <div className='str-chat__channel-list-item-data'>\n          <div className='str-chat__channel-list-item-data__first-row'>\n            <div className='str-chat__channel-list-item-data__title'>\n              <span>{displayTitle || 'N/A'}</span>\n              {pinned && <IconPin />}\n              {muted && <IconMute />}\n            </div>\n            <div className='str-chat__channel-list-item-data__timestamp-and-badge'>\n              <ChannelListItemTimestamp previewedMessage={previewedMessage} />\n              {typeof unread === 'number' && unread > 0 && (\n                <Badge data-testid='unread-badge' size='md' variant='primary'>\n                  {unread}\n                </Badge>\n              )}\n            </div>\n          </div>\n          <SummarizedMessagePreview\n            latestMessage={previewedMessage}\n            messageDeliveryStatus={messageDeliveryStatus}\n            participantCount={channel.data?.member_count}\n          />\n        </div>\n      </button>\n      <ChannelListItemActionButtons />\n    </div>\n  );\n};\n\n/** Default row UI of `ChannelListItem`: avatar, title, timestamp, unread badge and preview. */\nexport const ChannelListItemUI = React.memo(\n  UnMemoizedChannelListItemUI,\n) as typeof UnMemoizedChannelListItemUI;\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,IAAM,+BAA+B,UAAkC;CACrE,MAAM,EAAE,UAAU,YAAY,yBAAyB;CACvD,MAAM,EACJ,uBACA,QACA,SACA,WAAW,kBAAkB,IAC7B,cACA,cACA,yBACA,uBACA,OACA,UAAU,uBACV,QACA,kBACA,WACE;CAEJ,MAAM,EACJ,SAAS,eACT,8BAAA,iCAA+B,8BAC/B,0BAAA,6BAA2B,6BACzB,oBAAoB;CACxB,MAAM,EAAE,QAAQ,yBAAyB,eAAe;CACxD,MAAM,EAAE,GAAG,iBAAiB,iBAAiB,sBAAsB;CACnE,MAAM,EAAE,gBAAgB,uBAAuB;CAC/C,MAAM,EAAE,wBAAwB,4BAA4B;CAE5D,MAAM,uBAAuB,OAAiC,IAAI;CAIlE,MAAM,kBAAkB,cAEpB,sCACE;EACE;EACA;EACA;EACA;EACA;EACA,eAAe;EACf;EACA;EACA;EACA,aAAa;EACb;CACF,GACA,qBAC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