import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { useMemo } from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
import { getIsRovoChatEnabled } from '../../../utils/rovo';
import { getExtensionKey } from '../../helpers';
import { useSmartCardState } from '../../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);
};
export var EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY = 'platform_sl_3p_auth_rovo_embed_footer_exp';
var NOT_ENABLED_RESULT = {
  isEnabled: false
};
export var isEmbedRovoActionsFooterExperimentEnabled = function isEmbedRovoActionsFooterExperimentEnabled(product) {
  return product === 'CONFLUENCE' && fg('platform_sl_3p_auth_rovo_embed_footer_kill_switch') && expValEquals(EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY, 'isEnabled', true);
};
var isEmbedRovoActionsFooterKillSwitchEnabled = function isEmbedRovoActionsFooterKillSwitchEnabled(product) {
  return product === 'CONFLUENCE' && fg('platform_sl_3p_auth_rovo_embed_footer_kill_switch');
};
var isEmbedRovoActionsFooterExperimentEnabledNoExposure = function isEmbedRovoActionsFooterExperimentEnabledNoExposure(product) {
  return isEmbedRovoActionsFooterKillSwitchEnabled(product) && expValEqualsNoExposure(EMBED_ROVO_ACTIONS_FOOTER_EXPERIMENT_KEY, 'isEnabled', true);
};
export var 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 _defineProperty({}, 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 = getIsRovoChatEnabled(rovoOptions);
  var cardState = useSmartCardState(url !== null && url !== void 0 ? url : '');
  var extensionKey = 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 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]);
};
export default useEmbedRovoActionsFooterExperiment;