"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _postMessageToPubsub = require("@atlaskit/rovo-triggers/post-message-to-pubsub");
var _rovo = require("../../../utils/rovo");
var _useRovoConfig2 = _interopRequireDefault(require("../use-rovo-config"));
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var SMART_LINK_TO_ROVO_SOURCE = 'smart-link';
var useRovoChat = function useRovoChat() {
  var _useRovoConfig = (0, _useRovoConfig2.default)(),
    config = _useRovoConfig.rovoOptions,
    product = _useRovoConfig.product;
  var _useRovoPostMessageTo = (0, _postMessageToPubsub.useRovoPostMessageToPubsub)(),
    publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage;
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(config);
  var sendPromptMessage = (0, _react.useCallback)(function (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: _objectSpread(_objectSpread({
          dialogues: []
        }, data), {}, {
          agentId: undefined
        }),
        openChat: true,
        openChatMode: product && _constants.JIRA_PRODUCTS.includes(product) && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_jira_kill_switch') || (0, _platformFeatureFlags.fg)('rovogrowth-640-inline-action-nudge-fg') ? 'mini-modal' : 'sidebar'
      },
      onAcknowledgeTimeout: function onAcknowledgeTimeout() {
        // NAVX-3599: Add analytics event
      }
    });
  }, [publishWithPostMessage, product]);
  return (0, _react.useMemo)(function () {
    return {
      isRovoChatEnabled: isRovoChatEnabled,
      sendPromptMessage: sendPromptMessage
    };
  }, [isRovoChatEnabled, sendPromptMessage]);
};
var _default = exports.default = useRovoChat;