"use strict";

import { useCallback, useEffect } from 'react';
import { useXmppClient } from '../context/xmppProvider';
import { useSelector } from 'react-redux';
import { useChatSettingState } from './useChatSettingState';
const useComposing = config => {
  const {
    client
  } = useXmppClient();
  const {
    activeRoomJID
  } = useSelector(state => state.rooms);
  const {
    user
  } = useChatSettingState();
  const sendStartComposing = 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 = useCallback(() => {
    if (config?.disableTypingIndicator) {
      return;
    }
    if (client) {
      client.sendTypingRequestStanza(activeRoomJID || '', `${user.firstName} ${user.lastName}`, false);
    }
  }, [activeRoomJID, client, config?.disableTypingIndicator, user.firstName, user.lastName]);
  useEffect(() => {
    const timerId = setTimeout(() => {
      sendEndComposing();
    }, 100);
    return () => clearTimeout(timerId);
  }, [sendEndComposing]);
  return {
    sendStartComposing,
    sendEndComposing
  };
};
export default useComposing;
//# sourceMappingURL=useComposing.js.map