"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _rovo = require("../../../utils/rovo");
var _helpers = require("../../helpers");
var _store = require("../../store");
var _useRovoConfig = _interopRequireDefault(require("../use-rovo-config"));
var EXCLUDED_EXTENSION_KEYS = new Set(['figma-object-provider', 'google-object-provider']);
var NOT_ENABLED_RESULT = {
  isEnabled: false
};

/**
 * Returns whether the rovogrowth-640-inline-action-nudge-exp experiment
 * is enabled for the current user and link context.
 *
 * All eligibility criteria are consolidated here:
 * 1. Rovo chat must be enabled for the tenant.
 * 2. The consumer must have opted in via actionOptions.rovoChatAction.optIn.
 * 3. The link must support the RovoActions feature.
 * 4. The extension key must not be excluded (Figma and Google links are excluded).
 * 5. The experiment value must be true (via tmp-editor-statsig).
 *
 * The extension key is derived from the card store via the resolved URL,
 * so callers don't need to thread it as a prop.
 */
var useInlineActionNudgeExperiment = function useInlineActionNudgeExperiment(url, showHoverPreview, actionOptions) {
  var _cardState$details$me, _cardState$details, _actionOptions$rovoCh, _actionOptions$rovoCh2;
  var rovoConfig = (0, _useRovoConfig.default)();
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(rovoConfig);
  var cardState = (0, _store.useSmartCardState)(url !== null && url !== void 0 ? url : '');
  var supportsRovoActions = (_cardState$details$me = cardState === null || cardState === void 0 || (_cardState$details = cardState.details) === null || _cardState$details === void 0 || (_cardState$details = _cardState$details.meta) === null || _cardState$details === void 0 || (_cardState$details = _cardState$details.supportedFeature) === null || _cardState$details === void 0 ? void 0 : _cardState$details.includes('RovoActions')) !== null && _cardState$details$me !== void 0 ? _cardState$details$me : false;
  var extensionKey = (0, _helpers.getExtensionKey)(cardState.details);
  var isRovoChatActionOptedIn = (_actionOptions$rovoCh = actionOptions === null || actionOptions === void 0 || (_actionOptions$rovoCh2 = actionOptions.rovoChatAction) === null || _actionOptions$rovoCh2 === void 0 ? void 0 : _actionOptions$rovoCh2.optIn) !== null && _actionOptions$rovoCh !== void 0 ? _actionOptions$rovoCh : false;
  return (0, _react.useMemo)(function () {
    if (!isRovoChatEnabled || !showHoverPreview || !supportsRovoActions || !url || !isRovoChatActionOptedIn) {
      return NOT_ENABLED_RESULT;
    }
    if (extensionKey && EXCLUDED_EXTENSION_KEYS.has(extensionKey)) {
      return NOT_ENABLED_RESULT;
    }
    var isEnabled = (0, _expValEquals.expValEquals)('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
    return {
      isEnabled: isEnabled
    };
  }, [isRovoChatEnabled, extensionKey, showHoverPreview, supportsRovoActions, url, isRovoChatActionOptedIn]);
};
var _default = exports.default = useInlineActionNudgeExperiment;