{"version":3,"file":"SuggestionListItem.mjs","names":[],"sources":["../../../../../src/components/TextareaComposer/SuggestionList/SuggestionListItem.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { type ComponentProps, useRef } from 'react';\nimport React, { useCallback, useLayoutEffect } from 'react';\nimport { useMessageComposerController } from '../../MessageComposer/hooks/useMessageComposerController';\nimport type { TextComposerSuggestion } from 'stream-chat';\nimport type { CommandItemProps } from './CommandItem';\nimport type { EmoticonItemProps } from './EmoticonItem';\nimport type { MentionItemProps } from './MentionItem';\nimport { useMessageComposerContext } from '../../../context';\n\nexport type DefaultSuggestionListItemEntity =\n  | MentionItemProps['entity']\n  | CommandItemProps['entity']\n  | EmoticonItemProps['entity'];\n\nexport type SuggestionListItemComponentProps = {\n  entity: DefaultSuggestionListItemEntity | unknown;\n  focused: boolean;\n} & ComponentProps<'button'>;\n\nexport type SuggestionItemProps = ComponentProps<'button'> & {\n  component: React.ComponentType<SuggestionListItemComponentProps>;\n  item: TextComposerSuggestion;\n  focused: boolean;\n};\n\nexport const SuggestionListItem = ({\n  className,\n  component: Component,\n  focused,\n  item,\n  onClick,\n  onKeyDown,\n  onMouseEnter,\n  ...restProps\n}: SuggestionItemProps) => {\n  const { textComposer } = useMessageComposerController();\n  const { textareaRef } = useMessageComposerContext();\n  const componentRef = useRef<HTMLButtonElement | null>(null);\n\n  const handleSelect = useCallback(() => {\n    textComposer.handleSelect(item);\n    textareaRef.current?.focus();\n  }, [item, textareaRef, textComposer]);\n\n  useLayoutEffect(() => {\n    if (!focused) return;\n    componentRef.current?.scrollIntoView({ behavior: 'instant', block: 'nearest' });\n  }, [focused]);\n\n  return (\n    <Component\n      {...restProps}\n      className={clsx('str-chat__suggestion-list-item', className, {\n        'str-chat__suggestion-list-item--selected': focused,\n      })}\n      entity={item}\n      focused={focused}\n      onClick={(e) => {\n        handleSelect();\n        onClick?.(e);\n      }}\n      onKeyDown={(event) => {\n        if (event.key === 'Enter') handleSelect();\n        onKeyDown?.(event);\n      }}\n      onMouseEnter={onMouseEnter}\n      ref={componentRef}\n    />\n  );\n};\n"],"mappings":";;;;;;AA0BA,IAAa,sBAAsB,EACjC,WACA,WAAW,WACX,SACA,MACA,SACA,WACA,cACA,GAAG,gBACsB;CACzB,MAAM,EAAE,iBAAiB,6BAA6B;CACtD,MAAM,EAAE,gBAAgB,0BAA0B;CAClD,MAAM,eAAe,OAAiC,IAAI;CAE1D,MAAM,eAAe,kBAAkB;EACrC,aAAa,aAAa,IAAI;EAC9B,YAAY,SAAS,MAAM;CAC7B,GAAG;EAAC;EAAM;EAAa;CAAY,CAAC;CAEpC,sBAAsB;EACpB,IAAI,CAAC,SAAS;EACd,aAAa,SAAS,eAAe;GAAE,UAAU;GAAW,OAAO;EAAU,CAAC;CAChF,GAAG,CAAC,OAAO,CAAC;CAEZ,OACE,oBAAC,WAAD;EACE,GAAI;EACJ,WAAW,KAAK,kCAAkC,WAAW,EAC3D,4CAA4C,QAC9C,CAAC;EACD,QAAQ;EACC;EACT,UAAU,MAAM;GACd,aAAa;GACb,UAAU,CAAC;EACb;EACA,YAAY,UAAU;GACpB,IAAI,MAAM,QAAQ,SAAS,aAAa;GACxC,YAAY,KAAK;EACnB;EACc;EACd,KAAK;CACN,CAAA;AAEL"}