import { useCallback, useMemo } from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
import { useRovoPostMessageToPubsub } from '@atlaskit/rovo-triggers/post-message-to-pubsub';
import { getIsRovoChatEnabled } from '../../../utils/rovo';
import useRovoConfig from '../use-rovo-config';
import { JIRA_PRODUCTS } from './constants';
const SMART_LINK_TO_ROVO_SOURCE = 'smart-link';
const useRovoChat = () => {
  const {
    rovoOptions: config,
    product
  } = useRovoConfig();
  const {
    publishWithPostMessage
  } = useRovoPostMessageToPubsub();
  const isRovoChatEnabled = getIsRovoChatEnabled(config);
  const isJiraProduct = product && JIRA_PRODUCTS.includes(product);
  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: isJiraProduct && (fg('platform_sl_3p_auth_rovo_block_jira_kill_switch') || fg('rovogrowth-640-inline-action-nudge-fg')) ? 'mini-modal' : 'sidebar'
      },
      onAcknowledgeTimeout: () => {
        // NAVX-3599: Add analytics event
      }
    });
  }, [publishWithPostMessage, isJiraProduct]);
  return useMemo(() => ({
    isRovoChatEnabled,
    sendPromptMessage
  }), [isRovoChatEnabled, sendPromptMessage]);
};
export default useRovoChat;