import { useMemo } from 'react';

import type { ThreadContextValue } from '../../threadContext/ThreadContext';
import type { MessageInputContextValue } from '../MessageInputContext';

export const useCreateMessageInputContext = ({
  additionalTextInputProps,
  allowSendBeforeAttachmentsUpload,
  asyncMessagesLockDistance,
  asyncMessagesMinimumPressDuration,
  asyncMessagesSlideToCancelDistance,
  audioRecordingSendOnComplete,
  attachmentPickerBottomSheetHeight,
  attachmentSelectionBarHeight,
  audioRecordingEnabled,
  closeAttachmentPicker,
  closePollCreationDialog,
  compressImageQuality,
  createPollOptionGap,
  editMessage,
  focusInputOnPickerClose,
  handleAttachButtonPress,
  hasCameraPicker,
  hasCommands,
  hasFilePicker,
  hasImagePicker,
  inputBoxRef,
  messageInputFloating,
  messageInputHeightStore,
  openAttachmentPicker,
  openPollCreationDialog,
  pickAndUploadImageFromNativePicker,
  pickFile,
  sendMessage,
  setInputBoxRef,
  setInputRef,
  showPollCreationDialog,
  takeAndUploadImage,
  uploadNewFile,
  audioRecorderManager,
  startVoiceRecording,
  deleteVoiceRecording,
  uploadVoiceRecording,
  stopVoiceRecording,
  thread,
}: MessageInputContextValue & Pick<ThreadContextValue, 'thread'>) => {
  const threadId = thread?.id;

  const messageInputContext: MessageInputContextValue = useMemo(
    () => ({
      additionalTextInputProps,
      allowSendBeforeAttachmentsUpload,
      asyncMessagesLockDistance,
      asyncMessagesMinimumPressDuration,
      asyncMessagesSlideToCancelDistance,
      audioRecordingSendOnComplete,
      attachmentPickerBottomSheetHeight,
      attachmentSelectionBarHeight,
      audioRecordingEnabled,
      closeAttachmentPicker,
      closePollCreationDialog,
      compressImageQuality,
      createPollOptionGap,
      editMessage,
      focusInputOnPickerClose,
      handleAttachButtonPress,
      hasCameraPicker,
      hasCommands,
      hasFilePicker,
      hasImagePicker,
      inputBoxRef,
      messageInputFloating,
      messageInputHeightStore,
      openAttachmentPicker,
      openPollCreationDialog,
      pickAndUploadImageFromNativePicker,
      pickFile,
      sendMessage,
      setInputBoxRef,
      setInputRef,
      showPollCreationDialog,
      takeAndUploadImage,
      uploadNewFile,
      audioRecorderManager,
      startVoiceRecording,
      deleteVoiceRecording,
      uploadVoiceRecording,
      stopVoiceRecording,
    }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [threadId, showPollCreationDialog, allowSendBeforeAttachmentsUpload],
  );

  return messageInputContext;
};
