"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _xmppProvider = require("../context/xmppProvider");
var _reactRedux = require("react-redux");
var _useChatSettingState = require("./useChatSettingState");
const useComposing = config => {
  const {
    client
  } = (0, _xmppProvider.useXmppClient)();
  const {
    activeRoomJID
  } = (0, _reactRedux.useSelector)(state => state.rooms);
  const {
    user
  } = (0, _useChatSettingState.useChatSettingState)();
  const sendStartComposing = (0, _react.useCallback)(() => {
    if (config?.disableTypingIndicator) {
      return;
    }
    if (client) {
      client.sendTypingRequestStanza(activeRoomJID || '', `${user.firstName} ${user.lastName}`, true);
    }
  }, [activeRoomJID, client, config?.disableTypingIndicator, user.firstName, user.lastName]);
  const sendEndComposing = (0, _react.useCallback)(() => {
    if (config?.disableTypingIndicator) {
      return;
    }
    if (client) {
      client.sendTypingRequestStanza(activeRoomJID || '', `${user.firstName} ${user.lastName}`, false);
    }
  }, [activeRoomJID, client, config?.disableTypingIndicator, user.firstName, user.lastName]);
  (0, _react.useEffect)(() => {
    const timerId = setTimeout(() => {
      sendEndComposing();
    }, 100);
    return () => clearTimeout(timerId);
  }, [sendEndComposing]);
  return {
    sendStartComposing,
    sendEndComposing
  };
};
var _default = exports.default = useComposing;
//# sourceMappingURL=useComposing.js.map