import { extractSmartLinkUrl } from '@atlaskit/link-extractors';
import { InternalActionName } 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 _actionOptions$rovoCh;
  if (!canShowAction(CardAction.RovoChatAction, actionOptions)) {
    return;
  }
  const isRovoChatEnabled = 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
  const isSupportedFeature = getExtensionKey(response) === 'google-object-provider';
  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: InternalActionName.RovoChatAction,
      definitionId: getDefinitionId(response),
      display: appearance,
      extensionKey: getExtensionKey(response),
      id,
      resourceType: getResourceType(response)
    },
    product,
    url
  } : undefined;
};
export default extractRovoChatAction;