"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useBlockCardRovoActionExperimentNoExposure = exports.isBlockCardRovoActionExperimentEnabled = exports.default = void 0;
var _react = require("react");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
var _rovo = require("../../../utils/rovo");
var _helpers = require("../../helpers");
var _store = require("../../store");
var _constants = require("../use-rovo-chat/constants");
var _useRovoConfig3 = _interopRequireDefault(require("../use-rovo-config"));
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 NOT_ENABLED_RESULT = {
  isEnabled: false
};

/**
 * Returns whether the platform_sl_3p_auth_rovo_block_card_jira or platform_sl_3p_auth_rovo_block_card_confluence 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 be one of the supported options.
 * 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 useBlockCardRovoActionExperiment = function useBlockCardRovoActionExperiment(url, actionOptions) {
  var _actionOptions$rovoCh, _actionOptions$rovoCh2;
  var _useRovoConfig = (0, _useRovoConfig3.default)(),
    rovoConfig = _useRovoConfig.rovoOptions,
    product = _useRovoConfig.product;
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(rovoConfig);
  var cardState = (0, _store.useSmartCardState)(url !== null && url !== void 0 ? url : '');
  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 || !url || !isRovoChatActionOptedIn) {
      return NOT_ENABLED_RESULT;
    }
    if (extensionKey && !ELIGIBLE_EXTENSION_KEYS.has(extensionKey)) {
      return NOT_ENABLED_RESULT;
    }
    var isJiraEnabled = !!product && _constants.JIRA_PRODUCTS.includes(product) && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_jira_kill_switch') && (0, _expValEquals.expValEquals)('platform_sl_3p_auth_rovo_block_card_jira', 'isEnabled', true);
    var isConfluenceEnabled = !!product && product === 'CONFLUENCE' && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_card_kill_switch') && (0, _expValEquals.expValEquals)('platform_sl_3p_auth_rovo_block_card_confluence', 'isEnabled', true);
    return {
      isEnabled: isJiraEnabled || isConfluenceEnabled
    };
  }, [isRovoChatEnabled, extensionKey, url, isRovoChatActionOptedIn, product]);
};
var isBlockCardRovoActionExperimentEnabled = exports.isBlockCardRovoActionExperimentEnabled = function isBlockCardRovoActionExperimentEnabled(product) {
  var isJiraEnabled = !!product && _constants.JIRA_PRODUCTS.includes(product) && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_jira_kill_switch') && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_sl_3p_auth_rovo_block_card_jira', 'isEnabled', true);
  var isConfluenceEnabled = !!product && product === 'CONFLUENCE' && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_card_kill_switch') && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_sl_3p_auth_rovo_block_card_confluence', 'isEnabled', true);
  return isJiraEnabled || isConfluenceEnabled;
};
var useBlockCardRovoActionExperimentNoExposure = exports.useBlockCardRovoActionExperimentNoExposure = function useBlockCardRovoActionExperimentNoExposure() {
  var _useRovoConfig2 = (0, _useRovoConfig3.default)(),
    product = _useRovoConfig2.product;
  return isBlockCardRovoActionExperimentEnabled(product);
};
var _default = exports.default = useBlockCardRovoActionExperiment;