import { extractSmartLinkUrl } from '@atlaskit/link-extractors';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
import { ActionName } from '../../../constants';
import { getDefinitionId, getExtensionKey, getResourceType } from '../../../state/helpers';
import { canShowAction } from '../../../utils/actions/can-show-action';
import { getIsRovoChatEnabled } from '../../../utils/rovo';
import { CardAction } from '../../../view/Card/types';
// 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 _actionOptions$rovoCh;
  var actionOptions = _ref.actionOptions,
    appearance = _ref.appearance,
    id = _ref.id,
    product = _ref.product,
    response = _ref.response,
    rovoConfig = _ref.rovoConfig;
  if (!canShowAction(CardAction.RovoChatAction, actionOptions)) {
    return;
  }
  var isRovoChatEnabled = getIsRovoChatEnabled(rovoConfig === null || rovoConfig === void 0 ? void 0 : rovoConfig.rovoOptions);
  if (!isRovoChatEnabled) {
    return;
  }
  var extensionKey = getExtensionKey(response);
  var isGoogleProvider = extensionKey === 'google-object-provider';
  var is3PAuthRovoActionEnabled = isGoogleProvider && fg('platform_sl_3p_auth_rovo_action_kill_switch');
  var is3PInlinePostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && fg('rovogrowth-640-inline-action-nudge-fg') && expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
  var is3PBlockPostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && fg('platform_sl_3p_auth_rovo_block_card_kill_switch');
  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 = extractSmartLinkUrl(response);
  return isSupportedFeature && isOptIn ? {
    invokeAction: {
      actionSubjectId: 'rovoChatPrompt',
      actionType: ActionName.RovoChatAction,
      definitionId: getDefinitionId(response),
      display: appearance,
      extensionKey: extensionKey,
      id: id,
      resourceType: getResourceType(response)
    },
    product: product,
    url: url
  } : undefined;
};
export default extractRovoChatAction;