"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.RovoChatPromptKey = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _rovoChat = _interopRequireDefault(require("@atlaskit/icon/core/rovo-chat"));
var _useRovoChat2 = _interopRequireDefault(require("../../../../../state/hooks/use-rovo-chat"));
var _action = _interopRequireDefault(require("../action"));
var _excluded = ["onClick", "prompts", "testId"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
// Replace this with actual message key, e.g. link-relevancy, link-summary, etc.
var RovoChatPromptKey = exports.RovoChatPromptKey = /*#__PURE__*/function (RovoChatPromptKey) {
  RovoChatPromptKey["MESSAGE_1"] = "message-1";
  RovoChatPromptKey["MESSAGE_2"] = "message-2";
  return RovoChatPromptKey;
}({});
var DEFAULT_PROMPTS = [RovoChatPromptKey.MESSAGE_1, RovoChatPromptKey.MESSAGE_2];
var getPromptAction = function getPromptAction(promptKey) {
  // NAVX-3581: Replace this with real prompt message
  switch (promptKey) {
    case RovoChatPromptKey.MESSAGE_1:
      return {
        icon: /*#__PURE__*/_react.default.createElement(_rovoChat.default, {
          label: "",
          spacing: "spacious"
        }),
        content: 'Action title 1',
        tooltipMessage: 'Action tooltip 1',
        data: {
          name: 'Chat title 1',
          dialogues: [],
          prompt: {
            version: 1,
            type: 'doc',
            content: []
          }
        }
      };
    case RovoChatPromptKey.MESSAGE_2:
      return {
        icon: /*#__PURE__*/_react.default.createElement(_rovoChat.default, {
          label: "",
          spacing: "spacious"
        }),
        content: 'Action title 2',
        tooltipMessage: 'Action tooltip 2',
        data: {
          name: 'Chat title 2',
          dialogues: [],
          prompt: {
            version: 1,
            type: 'doc',
            content: []
          }
        }
      };
  }
};
var RovoChatAction = function RovoChatAction(_ref) {
  var onClickCallback = _ref.onClick,
    _ref$prompts = _ref.prompts,
    prompts = _ref$prompts === void 0 ? DEFAULT_PROMPTS : _ref$prompts,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-action-rovo-chat-action' : _ref$testId,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useRovoChat = (0, _useRovoChat2.default)(),
    isRovoChatEnabled = _useRovoChat.isRovoChatEnabled,
    sendPromptMessage = _useRovoChat.sendPromptMessage;
  var _onClick = (0, _react.useCallback)(function (promptData) {
    if (promptData) {
      sendPromptMessage(promptData);

      // NAVX-3599: Add analytics event, possibly as useInvokeClientAction()

      onClickCallback === null || onClickCallback === void 0 || onClickCallback();
    }
  }, [onClickCallback, sendPromptMessage]);
  var promptActions = (0, _react.useMemo)(function () {
    return prompts.map(function (promptKey, idx) {
      var _ref2 = getPromptAction(promptKey) || {},
        icon = _ref2.icon,
        content = _ref2.content,
        tooltipMessage = _ref2.tooltipMessage,
        promptData = _ref2.data;
      return promptData ? /*#__PURE__*/_react.default.createElement(_action.default, (0, _extends2.default)({
        content: content,
        icon: icon,
        key: promptKey,
        onClick: function onClick() {
          return _onClick(promptData);
        },
        testId: "".concat(testId, "-").concat(idx + 1),
        tooltipMessage: tooltipMessage
      }, props)) : null;
    });
  }, [_onClick, prompts, props, testId]);
  return isRovoChatEnabled && (promptActions === null || promptActions === void 0 ? void 0 : promptActions.length) > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, promptActions) : null;
};
var _default = exports.default = RovoChatAction;