{"version":3,"file":"MessageComposerActions.mjs","names":[],"sources":["../../../../src/components/MessageComposer/MessageComposerActions.tsx"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { StopAIGenerationButton as DefaultStopAIGenerationButton } from './StopAIGenerationButton';\nimport { CooldownTimer as DefaultCooldownTimer } from './CooldownTimer';\nimport { SendButton as DefaultSendButton } from './SendButton';\nimport {\n  useChannel,\n  useComponentContext,\n  useComponentContextIcons,\n  useMessageComposerContext,\n} from '../../context';\nimport { useAIState } from '../AIStateIndicator';\nimport {\n  useMessageComposerController,\n  useMessageComposerSubmitFn,\n  useMessageContentIsEmpty,\n} from './hooks';\nimport { AudioRecordingButtonWithNotification } from '../MediaRecorder/AudioRecorder/AudioRecordingButtonWithNotification';\nimport { useIsCooldownActive } from './hooks/useIsCooldownActive';\nimport { AIStates } from 'stream-chat';\nimport type { AIState, MessageComposerState, TextComposerState } from 'stream-chat';\nimport { useStateStore } from '../../store';\nimport { useInertWhenHidden } from '../Accessibility';\n\n// Typed as `AIState[]` because an inferred array of the literal-typed `AIStates` members would\n// reject the wide `AIState` that `useAIState` returns.\nconst STOPPABLE_AI_STATES: readonly AIState[] = [AIStates.Thinking, AIStates.Generating];\n\nconst messageComposerStateSelector = ({ editedMessage }: MessageComposerState) => ({\n  editedMessage,\n});\n\nconst textComposerStateSelector = ({ command, text }: TextComposerState) => ({\n  command,\n  text,\n});\n\nexport const MessageComposerActions = () => {\n  const { IconCheckmark, IconSend } = useComponentContextIcons();\n  const channel = useChannel();\n  const { hideSendButton } = useMessageComposerContext();\n  const messageComposer = useMessageComposerController();\n  const {\n    CooldownTimer = DefaultCooldownTimer,\n    SendButton,\n    StopAIGenerationButton: StopAIGenerationButtonOverride,\n  } = useComponentContext();\n\n  const { editedMessage } = useStateStore(\n    messageComposer.state,\n    messageComposerStateSelector,\n  );\n\n  const { command } = useStateStore(\n    messageComposer.textComposer.state,\n    textComposerStateSelector,\n  );\n\n  const contentIsEmpty = useMessageContentIsEmpty();\n  // Only `undefined` falls back to the default, so a `StopAIGenerationButton: null` override\n  // removes the stop button.\n  const StopAIGenerationButton =\n    StopAIGenerationButtonOverride === undefined\n      ? DefaultStopAIGenerationButton\n      : StopAIGenerationButtonOverride;\n\n  const { recordingController } = useMessageComposerContext();\n  const submitMessageFn = useMessageComposerSubmitFn();\n  const isCooldownActive = useIsCooldownActive();\n\n  const { aiState } = useAIState(channel);\n  const stopGenerating = useCallback(() => channel?.stopAIResponse(), [channel]);\n  const shouldDisplayStopAIGeneration =\n    STOPPABLE_AI_STATES.includes(aiState) && !!StopAIGenerationButton;\n\n  // Accounts for an iOS requirement, see https://bugs.webkit.org/show_bug.cgi?id=252303\n  const recordingEnabled = !!(recordingController.recorder && navigator.mediaDevices);\n\n  // One control fills the slot, first match wins. While the AI is answering, stopping it is the\n  // only useful action, so the stop button outranks everything else, `hideSendButton` included.\n  let content: React.ReactNode;\n  if (shouldDisplayStopAIGeneration) {\n    content = <StopAIGenerationButton onClick={stopGenerating} />;\n  } else if (hideSendButton) {\n    return null;\n  } else if (isCooldownActive) {\n    content = <CooldownTimer />;\n  } else if (contentIsEmpty && !editedMessage && !command && recordingEnabled) {\n    content = <AudioRecordingButtonWithNotification />;\n  } else if (SendButton) {\n    content = <SendButton sendMessage={submitMessageFn} />;\n  } else {\n    content = (\n      <DefaultSendButton sendMessage={submitMessageFn}>\n        {editedMessage || command ? <IconCheckmark /> : <IconSend />}\n      </DefaultSendButton>\n    );\n  }\n\n  return <div className='str-chat__message-composer__actions'>{content}</div>;\n};\n\nexport const AdditionalMessageComposerActions = () => {\n  const { EmojiPicker } = useComponentContext();\n  const isCooldownActive = useIsCooldownActive();\n  const messageComposer = useMessageComposerController();\n  const { command } = useStateStore(\n    messageComposer.textComposer.state,\n    textComposerStateSelector,\n  );\n  // Hidden by a CSS transition while a command is active. Inert keeps them out of the a11y tree\n  // and tab order without `display: none`, which would break the transition.\n  const inertProps = useInertWhenHidden(!!command, { setHiddenAttribute: false });\n\n  return (\n    <div className='str-chat__message-composer__additional-actions' {...inertProps}>\n      {!isCooldownActive && EmojiPicker ? <EmojiPicker /> : null}\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,IAAM,sBAA0C,CAAC,SAAS,UAAU,SAAS,UAAU;AAEvF,IAAM,gCAAgC,EAAE,qBAA2C,EACjF,cACF;AAEA,IAAM,6BAA6B,EAAE,SAAS,YAA+B;CAC3E;CACA;AACF;AAEA,IAAa,+BAA+B;CAC1C,MAAM,EAAE,eAAe,aAAa,yBAAyB;CAC7D,MAAM,UAAU,WAAW;CAC3B,MAAM,EAAE,mBAAmB,0BAA0B;CACrD,MAAM,kBAAkB,6BAA6B;CACrD,MAAM,EACJ,eAAA,kBAAgB,eAChB,YAAA,cACA,wBAAwB,mCACtB,oBAAoB;CAExB,MAAM,EAAE,kBAAkB,cACxB,gBAAgB,OAChB,4BACF;CAEA,MAAM,EAAE,YAAY,cAClB,gBAAgB,aAAa,OAC7B,yBACF;CAEA,MAAM,iBAAiB,yBAAyB;CAGhD,MAAM,2BACJ,mCAAmC,KAAA,IAC/B,yBACA;CAEN,MAAM,EAAE,wBAAwB,0BAA0B;CAC1D,MAAM,kBAAkB,2BAA2B;CACnD,MAAM,mBAAmB,oBAAoB;CAE7C,MAAM,EAAE,YAAY,WAAW,OAAO;CACtC,MAAM,iBAAiB,kBAAkB,SAAS,eAAe,GAAG,CAAC,OAAO,CAAC;CAC7E,MAAM,gCACJ,oBAAoB,SAAS,OAAO,KAAK,CAAC,CAAC;CAG7C,MAAM,mBAAmB,CAAC,EAAE,oBAAoB,YAAY,UAAU;CAItE,IAAI;CACJ,IAAI,+BACF,UAAU,oBAAC,0BAAD,EAAwB,SAAS,eAAiB,CAAA;MACvD,IAAI,gBACT,OAAO;MACF,IAAI,kBACT,UAAU,oBAAC,iBAAD,CAAgB,CAAA;MACrB,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,WAAW,kBACzD,UAAU,oBAAC,sCAAD,CAAuC,C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