"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _linkExtractors = require("@atlaskit/link-extractors");
var _constants = require("../../../constants");
var _helpers = require("../../../state/helpers");
var _canShowAction = require("../../../utils/actions/can-show-action");
var _rovo = require("../../../utils/rovo");
var _types = require("../../../view/Card/types");
var extractRovoChatAction = function extractRovoChatAction(_ref) {
  var _actionOptions$rovoCh;
  var actionOptions = _ref.actionOptions,
    appearance = _ref.appearance,
    id = _ref.id,
    product = _ref.product,
    response = _ref.response,
    rovoConfig = _ref.rovoConfig;
  if (!(0, _canShowAction.canShowAction)(_types.CardAction.RovoChatAction, actionOptions)) {
    return;
  }
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(rovoConfig);
  if (!isRovoChatEnabled) {
    return;
  }

  // Experiment cleanup note: platform_sl_3p_auth_rovo_action
  // If feature isn't support all 3P, this value should come from meta.supportedFeature
  var isSupportedFeature = (0, _helpers.getExtensionKey)(response) === 'google-object-provider';
  var isOptIn = (actionOptions === null || actionOptions === void 0 || (_actionOptions$rovoCh = actionOptions.rovoChatAction) === null || _actionOptions$rovoCh === void 0 ? void 0 : _actionOptions$rovoCh.optIn) === true;
  var url = (0, _linkExtractors.extractSmartLinkUrl)(response);
  return isSupportedFeature && isOptIn ? {
    invokeAction: {
      actionSubjectId: 'rovoChatPrompt',
      actionType: _constants.InternalActionName.RovoChatAction,
      definitionId: (0, _helpers.getDefinitionId)(response),
      display: appearance,
      extensionKey: (0, _helpers.getExtensionKey)(response),
      id: id,
      resourceType: (0, _helpers.getResourceType)(response)
    },
    product: product,
    url: url
  } : undefined;
};
var _default = exports.default = extractRovoChatAction;