"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getVariant = void 0;
var _dataSources = require("@mirai/data-sources");
var _Core = require("../Core.constants");
var _process, _process$env;
const IS_JEST = !!((_process = process) !== null && _process !== void 0 && (_process$env = _process.env) !== null && _process$env !== void 0 && _process$env.JEST_WORKER_ID);
const variantStorage = new _dataSources.Storage({
  adapter: _dataSources.SessionAdapter
});
const {
  A,
  B
} = _Core.VARIANT;
const getVariant = function () {
  let {
    urlParams = {}
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (IS_JEST && !window.IS_PLAYWRIGHT) return undefined;
  if (urlParams.variant === A || urlParams.variant === B) {
    return urlParams.variant;
  }
  const stored = variantStorage.get(_Core.VARIANT_STORAGE_KEY);
  if (stored === A || stored === B) return stored;
  const next = Math.random() < 0.5 ? A : B;
  variantStorage.set(_Core.VARIANT_STORAGE_KEY, next);
  return next;
};
exports.getVariant = getVariant;
//# sourceMappingURL=getVariant.js.map