import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["onClick", "prompts", "testId"];
import React, { useCallback, useMemo } from 'react';
import RovoChatIcon from '@atlaskit/icon/core/rovo-chat';
import useRovoChat from '../../../../../state/hooks/use-rovo-chat';
import Action from '../action';
// Replace this with actual message key, e.g. link-relevancy, link-summary, etc.
export var 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.createElement(RovoChatIcon, {
          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.createElement(RovoChatIcon, {
          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 = _objectWithoutProperties(_ref, _excluded);
  var _useRovoChat = useRovoChat(),
    isRovoChatEnabled = _useRovoChat.isRovoChatEnabled,
    sendPromptMessage = _useRovoChat.sendPromptMessage;
  var _onClick = 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 = 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.createElement(Action, _extends({
        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.createElement(React.Fragment, null, promptActions) : null;
};
export default RovoChatAction;