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 EXCLUDED_EXTENSION_KEYS = new Set(['figma-object-provider', 'google-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 extension key must not be excluded (Figma and Google links are excluded).
 * 3. 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) => {
  var _cardState$details$me, _cardState$details, _cardState$details$me2, _cardState$details$me3;
  const rovoConfig = useRovoConfig();
  const isRovoChatEnabled = getIsRovoChatEnabled(rovoConfig);
  const cardState = useSmartCardState(url !== null && url !== void 0 ? url : '');
  const supportsRovoActions = (_cardState$details$me = cardState === null || cardState === void 0 ? void 0 : (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : (_cardState$details$me2 = _cardState$details.meta) === null || _cardState$details$me2 === void 0 ? void 0 : (_cardState$details$me3 = _cardState$details$me2.supportedFeature) === null || _cardState$details$me3 === void 0 ? void 0 : _cardState$details$me3.includes('RovoActions')) !== null && _cardState$details$me !== void 0 ? _cardState$details$me : false;
  const extensionKey = getExtensionKey(cardState.details);
  return useMemo(() => {
    if (!isRovoChatEnabled || !showHoverPreview || !supportsRovoActions || !url) {
      return NOT_ENABLED_RESULT;
    }
    if (extensionKey && EXCLUDED_EXTENSION_KEYS.has(extensionKey)) {
      return NOT_ENABLED_RESULT;
    }
    const isEnabled = expValEquals('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
    return {
      isEnabled
    };
  }, [isRovoChatEnabled, extensionKey, showHoverPreview, supportsRovoActions, url]);
};
export default useInlineActionNudgeExperiment;