"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _linkExtractors = require("@atlaskit/link-extractors");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
var _constants = require("../../../constants");
var _helpers = require("../../../state/helpers");
var _useBlockCardRovoActionExperiment = require("../../../state/hooks/use-block-card-rovo-action-experiment");
var _canShowAction = require("../../../utils/actions/can-show-action");
var _rovo = require("../../../utils/rovo");
// For rovogrowth-640 post auth inline experiment and block card experiment (NAVX-4814)
var ELIGIBLE_EXTENSION_KEYS = new Set(['slack-object-provider', 'google-object-provider', 'onedrive-object-provider', 'github-object-provider', 'ms-teams-object-provider', 'gitlab-object-provider', 'salesforce-object-provider']);
var extractRovoChatAction = function extractRovoChatAction(_ref) {
  var _rovoConfig$product, _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)(_constants.CardAction.RovoChatAction, actionOptions)) {
    return;
  }
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(rovoConfig === null || rovoConfig === void 0 ? void 0 : rovoConfig.rovoOptions);
  if (!isRovoChatEnabled) {
    return;
  }
  var extensionKey = (0, _helpers.getExtensionKey)(response);
  var isGoogleProvider = extensionKey === 'google-object-provider';
  var is3PBlockExperimentEnabled = (0, _useBlockCardRovoActionExperiment.isBlockCardRovoActionExperimentEnabled)((_rovoConfig$product = rovoConfig === null || rovoConfig === void 0 ? void 0 : rovoConfig.product) !== null && _rovoConfig$product !== void 0 ? _rovoConfig$product : product);
  var is3PAuthRovoActionEnabled = isGoogleProvider && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_action_kill_switch');
  var is3PInlinePostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && (0, _platformFeatureFlags.fg)('rovogrowth-640-inline-action-nudge-fg') && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
  var is3PBlockPostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && is3PBlockExperimentEnabled;
  var isSupportedFeature = is3PInlinePostAuthActionsEnabled || is3PAuthRovoActionEnabled || is3PBlockPostAuthActionsEnabled;
  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.ActionName.RovoChatAction,
      definitionId: (0, _helpers.getDefinitionId)(response),
      display: appearance,
      extensionKey: extensionKey,
      id: id,
      resourceType: (0, _helpers.getResourceType)(response)
    },
    product: product,
    url: url
  } : undefined;
};
var _default = exports.default = extractRovoChatAction;