{"version":3,"file":"ChannelListItemActionButtons.mjs","names":[],"sources":["../../../../src/components/ChannelListItem/ChannelListItemActionButtons.tsx"],"sourcesContent":["import React, { type ComponentProps, type ComponentType, type ReactNode } from 'react';\n\nimport clsx from 'clsx';\nimport { ContextMenu, useDialogIsOpen, useDialogOnNearestManager } from '../Dialog';\nimport { useComponentContext, useTranslationContext } from '../../context';\nimport {\n  defaultChannelActionSet,\n  useBaseChannelActionSetFilter,\n} from './ChannelListItemActionButtons.defaults';\nimport { useSplitActionSet } from '../Chat/hooks/useSplitActionSet';\nimport { useChannelListItemContext } from './ChannelListItem';\n\n/** No props. Spelled via `ComponentProps` because lint rejects an empty `{}` type. */\nexport type ChannelListItemActionButtonsProps = ComponentProps<ComponentType>;\n\ninterface ChannelListItemActionButtonsInterface {\n  (props: ChannelListItemActionButtonsProps): ReactNode;\n  getDialogId: (_: { channelId: string }) => string;\n  displayName: string;\n}\n\nexport const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface = () => {\n  const { ContextMenu: ContextMenuComponent = ContextMenu } = useComponentContext();\n  const { t } = useTranslationContext();\n  const { channel } = useChannelListItemContext();\n  const [referenceElement, setReferenceElement] =\n    React.useState<HTMLButtonElement | null>(null);\n  const [isRestoringFocus, setIsRestoringFocus] = React.useState(false);\n  const dialogId = ChannelListItemActionButtons.getDialogId({\n    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n    channelId: channel.id!,\n  });\n  const { dialog, dialogManager } = useDialogOnNearestManager({ id: dialogId });\n  const dialogIsOpen = useDialogIsOpen(dialogId, dialogManager?.id);\n\n  const closeContextMenu = React.useCallback(() => {\n    setIsRestoringFocus(true);\n    dialog?.close();\n\n    requestAnimationFrame(() => {\n      if (!referenceElement?.isConnected) {\n        setIsRestoringFocus(false);\n        return;\n      }\n\n      referenceElement.focus();\n\n      requestAnimationFrame(() => {\n        if (document.activeElement !== referenceElement) {\n          setIsRestoringFocus(false);\n        }\n      });\n    });\n  }, [dialog, referenceElement]);\n\n  const filteredActionSet = useBaseChannelActionSetFilter(defaultChannelActionSet);\n  const { dropdownActionSet, quickActionSet, quickDropdownToggleAction } =\n    useSplitActionSet(filteredActionSet);\n\n  if (quickActionSet.length + dropdownActionSet.length === 0) {\n    return null;\n  }\n\n  return (\n    <div\n      className={clsx('str-chat__channel-list-item__action-buttons', {\n        'str-chat__channel-list-item__action-buttons--active':\n          dialogIsOpen || isRestoringFocus,\n      })}\n      data-testid='channel-list-item-action-buttons'\n      onFocusCapture={() => {\n        setIsRestoringFocus(false);\n      }}\n    >\n      {quickDropdownToggleAction && dropdownActionSet.length > 0 && (\n        <quickDropdownToggleAction.Component ref={setReferenceElement} />\n      )}\n      {quickActionSet.map(({ Component, type }) => (\n        <Component key={type} />\n      ))}\n      <ContextMenuComponent\n        aria-label={t('channelListItem.channelActions.ariaLabel', 'Channel Actions')}\n        className='str-chat__channel-list-item__action-buttons-context-menu'\n        data-testid='channel-list-item-context-menu'\n        dialogManagerId={dialogManager?.id}\n        id={dialog.id}\n        onClose={closeContextMenu}\n        placement='bottom-start'\n        referenceElement={referenceElement}\n        tabIndex={-1}\n        trapFocus\n      >\n        {dropdownActionSet.map(({ Component, type }) => (\n          <Component key={type} />\n        ))}\n      </ContextMenuComponent>\n    </div>\n  );\n};\n\nChannelListItemActionButtons.getDialogId = ({ channelId }) =>\n  `channel-action-buttons-${channelId}`;\n\nChannelListItemActionButtons.displayName = 'ChannelListItemActionButtons';\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,qCAA4E;CACvF,MAAM,EAAE,aAAa,uBAAuB,gBAAgB,oBAAoB;CAChF,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,YAAY,0BAA0B;CAC9C,MAAM,CAAC,kBAAkB,uBACvB,MAAM,SAAmC,IAAI;CAC/C,MAAM,CAAC,kBAAkB,uBAAuB,MAAM,SAAS,KAAK;CACpE,MAAM,WAAW,6BAA6B,YAAY,EAExD,WAAW,QAAQ,GACrB,CAAC;CACD,MAAM,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