"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.sheet = exports.prefix = exports.merge = exports.memoizeStyle = exports.keyframes = exports.injectGlobal = exports.hydrate = exports.getRegisteredStyles = exports.flush = exports.cx = exports.css = exports.cache = void 0;var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _createInstance = _interopRequireDefault(require("@emotion/css/create-instance"));
var _stylisPluginExtraScope = _interopRequireDefault(require("stylis-plugin-extra-scope"));
var _globalObject = require("@skbkontur/global-object");

var _Upgrades = require("../Upgrades");var _globalObject$documen;




var REACT_UI_PREFIX = _Upgrades.Upgrade.getSpecificityClassName();

var scope = new Array(_Upgrades.Upgrade.getSpecificityLevel()).fill("." + REACT_UI_PREFIX).join('');

var _createEmotion =
  (0, _createInstance.default)({
    key: REACT_UI_PREFIX,
    prepend: true,
    stylisPlugins: scope ? [(0, _stylisPluginExtraScope.default)(scope)] : undefined,
    container: (_globalObject$documen = _globalObject.globalObject.document) == null ? void 0 : _globalObject$documen.head
  }),flush = exports.flush = _createEmotion.flush,hydrate = exports.hydrate = _createEmotion.hydrate,cx = exports.cx = _createEmotion.cx,merge = exports.merge = _createEmotion.merge,getRegisteredStyles = exports.getRegisteredStyles = _createEmotion.getRegisteredStyles,injectGlobal = exports.injectGlobal = _createEmotion.injectGlobal,keyframes = exports.keyframes = _createEmotion.keyframes,css = exports.css = _createEmotion.css,sheet = exports.sheet = _createEmotion.sheet,cache = exports.cache = _createEmotion.cache;

function isZeroArgs(fn) {
  return fn.length === 0;
}

var memoize = function memoize(fn) {
  if (isZeroArgs(fn)) {
    var isCalled = false;
    var result;
    return function () {
      if (!isCalled) {
        isCalled = true;
        result = fn();
      }
      return result;
    };
  }

  var cache = new WeakMap();
  return function (arg) {
    if (!cache.has(arg)) {
      cache.set(arg, fn(arg));
    }

    return cache.get(arg);
  };
};

var memoizeStyle = exports.memoizeStyle = function memoizeStyle(
styles)
{
  Object.keys(styles).forEach(function (className) {return styles[className] = memoize(styles[className]);});
  return styles;
};

var prefix = exports.prefix =
function prefix(component, app) {if (app === void 0) {app = REACT_UI_PREFIX;}return (
    function (classes) {return (
        Object.keys(classes).reduce(function (acc, key) {var _extends2;
          return (0, _extends3.default)({}, acc, (_extends2 = {}, _extends2[key] = app + "-" + component + "-" + classes[key], _extends2));
        }, {}));});};