var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useMessageInputContext = exports.MessageInputProvider = exports.MessageInputContext = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _uniq = _interopRequireDefault(require("lodash/uniq"));
var _streamChat = require("stream-chat");
var _useCreateMessageInputContext = require("./hooks/useCreateMessageInputContext");
var _useMessageDetailsForState = require("./hooks/useMessageDetailsForState");
var _utils = require("./utils/utils");
var _parseLinks = require("../../components/Message/MessageSimple/utils/parseLinks");
var _useCooldown2 = require("../../components/MessageInput/hooks/useCooldown");
var _native = require("../../native");
var _types = require("../../types/types");
var _ACITriggerSettings = require("../../utils/ACITriggerSettings");
var _compressImage = require("../../utils/compressImage");
var _removeReservedFields = require("../../utils/removeReservedFields");
var _utils2 = require("../../utils/utils");
var _AttachmentPickerContext = require("../attachmentPickerContext/AttachmentPickerContext");
var _ChannelContext = require("../channelContext/ChannelContext");
var _ChatContext = require("../chatContext/ChatContext");
var _MessagesContext = require("../messagesContext/MessagesContext");
var _OwnCapabilitiesContext = require("../ownCapabilitiesContext/OwnCapabilitiesContext");
var _ThreadContext = require("../threadContext/ThreadContext");
var _TranslationContext = require("../translationContext/TranslationContext");
var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
var _isTestEnvironment = require("../utils/isTestEnvironment");
var _jsxRuntime = require("react/jsx-runtime");
var _this = this,
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/messageInputContext/MessageInputContext.tsx";
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function escapeRegExp(text) {
  return text.replace(/[[\]{}()*+?,\\^$|#\s]/g, '_');
}
var MessageInputContext = exports.MessageInputContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
var MessageInputProvider = exports.MessageInputProvider = function MessageInputProvider(_ref) {
  var children = _ref.children,
    value = _ref.value;
  var _useAttachmentPickerC = (0, _AttachmentPickerContext.useAttachmentPickerContext)(),
    closePicker = _useAttachmentPickerC.closePicker,
    openPicker = _useAttachmentPickerC.openPicker,
    selectedFiles = _useAttachmentPickerC.selectedFiles,
    selectedImages = _useAttachmentPickerC.selectedImages,
    selectedPicker = _useAttachmentPickerC.selectedPicker,
    setSelectedFiles = _useAttachmentPickerC.setSelectedFiles,
    setSelectedImages = _useAttachmentPickerC.setSelectedImages,
    setSelectedPicker = _useAttachmentPickerC.setSelectedPicker;
  var _useChatContext = (0, _ChatContext.useChatContext)(),
    appSettings = _useChatContext.appSettings,
    client = _useChatContext.client,
    enableOfflineSupport = _useChatContext.enableOfflineSupport,
    isOnline = _useChatContext.isOnline;
  var _useMessagesContext = (0, _MessagesContext.useMessagesContext)(),
    removeMessage = _useMessagesContext.removeMessage;
  var getFileUploadConfig = function getFileUploadConfig() {
    var _appSettings$app;
    var fileConfig = appSettings == null || (_appSettings$app = appSettings.app) == null ? void 0 : _appSettings$app.file_upload_config;
    if (fileConfig !== undefined) {
      return fileConfig;
    } else {
      return {};
    }
  };
  var getImageUploadConfig = function getImageUploadConfig() {
    var _appSettings$app2;
    var imageConfig = appSettings == null || (_appSettings$app2 = appSettings.app) == null ? void 0 : _appSettings$app2.image_upload_config;
    if (imageConfig !== undefined) {
      return imageConfig;
    }
    return {};
  };
  var channelCapabities = (0, _OwnCapabilitiesContext.useOwnCapabilitiesContext)();
  var _useChannelContext = (0, _ChannelContext.useChannelContext)(),
    channel = _useChannelContext.channel,
    giphyEnabled = _useChannelContext.giphyEnabled,
    uploadAbortControllerRef = _useChannelContext.uploadAbortControllerRef;
  var _useThreadContext = (0, _ThreadContext.useThreadContext)(),
    thread = _useThreadContext.thread;
  var _useTranslationContex = (0, _TranslationContext.useTranslationContext)(),
    t = _useTranslationContex.t;
  var inputBoxRef = (0, _react.useRef)(null);
  var sending = (0, _react.useRef)(false);
  var _useState = (0, _react.useState)([]),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    asyncIds = _useState2[0],
    setAsyncIds = _useState2[1];
  var _useState3 = (0, _react.useState)({}),
    _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
    asyncUploads = _useState4[0],
    setAsyncUploads = _useState4[1];
  var _useState5 = (0, _react.useState)(false),
    _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
    giphyActive = _useState6[0],
    setGiphyActive = _useState6[1];
  var _useState7 = (0, _react.useState)(false),
    _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
    sendThreadMessageInChannel = _useState8[0],
    setSendThreadMessageInChannel = _useState8[1];
  var _useState9 = (0, _react.useState)(false),
    _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
    showPollCreationDialog = _useState10[0],
    setShowPollCreationDialog = _useState10[1];
  var defaultOpenPollCreationDialog = (0, _react.useCallback)(function () {
    return setShowPollCreationDialog(true);
  }, []);
  var closePollCreationDialog = (0, _react.useCallback)(function () {
    return setShowPollCreationDialog(false);
  }, []);
  var editing = value.editing,
    initialValue = value.initialValue,
    openPollCreationDialogFromContext = value.openPollCreationDialog,
    StopMessageStreamingButton = value.StopMessageStreamingButton;
  var _useMessageDetailsFor = (0, _useMessageDetailsForState.useMessageDetailsForState)(editing, initialValue),
    fileUploads = _useMessageDetailsFor.fileUploads,
    imageUploads = _useMessageDetailsFor.imageUploads,
    mentionedUsers = _useMessageDetailsFor.mentionedUsers,
    numberOfUploads = _useMessageDetailsFor.numberOfUploads,
    setFileUploads = _useMessageDetailsFor.setFileUploads,
    setImageUploads = _useMessageDetailsFor.setImageUploads,
    setMentionedUsers = _useMessageDetailsFor.setMentionedUsers,
    setNumberOfUploads = _useMessageDetailsFor.setNumberOfUploads,
    setShowMoreOptions = _useMessageDetailsFor.setShowMoreOptions,
    setText = _useMessageDetailsFor.setText,
    showMoreOptions = _useMessageDetailsFor.showMoreOptions,
    text = _useMessageDetailsFor.text;
  var _useCooldown = (0, _useCooldown2.useCooldown)(),
    cooldownEndsAt = _useCooldown.endsAt,
    startCooldown = _useCooldown.start;
  var onChangeText = value.onChangeText,
    emojiSearchIndex = value.emojiSearchIndex,
    autoCompleteTriggerSettings = value.autoCompleteTriggerSettings;
  var threadId = thread == null ? void 0 : thread.id;
  (0, _react.useEffect)(function () {
    setSendThreadMessageInChannel(false);
  }, [threadId]);
  var appendText = useStableCallback(function (newText) {
    setText(function (prevText) {
      return "".concat(prevText).concat(newText);
    });
  });
  var isValidMessage = useStableCallback(function () {
    if (text && text.trim()) {
      return true;
    }
    var imagesAndFiles = [].concat((0, _toConsumableArray2["default"])(imageUploads), (0, _toConsumableArray2["default"])(fileUploads));
    if (imagesAndFiles.length === 0) {
      return false;
    }
    if (enableOfflineSupport) {
      var _iterator = _createForOfIteratorHelper(imagesAndFiles),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var file = _step.value;
          if (file.state === _utils2.FileState.NOT_SUPPORTED) {
            return false;
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
      return true;
    }
    var _iterator2 = _createForOfIteratorHelper(imagesAndFiles),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _file = _step2.value;
        if (!_file || _file.state === _utils2.FileState.UPLOAD_FAILED) {
          continue;
        }
        if (_file.state === _utils2.FileState.UPLOADING) {
          return false;
        }
        return true;
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    return false;
  });
  var onChange = (0, _react.useCallback)(function (newText) {
    if (sending.current) {
      return;
    }
    setText(newText);
    if (newText && channel && channelCapabities.sendTypingEvents && isOnline) {
      (0, _streamChat.logChatPromiseExecution)(channel.keystroke(thread == null ? void 0 : thread.id), 'start typing event');
    }
    if (onChangeText) {
      onChangeText(newText);
    }
  }, [channel, channelCapabities.sendTypingEvents, isOnline, setText, thread == null ? void 0 : thread.id, onChangeText]);
  var openCommandsPicker = useStableCallback(function () {
    appendText('/');
    if (inputBoxRef.current) {
      inputBoxRef.current.focus();
    }
  });
  var openMentionsPicker = useStableCallback(function () {
    appendText('@');
    if (inputBoxRef.current) {
      inputBoxRef.current.focus();
    }
  });
  var takeAndUploadImage = useStableCallback(function () {
    var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(mediaType) {
      var file;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            setSelectedPicker(undefined);
            closePicker();
            _context.next = 4;
            return _native.NativeHandlers.takePhoto({
              compressImageQuality: value.compressImageQuality,
              mediaType: mediaType
            });
          case 4:
            file = _context.sent;
            if (file.askToOpenSettings) {
              _reactNative.Alert.alert(t('Allow camera access in device settings'), t('Device camera is used to take photos or videos.'), [{
                style: 'cancel',
                text: t('Cancel')
              }, {
                onPress: function onPress() {
                  return _reactNative.Linking.openSettings();
                },
                style: 'default',
                text: t('Open Settings')
              }]);
            }
            if (file.cancelled) {
              _context.next = 14;
              break;
            }
            if (!file.type.includes('image')) {
              _context.next = 12;
              break;
            }
            _context.next = 10;
            return uploadNewImage(file);
          case 10:
            _context.next = 14;
            break;
          case 12:
            _context.next = 14;
            return uploadNewFile(file);
          case 14:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x) {
      return _ref2.apply(this, arguments);
    };
  }());
  var pickAndUploadImageFromNativePicker = useStableCallback((0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
    var result;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          _context3.next = 2;
          return _native.NativeHandlers.pickImage();
        case 2:
          result = _context3.sent;
          if (result.askToOpenSettings) {
            _reactNative.Alert.alert(t('Allow access to your Gallery'), t('Device gallery permissions is used to take photos or videos.'), [{
              style: 'cancel',
              text: t('Cancel')
            }, {
              onPress: function onPress() {
                return _reactNative.Linking.openSettings();
              },
              style: 'default',
              text: t('Open Settings')
            }]);
          }
          if (!(numberOfUploads >= value.maxNumberOfFiles)) {
            _context3.next = 7;
            break;
          }
          _reactNative.Alert.alert(t('Maximum number of files reached'));
          return _context3.abrupt("return");
        case 7:
          if (!(result.assets && result.assets.length > 0)) {
            _context3.next = 12;
            break;
          }
          if (!(result.assets.length > value.maxNumberOfFiles)) {
            _context3.next = 11;
            break;
          }
          _reactNative.Alert.alert(t('Maximum number of files reached'));
          return _context3.abrupt("return");
        case 11:
          result.assets.forEach(function () {
            var _ref4 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(asset) {
              var compressedURI;
              return _regenerator["default"].wrap(function _callee2$(_context2) {
                while (1) switch (_context2.prev = _context2.next) {
                  case 0:
                    if (!asset.type.includes('image')) {
                      _context2.next = 8;
                      break;
                    }
                    _context2.next = 3;
                    return (0, _compressImage.compressedImageURI)(asset, value.compressImageQuality);
                  case 3:
                    compressedURI = _context2.sent;
                    _context2.next = 6;
                    return uploadNewImage(Object.assign({}, asset, {
                      uri: compressedURI
                    }));
                  case 6:
                    _context2.next = 10;
                    break;
                  case 8:
                    _context2.next = 10;
                    return uploadNewFile(asset);
                  case 10:
                  case "end":
                    return _context2.stop();
                }
              }, _callee2);
            }));
            return function (_x2) {
              return _ref4.apply(this, arguments);
            };
          }());
        case 12:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  var openAttachmentPicker = (0, _react.useCallback)(function () {
    _reactNative.Keyboard.dismiss();
    setSelectedPicker('images');
    openPicker();
  }, [openPicker, setSelectedPicker]);
  var closeAttachmentPicker = (0, _react.useCallback)(function () {
    setSelectedPicker(undefined);
    closePicker();
  }, [closePicker, setSelectedPicker]);
  var toggleAttachmentPicker = (0, _react.useCallback)(function () {
    if (selectedPicker) {
      closeAttachmentPicker();
    } else {
      openAttachmentPicker();
    }
  }, [closeAttachmentPicker, openAttachmentPicker, selectedPicker]);
  var onSelectItem = useStableCallback(function (item) {
    setMentionedUsers(function (prevMentionedUsers) {
      return [].concat((0, _toConsumableArray2["default"])(prevMentionedUsers), [item.id]);
    });
  });
  var pickFile = useStableCallback((0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5() {
    var result;
    return _regenerator["default"].wrap(function _callee5$(_context5) {
      while (1) switch (_context5.prev = _context5.next) {
        case 0:
          if ((0, _native.isDocumentPickerAvailable)()) {
            _context5.next = 3;
            break;
          }
          console.log('The file picker is not installed. Check our Getting Started documentation to install it.');
          return _context5.abrupt("return");
        case 3:
          if (!(numberOfUploads >= value.maxNumberOfFiles)) {
            _context5.next = 6;
            break;
          }
          _reactNative.Alert.alert(t('Maximum number of files reached'));
          return _context5.abrupt("return");
        case 6:
          _context5.next = 8;
          return _native.NativeHandlers.pickDocument({
            maxNumberOfFiles: value.maxNumberOfFiles - numberOfUploads
          });
        case 8:
          result = _context5.sent;
          if (!result.cancelled && result.assets) {
            result.assets.forEach(function () {
              var _ref6 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(asset) {
                var compressedURI;
                return _regenerator["default"].wrap(function _callee4$(_context4) {
                  while (1) switch (_context4.prev = _context4.next) {
                    case 0:
                      if (!asset.type.includes('image')) {
                        _context4.next = 8;
                        break;
                      }
                      _context4.next = 3;
                      return (0, _compressImage.compressedImageURI)(asset, value.compressImageQuality);
                    case 3:
                      compressedURI = _context4.sent;
                      _context4.next = 6;
                      return uploadNewImage(Object.assign({}, asset, {
                        uri: compressedURI
                      }));
                    case 6:
                      _context4.next = 10;
                      break;
                    case 8:
                      _context4.next = 10;
                      return uploadNewFile(asset);
                    case 10:
                    case "end":
                      return _context4.stop();
                  }
                }, _callee4);
              }));
              return function (_x3) {
                return _ref6.apply(this, arguments);
              };
            }());
          }
        case 10:
        case "end":
          return _context5.stop();
      }
    }, _callee5);
  })));
  var removeFile = (0, _react.useCallback)(function (id) {
    if (fileUploads.some(function (file) {
      return file.id === id;
    })) {
      setFileUploads(function (prevFileUploads) {
        return prevFileUploads.filter(function (file) {
          return file.id !== id;
        });
      });
      setNumberOfUploads(function (prevNumberOfUploads) {
        return prevNumberOfUploads - 1;
      });
    }
  }, [fileUploads, setFileUploads, setNumberOfUploads]);
  var removeImage = (0, _react.useCallback)(function (id) {
    if (imageUploads.some(function (image) {
      return image.id === id;
    })) {
      setImageUploads(function (prevImageUploads) {
        return prevImageUploads.filter(function (image) {
          return image.id !== id;
        });
      });
      setNumberOfUploads(function (prevNumberOfUploads) {
        return prevNumberOfUploads - 1;
      });
    }
  }, [imageUploads, setImageUploads, setNumberOfUploads]);
  var resetInput = useStableCallback(function () {
    var pendingAttachments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    if ((0, _native.isImageMediaLibraryAvailable)()) {
      setSelectedFiles([]);
      setSelectedImages([]);
    }
    setFileUploads([]);
    setGiphyActive(false);
    setShowMoreOptions(true);
    setImageUploads([]);
    setMentionedUsers([]);
    setNumberOfUploads(function (prevNumberOfUploads) {
      return prevNumberOfUploads - ((pendingAttachments == null ? void 0 : pendingAttachments.length) || 0);
    });
    setText('');
    if (value.editing) {
      value.clearEditingState();
    }
  });
  var mapImageUploadToAttachment = useStableCallback(function (image) {
    return {
      fallback: image.file.name,
      image_url: image.url,
      mime_type: image.file.type,
      original_height: image.file.height,
      original_width: image.file.width,
      originalImage: image.file,
      type: _types.FileTypes.Image
    };
  });
  var mapFileUploadToAttachment = useStableCallback(function (file) {
    if (file.type === _types.FileTypes.Image) {
      return {
        fallback: file.file.name,
        image_url: file.url,
        mime_type: file.file.type,
        original_height: file.file.height,
        original_width: file.file.width,
        originalFile: file.file,
        type: _types.FileTypes.Image
      };
    } else if (file.type === _types.FileTypes.Audio) {
      return {
        asset_url: file.url || file.file.uri,
        duration: file.file.duration,
        file_size: file.file.size,
        mime_type: file.file.type,
        originalFile: file.file,
        title: file.file.name,
        type: _types.FileTypes.Audio
      };
    } else if (file.type === _types.FileTypes.Video) {
      return {
        asset_url: file.url || file.file.uri,
        duration: file.file.duration,
        file_size: file.file.size,
        mime_type: file.file.type,
        originalFile: file.file,
        thumb_url: file.thumb_url,
        title: file.file.name,
        type: _types.FileTypes.Video
      };
    } else if (file.type === _types.FileTypes.VoiceRecording) {
      return {
        asset_url: file.url || file.file.uri,
        duration: file.file.duration,
        file_size: file.file.size,
        mime_type: file.file.type,
        originalFile: file.file,
        title: file.file.name,
        type: _types.FileTypes.VoiceRecording,
        waveform_data: file.file.waveform_data
      };
    } else {
      return {
        asset_url: file.url || file.file.uri,
        file_size: file.file.size,
        mime_type: file.file.type,
        originalFile: file.file,
        title: file.file.name,
        type: _types.FileTypes.File
      };
    }
  });
  var sendMessage = useStableCallback((0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6() {
    var _ref8,
      customMessageData,
      linkInfos,
      prevText,
      attachments,
      _loop,
      _ret,
      _iterator3,
      _step3,
      image,
      _iterator4,
      _step4,
      file,
      message,
      updatedMessage,
      updateMessagePromise,
      _args7 = arguments;
    return _regenerator["default"].wrap(function _callee6$(_context7) {
      while (1) switch (_context7.prev = _context7.next) {
        case 0:
          _ref8 = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {}, customMessageData = _ref8.customMessageData;
          if (!sending.current) {
            _context7.next = 3;
            break;
          }
          return _context7.abrupt("return");
        case 3:
          linkInfos = (0, _parseLinks.parseLinksFromText)(text);
          if (!(!channelCapabities.sendLinks && linkInfos.length > 0)) {
            _context7.next = 7;
            break;
          }
          _reactNative.Alert.alert(t('Links are disabled'), t('Sending links is not allowed in this conversation'));
          return _context7.abrupt("return");
        case 7:
          sending.current = true;
          startCooldown();
          prevText = giphyEnabled && giphyActive ? "/giphy ".concat(text) : text;
          setText('');
          if (inputBoxRef.current) {
            inputBoxRef.current.clear();
          }
          attachments = [];
          _loop = _regenerator["default"].mark(function _loop(image) {
            return _regenerator["default"].wrap(function _loop$(_context6) {
              while (1) switch (_context6.prev = _context6.next) {
                case 0:
                  if (!enableOfflineSupport) {
                    _context6.next = 5;
                    break;
                  }
                  if (!(image.state === _utils2.FileState.NOT_SUPPORTED)) {
                    _context6.next = 3;
                    break;
                  }
                  return _context6.abrupt("return", {
                    v: void 0
                  });
                case 3:
                  attachments.push(mapImageUploadToAttachment(image));
                  return _context6.abrupt("return", 0);
                case 5:
                  if (!((!image || image.state === _utils2.FileState.UPLOAD_FAILED) && !enableOfflineSupport)) {
                    _context6.next = 7;
                    break;
                  }
                  return _context6.abrupt("return", 0);
                case 7:
                  if (!(image.state === _utils2.FileState.UPLOADING)) {
                    _context6.next = 14;
                    break;
                  }
                  if (!value.sendImageAsync) {
                    _context6.next = 12;
                    break;
                  }
                  setAsyncIds(function (prevAsyncIds) {
                    return [].concat((0, _toConsumableArray2["default"])(prevAsyncIds), [image.id]);
                  });
                  _context6.next = 14;
                  break;
                case 12:
                  sending.current = false;
                  return _context6.abrupt("return", {
                    v: setText(prevText)
                  });
                case 14:
                  if (image.state === _utils2.FileState.UPLOADED || image.state === _utils2.FileState.FINISHED) {
                    attachments.push(mapImageUploadToAttachment(image));
                  }
                case 15:
                case "end":
                  return _context6.stop();
              }
            }, _loop);
          });
          _iterator3 = _createForOfIteratorHelper(imageUploads);
          _context7.prev = 15;
          _iterator3.s();
        case 17:
          if ((_step3 = _iterator3.n()).done) {
            _context7.next = 27;
            break;
          }
          image = _step3.value;
          return _context7.delegateYield(_loop(image), "t0", 20);
        case 20:
          _ret = _context7.t0;
          if (!(_ret === 0)) {
            _context7.next = 23;
            break;
          }
          return _context7.abrupt("continue", 25);
        case 23:
          if (!_ret) {
            _context7.next = 25;
            break;
          }
          return _context7.abrupt("return", _ret.v);
        case 25:
          _context7.next = 17;
          break;
        case 27:
          _context7.next = 32;
          break;
        case 29:
          _context7.prev = 29;
          _context7.t1 = _context7["catch"](15);
          _iterator3.e(_context7.t1);
        case 32:
          _context7.prev = 32;
          _iterator3.f();
          return _context7.finish(32);
        case 35:
          _iterator4 = _createForOfIteratorHelper(fileUploads);
          _context7.prev = 36;
          _iterator4.s();
        case 38:
          if ((_step4 = _iterator4.n()).done) {
            _context7.next = 53;
            break;
          }
          file = _step4.value;
          if (!enableOfflineSupport) {
            _context7.next = 45;
            break;
          }
          if (!(file.state === _utils2.FileState.NOT_SUPPORTED)) {
            _context7.next = 43;
            break;
          }
          return _context7.abrupt("return");
        case 43:
          attachments.push(mapFileUploadToAttachment(file));
          return _context7.abrupt("continue", 51);
        case 45:
          if (!(!file || file.state === _utils2.FileState.UPLOAD_FAILED)) {
            _context7.next = 47;
            break;
          }
          return _context7.abrupt("continue", 51);
        case 47:
          if (!(file.state === _utils2.FileState.UPLOADING)) {
            _context7.next = 50;
            break;
          }
          sending.current = false;
          return _context7.abrupt("return");
        case 50:
          if (file.state === _utils2.FileState.UPLOADED || file.state === _utils2.FileState.FINISHED) {
            attachments.push(mapFileUploadToAttachment(file));
          }
        case 51:
          _context7.next = 38;
          break;
        case 53:
          _context7.next = 58;
          break;
        case 55:
          _context7.prev = 55;
          _context7.t2 = _context7["catch"](36);
          _iterator4.e(_context7.t2);
        case 58:
          _context7.prev = 58;
          _iterator4.f();
          return _context7.finish(58);
        case 61:
          if (!(!prevText && attachments.length === 0 && !(customMessageData != null && customMessageData.poll_id))) {
            _context7.next = 64;
            break;
          }
          sending.current = false;
          return _context7.abrupt("return");
        case 64:
          message = value.editing;
          if (!(message && message.type !== 'error')) {
            _context7.next = 74;
            break;
          }
          updatedMessage = Object.assign({}, message, {
            attachments: attachments,
            mentioned_users: mentionedUsers.map(function (userId) {
              return {
                id: userId
              };
            }),
            quoted_message: undefined,
            text: prevText
          }, customMessageData);
          value.clearEditingState();
          updateMessagePromise = value.editMessage((0, _removeReservedFields.removeReservedFields)(updatedMessage)).then(value.clearEditingState);
          (0, _streamChat.logChatPromiseExecution)(updateMessagePromise, 'update message');
          resetInput(attachments);
          sending.current = false;
          _context7.next = 90;
          break;
        case 74:
          _context7.prev = 74;
          if (!(message && (0, _utils2.isBouncedMessage)(message))) {
            _context7.next = 78;
            break;
          }
          _context7.next = 78;
          return removeMessage(message);
        case 78:
          value.sendMessage(Object.assign({
            attachments: attachments,
            mentioned_users: (0, _uniq["default"])(mentionedUsers),
            parent_id: thread == null ? void 0 : thread.id,
            quoted_message_id: value.quotedMessage ? value.quotedMessage.id : undefined,
            show_in_channel: sendThreadMessageInChannel || undefined,
            text: prevText
          }, customMessageData));
          value.clearQuotedMessageState();
          sending.current = false;
          resetInput(attachments);
          _context7.next = 90;
          break;
        case 84:
          _context7.prev = 84;
          _context7.t3 = _context7["catch"](74);
          sending.current = false;
          if (value.quotedMessage && typeof value.quotedMessage !== 'boolean') {
            value.setQuotedMessageState(value.quotedMessage);
          }
          setText(prevText.slice(giphyEnabled && giphyActive ? 7 : 0));
          console.log('Failed to send message');
        case 90:
        case "end":
          return _context7.stop();
      }
    }, _callee6, null, [[15, 29, 32, 35], [36, 55, 58, 61], [74, 84]]);
  })));
  var sendMessageAsync = useStableCallback(function (id) {
    var image = asyncUploads[id];
    if (!image || image.state === _utils2.FileState.UPLOAD_FAILED) {
      return;
    }
    if (image.state === _utils2.FileState.UPLOADED || image.state === _utils2.FileState.FINISHED) {
      var attachments = [{
        image_url: image.url,
        type: _types.FileTypes.Image
      }];
      startCooldown();
      try {
        value.sendMessage({
          attachments: attachments,
          mentioned_users: [],
          parent_id: thread == null ? void 0 : thread.id,
          quoted_message_id: value.quotedMessage ? value.quotedMessage.id : undefined,
          show_in_channel: sendThreadMessageInChannel || undefined,
          text: ''
        });
        setAsyncIds(function (prevAsyncIds) {
          return prevAsyncIds.splice(prevAsyncIds.indexOf(id), 1);
        });
        setAsyncUploads(function (prevAsyncUploads) {
          delete prevAsyncUploads[id];
          return prevAsyncUploads;
        });
        setNumberOfUploads(function (prevNumberOfUploads) {
          return prevNumberOfUploads - 1;
        });
      } catch (_error) {
        console.log('Failed');
      }
    }
  });
  var setInputBoxRef = useStableCallback(function (ref) {
    inputBoxRef.current = ref;
    if (value.setInputRef) {
      value.setInputRef(ref);
    }
  });
  var triggerSettings = (0, _react.useMemo)(function () {
    try {
      var _triggerSettings = {};
      if (channel) {
        if (autoCompleteTriggerSettings) {
          _triggerSettings = autoCompleteTriggerSettings({
            channel: channel,
            client: client,
            emojiSearchIndex: emojiSearchIndex,
            onMentionSelectItem: onSelectItem
          });
        } else {
          _triggerSettings = (0, _ACITriggerSettings.ACITriggerSettings)({
            channel: channel,
            client: client,
            emojiSearchIndex: emojiSearchIndex,
            onMentionSelectItem: onSelectItem
          });
        }
      }
      return _triggerSettings;
    } catch (error) {
      console.warn('Error in getting trigger settings', error);
      throw error;
    }
  }, [channel, client, onSelectItem, autoCompleteTriggerSettings, emojiSearchIndex]);
  var updateMessage = useStableCallback((0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7() {
    return _regenerator["default"].wrap(function _callee7$(_context8) {
      while (1) switch (_context8.prev = _context8.next) {
        case 0:
          _context8.prev = 0;
          if (!value.editing) {
            _context8.next = 4;
            break;
          }
          _context8.next = 4;
          return client.updateMessage(Object.assign({}, value.editing, {
            quoted_message: undefined,
            text: giphyEnabled && giphyActive ? "/giphy ".concat(text) : text
          }));
        case 4:
          value.clearEditingState();
          resetInput();
          _context8.next = 11;
          break;
        case 8:
          _context8.prev = 8;
          _context8.t0 = _context8["catch"](0);
          console.log(_context8.t0);
        case 11:
        case "end":
          return _context8.stop();
      }
    }, _callee7, null, [[0, 8]]);
  })));
  var regexCondition = /File (extension \.\w{2,4}|type \S+) is not supported/;
  var getUploadSetStateAction = useStableCallback(function (id, fileState) {
    var extraData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    return function (prevUploads) {
      return prevUploads.map(function (prevUpload) {
        if (prevUpload.id === id) {
          return Object.assign({}, prevUpload, extraData, {
            state: fileState
          });
        }
        return prevUpload;
      });
    };
  });
  var handleFileOrImageUploadError = useStableCallback(function (error, isImageError, id) {
    if (isImageError) {
      setNumberOfUploads(function (prevNumberOfUploads) {
        return prevNumberOfUploads - 1;
      });
      if (error instanceof Error) {
        if (regexCondition.test(error.message)) {
          return setImageUploads(getUploadSetStateAction(id, _utils2.FileState.NOT_SUPPORTED));
        }
        return setImageUploads(getUploadSetStateAction(id, _utils2.FileState.UPLOAD_FAILED));
      }
    } else {
      setNumberOfUploads(function (prevNumberOfUploads) {
        return prevNumberOfUploads - 1;
      });
      if (error instanceof Error) {
        if (regexCondition.test(error.message)) {
          return setFileUploads(getUploadSetStateAction(id, _utils2.FileState.NOT_SUPPORTED));
        }
        return setFileUploads(getUploadSetStateAction(id, _utils2.FileState.UPLOAD_FAILED));
      }
    }
  });
  var uploadFile = useStableCallback(function () {
    var _ref11 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee8(_ref10) {
      var newFile, file, id, filename, response, _file$type, compressedUri, extraData;
      return _regenerator["default"].wrap(function _callee8$(_context9) {
        while (1) switch (_context9.prev = _context9.next) {
          case 0:
            newFile = _ref10.newFile;
            file = newFile.file, id = newFile.id;
            filename = escapeRegExp(file.name);
            setFileUploads(getUploadSetStateAction(id, _utils2.FileState.UPLOADING));
            response = {};
            _context9.prev = 5;
            if (!value.doDocUploadRequest) {
              _context9.next = 12;
              break;
            }
            _context9.next = 9;
            return value.doDocUploadRequest(file, channel);
          case 9:
            response = _context9.sent;
            _context9.next = 27;
            break;
          case 12:
            if (!(channel && file.uri)) {
              _context9.next = 27;
              break;
            }
            uploadAbortControllerRef.current.set(filename, client.createAbortControllerForNextRequest());
            if (!((_file$type = file.type) != null && _file$type.includes('image'))) {
              _context9.next = 23;
              break;
            }
            _context9.next = 17;
            return (0, _compressImage.compressedImageURI)(file, value.compressImageQuality);
          case 17:
            compressedUri = _context9.sent;
            _context9.next = 20;
            return channel.sendFile(compressedUri, filename, file.type);
          case 20:
            response = _context9.sent;
            _context9.next = 26;
            break;
          case 23:
            _context9.next = 25;
            return channel.sendFile(file.uri, filename, file.type);
          case 25:
            response = _context9.sent;
          case 26:
            uploadAbortControllerRef.current["delete"](filename);
          case 27:
            extraData = {
              thumb_url: response.thumb_url,
              url: response.file
            };
            setFileUploads(getUploadSetStateAction(id, _utils2.FileState.UPLOADED, extraData));
            _context9.next = 37;
            break;
          case 31:
            _context9.prev = 31;
            _context9.t0 = _context9["catch"](5);
            if (!(_context9.t0 instanceof Error && (_context9.t0.name === 'AbortError' || _context9.t0.name === 'CanceledError'))) {
              _context9.next = 36;
              break;
            }
            uploadAbortControllerRef.current["delete"](filename);
            return _context9.abrupt("return");
          case 36:
            handleFileOrImageUploadError(_context9.t0, false, id);
          case 37:
          case "end":
            return _context9.stop();
        }
      }, _callee8, null, [[5, 31]]);
    }));
    return function (_x4) {
      return _ref11.apply(this, arguments);
    };
  }());
  var uploadImage = useStableCallback(function () {
    var _ref13 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee9(_ref12) {
      var _file$name;
      var newImage, _ref14, file, id, response, uri, filename, contentType, newImageUploads;
      return _regenerator["default"].wrap(function _callee9$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            newImage = _ref12.newImage;
            _ref14 = newImage || {}, file = _ref14.file, id = _ref14.id;
            if (file) {
              _context10.next = 4;
              break;
            }
            return _context10.abrupt("return");
          case 4:
            response = {};
            uri = file.uri || '';
            filename = escapeRegExp((_file$name = file.name) != null ? _file$name : (0, _utils2.getFileNameFromPath)(uri));
            _context10.prev = 7;
            contentType = file.type || 'multipart/form-data';
            if (!value.doImageUploadRequest) {
              _context10.next = 15;
              break;
            }
            _context10.next = 12;
            return value.doImageUploadRequest(file, channel);
          case 12:
            response = _context10.sent;
            _context10.next = 26;
            break;
          case 15:
            if (!channel) {
              _context10.next = 26;
              break;
            }
            if (!value.sendImageAsync) {
              _context10.next = 21;
              break;
            }
            uploadAbortControllerRef.current.set(filename, client.createAbortControllerForNextRequest());
            channel.sendImage(file.uri, filename, contentType).then(function (res) {
              uploadAbortControllerRef.current["delete"](filename);
              if (asyncIds.includes(id)) {
                setAsyncUploads(function (prevAsyncUploads) {
                  prevAsyncUploads[id] = Object.assign({}, prevAsyncUploads[id], {
                    state: _utils2.FileState.UPLOADED,
                    url: res.file
                  });
                  return prevAsyncUploads;
                });
              } else {
                var newImageUploads = getUploadSetStateAction(id, _utils2.FileState.UPLOADED, {
                  url: res.file
                });
                setImageUploads(newImageUploads);
              }
            }, function () {
              uploadAbortControllerRef.current["delete"](filename);
            });
            _context10.next = 26;
            break;
          case 21:
            uploadAbortControllerRef.current.set(filename, client.createAbortControllerForNextRequest());
            _context10.next = 24;
            return channel.sendImage(file.uri, filename, contentType);
          case 24:
            response = _context10.sent;
            uploadAbortControllerRef.current["delete"](filename);
          case 26:
            if (Object.keys(response).length) {
              newImageUploads = getUploadSetStateAction(id, _utils2.FileState.UPLOADED, {
                height: file.height,
                url: response.file,
                width: file.width
              });
              setImageUploads(newImageUploads);
            }
            _context10.next = 35;
            break;
          case 29:
            _context10.prev = 29;
            _context10.t0 = _context10["catch"](7);
            if (!(_context10.t0 instanceof Error && (_context10.t0.name === 'AbortError' || _context10.t0.name === 'CanceledError'))) {
              _context10.next = 34;
              break;
            }
            uploadAbortControllerRef.current["delete"](filename);
            return _context10.abrupt("return");
          case 34:
            handleFileOrImageUploadError(_context10.t0, true, id);
          case 35:
          case "end":
            return _context10.stop();
        }
      }, _callee9, null, [[7, 29]]);
    }));
    return function (_x5) {
      return _ref13.apply(this, arguments);
    };
  }());
  var uploadNewFile = useStableCallback(function () {
    var _ref15 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee10(file, fileType) {
      var id, fileConfig, size_limit, isAllowed, sizeLimit, fileState, derivedFileType, newFile;
      return _regenerator["default"].wrap(function _callee10$(_context11) {
        while (1) switch (_context11.prev = _context11.next) {
          case 0:
            _context11.prev = 0;
            id = (0, _utils2.generateRandomId)();
            fileConfig = getFileUploadConfig();
            size_limit = fileConfig.size_limit;
            isAllowed = (0, _utils.isUploadAllowed)({
              config: fileConfig,
              file: file
            });
            sizeLimit = size_limit || _utils.MAX_FILE_SIZE_TO_UPLOAD;
            if (!(file.size && file.size > sizeLimit)) {
              _context11.next = 10;
              break;
            }
            _reactNative.Alert.alert(t('File is too large: {{ size }}, maximum upload size is {{ limit }}', {
              limit: (0, _utils.prettifyFileSize)(sizeLimit),
              size: (0, _utils.prettifyFileSize)(file.size)
            }));
            setSelectedFiles(selectedFiles.filter(function (selectedFile) {
              return selectedFile.uri !== file.uri;
            }));
            return _context11.abrupt("return");
          case 10:
            fileState = isAllowed ? _utils2.FileState.UPLOADING : _utils2.FileState.NOT_SUPPORTED;
            derivedFileType = fileType != null ? fileType : (0, _utils2.getFileTypeFromMimeType)(file.type);
            newFile = {
              duration: file.duration || 0,
              file: file,
              id: id,
              mime_type: file.type,
              state: fileState,
              thumb_url: file.thumb_url,
              type: derivedFileType,
              url: file.uri
            };
            _context11.next = 15;
            return Promise.all([setFileUploads(function (prevFileUploads) {
              return prevFileUploads.concat([newFile]);
            }), setNumberOfUploads(function (prevNumberOfUploads) {
              return prevNumberOfUploads + 1;
            })]);
          case 15:
            if (!isAllowed) {
              _context11.next = 18;
              break;
            }
            _context11.next = 18;
            return uploadFile({
              newFile: newFile
            });
          case 18:
            _context11.next = 23;
            break;
          case 20:
            _context11.prev = 20;
            _context11.t0 = _context11["catch"](0);
            console.log('Error uploading file', _context11.t0);
          case 23:
          case "end":
            return _context11.stop();
        }
      }, _callee10, null, [[0, 20]]);
    }));
    return function (_x6, _x7) {
      return _ref15.apply(this, arguments);
    };
  }());
  var uploadNewImage = useStableCallback(function () {
    var _ref16 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee11(image) {
      var id, imageUploadConfig, size_limit, isAllowed, sizeLimit, imageState, newImage;
      return _regenerator["default"].wrap(function _callee11$(_context12) {
        while (1) switch (_context12.prev = _context12.next) {
          case 0:
            _context12.prev = 0;
            id = (0, _utils2.generateRandomId)();
            imageUploadConfig = getImageUploadConfig();
            size_limit = imageUploadConfig.size_limit;
            isAllowed = (0, _utils.isUploadAllowed)({
              config: imageUploadConfig,
              file: image
            });
            sizeLimit = size_limit || _utils.MAX_FILE_SIZE_TO_UPLOAD;
            if (!(image.size && (image == null ? void 0 : image.size) > sizeLimit)) {
              _context12.next = 10;
              break;
            }
            _reactNative.Alert.alert(t('File is too large: {{ size }}, maximum upload size is {{ limit }}', {
              limit: (0, _utils.prettifyFileSize)(sizeLimit),
              size: (0, _utils.prettifyFileSize)(image.size)
            }));
            setSelectedImages(selectedImages.filter(function (selectedImage) {
              return selectedImage.uri !== image.uri;
            }));
            return _context12.abrupt("return");
          case 10:
            imageState = isAllowed ? _utils2.FileState.UPLOADING : _utils2.FileState.NOT_SUPPORTED;
            newImage = {
              file: image,
              height: image.height,
              id: id,
              mime_type: image.type,
              state: imageState,
              type: _types.FileTypes.Image,
              url: image.uri,
              width: image.width
            };
            _context12.next = 14;
            return Promise.all([setImageUploads(function (prevImageUploads) {
              return prevImageUploads.concat([newImage]);
            }), setNumberOfUploads(function (prevNumberOfUploads) {
              return prevNumberOfUploads + 1;
            })]);
          case 14:
            if (!isAllowed) {
              _context12.next = 17;
              break;
            }
            _context12.next = 17;
            return uploadImage({
              newImage: newImage
            });
          case 17:
            _context12.next = 22;
            break;
          case 19:
            _context12.prev = 19;
            _context12.t0 = _context12["catch"](0);
            console.log('Error uploading image', _context12.t0);
          case 22:
          case "end":
            return _context12.stop();
        }
      }, _callee11, null, [[0, 19]]);
    }));
    return function (_x8) {
      return _ref16.apply(this, arguments);
    };
  }());
  var openPollCreationDialog = useStableCallback(function () {
    if (openPollCreationDialogFromContext) {
      openPollCreationDialogFromContext({
        sendMessage: sendMessage
      });
      return;
    }
    defaultOpenPollCreationDialog();
  });
  var messageInputContext = (0, _useCreateMessageInputContext.useCreateMessageInputContext)(Object.assign({
    appendText: appendText,
    asyncIds: asyncIds,
    asyncUploads: asyncUploads,
    closeAttachmentPicker: closeAttachmentPicker,
    cooldownEndsAt: cooldownEndsAt,
    fileUploads: fileUploads,
    giphyActive: giphyActive,
    giphyEnabled: giphyEnabled,
    imageUploads: imageUploads,
    inputBoxRef: inputBoxRef,
    isValidMessage: isValidMessage,
    mentionedUsers: mentionedUsers,
    numberOfUploads: numberOfUploads,
    onChange: onChange,
    onSelectItem: onSelectItem,
    openAttachmentPicker: openAttachmentPicker,
    openCommandsPicker: openCommandsPicker,
    openFilePicker: pickFile,
    openMentionsPicker: openMentionsPicker,
    pickAndUploadImageFromNativePicker: pickAndUploadImageFromNativePicker,
    pickFile: pickFile,
    removeFile: removeFile,
    removeImage: removeImage,
    resetInput: resetInput,
    selectedPicker: selectedPicker,
    sending: sending,
    sendMessageAsync: sendMessageAsync,
    sendThreadMessageInChannel: sendThreadMessageInChannel,
    setAsyncIds: setAsyncIds,
    setAsyncUploads: setAsyncUploads,
    setFileUploads: setFileUploads,
    setGiphyActive: setGiphyActive,
    setImageUploads: setImageUploads,
    setInputBoxRef: setInputBoxRef,
    setMentionedUsers: setMentionedUsers,
    setNumberOfUploads: setNumberOfUploads,
    setSendThreadMessageInChannel: setSendThreadMessageInChannel,
    setShowMoreOptions: setShowMoreOptions,
    setText: setText,
    showMoreOptions: showMoreOptions,
    takeAndUploadImage: takeAndUploadImage,
    text: text,
    thread: thread,
    toggleAttachmentPicker: toggleAttachmentPicker,
    triggerSettings: triggerSettings,
    updateMessage: updateMessage,
    uploadFile: uploadFile,
    uploadImage: uploadImage,
    uploadNewFile: uploadNewFile,
    uploadNewImage: uploadNewImage
  }, value, {
    closePollCreationDialog: closePollCreationDialog,
    hasText: !!text,
    openPollCreationDialog: openPollCreationDialog,
    sendMessage: sendMessage,
    showPollCreationDialog: showPollCreationDialog,
    StopMessageStreamingButton: StopMessageStreamingButton
  }));
  return (0, _jsxRuntime.jsx)(MessageInputContext.Provider, {
    value: messageInputContext,
    children: children
  });
};
var useMessageInputContext = exports.useMessageInputContext = function useMessageInputContext() {
  var contextValue = (0, _react.useContext)(MessageInputContext);
  if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
    throw new Error('The useMessageInputContext hook was called outside of the MessageInputContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel');
  }
  return contextValue;
};
var useStableCallback = function useStableCallback(callback) {
  var ref = (0, _react.useRef)(callback);
  ref.current = callback;
  return (0, _react.useCallback)(function () {
    return ref.current.apply(ref, arguments);
  }, []);
};
//# sourceMappingURL=MessageInputContext.js.map