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';
const extractRovoChatAction = ({
  actionOptions,
  appearance,
  id,
  product,
  response,
  rovoConfig
}) => {
  var _response$meta, _response$meta$suppor, _actionOptions$rovoCh;
  if (!canShowAction(CardAction.RovoChatAction, actionOptions)) {
    return;
  }
  const isRovoChatEnabled = getIsRovoChatEnabled(rovoConfig);
  if (!isRovoChatEnabled) {
    return;
  }
  const supportsRovoActions = response === null || response === void 0 ? void 0 : (_response$meta = response.meta) === null || _response$meta === void 0 ? void 0 : (_response$meta$suppor = _response$meta.supportedFeature) === null || _response$meta$suppor === void 0 ? void 0 : _response$meta$suppor.includes('RovoActions');
  const isGoogleProvider = getExtensionKey(response) === 'google-object-provider';
  const is3PAuthRovoActionEnabled = isGoogleProvider && fg('platform_sl_3p_auth_rovo_action_kill_switch');
  const is3PInlinePostAuthActionsEnabled = supportsRovoActions && !isGoogleProvider && fg('rovogrowth-640-inline-action-nudge-fg') && expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
  const is3PBlockPostAuthActionsEnabled = supportsRovoActions && fg('platform_sl_3p_auth_rovo_block_card_kill_switch');
  const isSupportedFeature = is3PInlinePostAuthActionsEnabled || is3PAuthRovoActionEnabled || is3PBlockPostAuthActionsEnabled;
  const isOptIn = (actionOptions === null || actionOptions === void 0 ? void 0 : (_actionOptions$rovoCh = actionOptions.rovoChatAction) === null || _actionOptions$rovoCh === void 0 ? void 0 : _actionOptions$rovoCh.optIn) === true;
  const url = extractSmartLinkUrl(response);
  return isSupportedFeature && isOptIn ? {
    invokeAction: {
      actionSubjectId: 'rovoChatPrompt',
      actionType: ActionName.RovoChatAction,
      definitionId: getDefinitionId(response),
      display: appearance,
      extensionKey: getExtensionKey(response),
      id,
      resourceType: getResourceType(response)
    },
    product,
    url
  } : undefined;
};
export default extractRovoChatAction;