import { useCallback, useMemo } from 'react';
import { useRovoPostMessageToPubsub } from '@atlaskit/rovo-triggers/post-message-to-pubsub';
import { getIsRovoChatEnabled } from '../../../utils/rovo';
import useRovoConfig from '../use-rovo-config';
const SMART_LINK_TO_ROVO_SOURCE = 'smart-link';
const useRovoChat = () => {
  const {
    rovoOptions: config
  } = useRovoConfig();
  const {
    publishWithPostMessage
  } = useRovoPostMessageToPubsub();
  const isRovoChatEnabled = getIsRovoChatEnabled(config);
  const sendPromptMessage = useCallback(data => {
    var _window$parent;
    publishWithPostMessage({
      targetWindow: (_window$parent = window.parent) !== null && _window$parent !== void 0 ? _window$parent : window,
      payload: {
        type: 'chat-new',
        source: SMART_LINK_TO_ROVO_SOURCE,
        data: {
          dialogues: [],
          ...data,
          agentId: undefined
        },
        openChat: true,
        openChatMode: 'sidebar'
      },
      onAcknowledgeTimeout: () => {
        // NAVX-3599: Add analytics event
      }
    });
  }, [publishWithPostMessage]);
  return useMemo(() => ({
    isRovoChatEnabled,
    sendPromptMessage
  }), [isRovoChatEnabled, sendPromptMessage]);
};
export default useRovoChat;