"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isEmbedRovoActionsFooterExperimentEnabled = exports.getEmbedRovoActionsFooterExperimentMeta = exports.default = exports.EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
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 EMBED_ROVO_ACTIONS_FOOTER_ELIGIBLE_EXTENSION_KEYS = new Set(['google-object-provider', 'onedrive-object-provider', 'github-object-provider', 'gitlab-object-provider']);
var isEligibleEmbedRovoActionsFooterExtensionKey = function isEligibleEmbedRovoActionsFooterExtensionKey(extensionKey) {
  return extensionKey !== undefined && EMBED_ROVO_ACTIONS_FOOTER_ELIGIBLE_EXTENSION_KEYS.has(extensionKey);
};
var EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY = exports.EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY = 'platform_sl_3p_auth_rovo_embed_footer_exp';
var NOT_ENABLED_RESULT = {
  isEnabled: false
};
var isEmbedRovoActionsFooterExperimentEnabled = exports.isEmbedRovoActionsFooterExperimentEnabled = function isEmbedRovoActionsFooterExperimentEnabled(product) {
  return product === 'CONFLUENCE' && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_embed_footer_kill_switch') && (0, _expValEquals.expValEquals)(EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY, 'isEnabled', true);
};
var isEmbedRovoActionsFooterKillSwitchEnabled = function isEmbedRovoActionsFooterKillSwitchEnabled(product) {
  return product === 'CONFLUENCE' && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_embed_footer_kill_switch');
};
var isEmbedRovoActionsFooterExperimentEnabledNoExposure = function isEmbedRovoActionsFooterExperimentEnabledNoExposure(product) {
  return isEmbedRovoActionsFooterKillSwitchEnabled(product) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)(EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY, 'isEnabled', true);
};
var getEmbedRovoActionsFooterExperimentMeta = exports.getEmbedRovoActionsFooterExperimentMeta = function getEmbedRovoActionsFooterExperimentMeta(_ref) {
  var extensionKey = _ref.extensionKey,
    isRovoChatActionOptedIn = _ref.isRovoChatActionOptedIn,
    isRovoChatEnabled = _ref.isRovoChatEnabled,
    product = _ref.product;
  var isEligible = isEmbedRovoActionsFooterKillSwitchEnabled(product) && isRovoChatEnabled && isRovoChatActionOptedIn && isEligibleEmbedRovoActionsFooterExtensionKey(extensionKey);
  if (!isEligible) {
    return undefined;
  }
  return (0, _defineProperty2.default)({}, EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY, {
    isEligible: true,
    isTreatment: isEmbedRovoActionsFooterExperimentEnabledNoExposure(product)
  });
};
var useEmbedRovoActionsFooterExperiment = function useEmbedRovoActionsFooterExperiment(url, actionOptions, rovoOptions, product) {
  var _actionOptions$rovoCh, _actionOptions$rovoCh2;
  var isRovoChatEnabled = (0, _rovo.getIsRovoChatEnabled)(rovoOptions);
  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 || !extensionKey) {
      return NOT_ENABLED_RESULT;
    }
    if (!isEligibleEmbedRovoActionsFooterExtensionKey(extensionKey)) {
      return NOT_ENABLED_RESULT;
    }
    return {
      isEnabled: isEmbedRovoActionsFooterExperimentEnabled(product)
    };
  }, [isRovoChatEnabled, extensionKey, url, isRovoChatActionOptedIn, product]);
};
var _default = exports.default = useEmbedRovoActionsFooterExperiment;