import { useMemo } from 'react';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { getIsRovoChatEnabled } from '../../../utils/rovo';
import { getExtensionKey } from '../../helpers';
import { useSmartCardState } from '../../store';
import useRovoConfig from '../use-rovo-config';
const 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']);
const 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 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.
 */
const useInlineActionNudgeExperiment = (url, showHoverPreview, actionOptions) => {
  var _actionOptions$rovoCh, _actionOptions$rovoCh2;
  const {
    rovoOptions: rovoConfig
  } = useRovoConfig();
  const isRovoChatEnabled = getIsRovoChatEnabled(rovoConfig);
  const cardState = useSmartCardState(url !== null && url !== void 0 ? url : '');
  const extensionKey = getExtensionKey(cardState.details);
  const isRovoChatActionOptedIn = (_actionOptions$rovoCh = actionOptions === null || actionOptions === void 0 ? 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(() => {
    if (!isRovoChatEnabled || !showHoverPreview || !url || !isRovoChatActionOptedIn) {
      return NOT_ENABLED_RESULT;
    }
    if (!extensionKey || !ELIGIBLE_EXTENSION_KEYS.has(extensionKey)) {
      return NOT_ENABLED_RESULT;
    }
    const isEnabled = expValEquals('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
    return {
      isEnabled
    };
  }, [isRovoChatEnabled, extensionKey, showHoverPreview, url, isRovoChatActionOptedIn]);
};
export default useInlineActionNudgeExperiment;