"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
var _useSocialProof2 = _interopRequireDefault(require("../use-social-proof"));
var TIER_THRESHOLD = 30;

/**
 * Returns enrollment and treatment state for the social proof unauth block card experiment.
 *
 * Delegates data-fetching to `useSocialProof` (Sasha's shared service layer),
 * which handles cloudId resolution, TAP trait fetch, localStorage caching,
 * request deduping, and sync reads.
 *
 * This hook adds the experiment/cohort layer on top:
 * - Only fires exposure (via editorExperiment) when data has loaded.
 * - Derives `tier` and `isTreatment` for rendering decisions.
 *
 * Expected to be called only inside the fg-enabled branch (via componentWithFG).
 *
 * @param extensionKey - The extensionKey of the current 3P provider (e.g. 'google-object-provider').
 */
var useSocialProofExperiment = function useSocialProofExperiment(extensionKey) {
  var baseUriWithNoTrailingSlash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  var _useSocialProof = (0, _useSocialProof2.default)(extensionKey, true, baseUriWithNoTrailingSlash),
    connectedPct = _useSocialProof.connectedPct,
    isEnabled = _useSocialProof.isEnabled,
    isLoading = _useSocialProof.isLoading;
  return (0, _react.useMemo)(function () {
    var hasSocialProofData = connectedPct !== undefined;

    // Only fire exposure when data has loaded (prevents exposure inflation)
    var isTreatment = isEnabled && !isLoading && hasSocialProofData ? (0, _experiments.editorExperiment)('social_proof_3p_unauth_block_exp', true) : false;
    var tier = connectedPct !== undefined && connectedPct >= TIER_THRESHOLD ? 'not-low' : 'low';
    return {
      isTreatment: isTreatment,
      tier: tier,
      connectedPct: connectedPct,
      isLoading: isLoading
    };
  }, [isEnabled, isLoading, connectedPct]);
};
var _default = exports.default = useSocialProofExperiment;