import { commonjsGlobal } from "../../_virtual/_commonjsHelpers.js";
import { __require as requireDefineProperties } from "../define-properties/index.js";
import { __require as requireIsSymbol } from "../is-symbol/index.js";
var globalCache_1;
var hasRequiredGlobalCache;
function requireGlobalCache() {
  if (hasRequiredGlobalCache) return globalCache_1;
  hasRequiredGlobalCache = 1;
  var define = requireDefineProperties();
  var isSymbol = requireIsSymbol();
  var globalKey = "__ global cache key __";
  if (typeof Symbol === "function" && isSymbol(Symbol("foo")) && typeof Symbol["for"] === "function") {
    globalKey = Symbol["for"](globalKey);
  }
  var trueThunk = function() {
    return true;
  };
  var ensureCache = function ensureCache2() {
    if (!commonjsGlobal[globalKey]) {
      var properties = {};
      properties[globalKey] = {};
      var predicates = {};
      predicates[globalKey] = trueThunk;
      define(commonjsGlobal, properties, predicates);
    }
    return commonjsGlobal[globalKey];
  };
  var cache = ensureCache();
  var isPrimitive = function isPrimitive2(val) {
    return val === null || typeof val !== "object" && typeof val !== "function";
  };
  var getPrimitiveKey = function getPrimitiveKey2(val) {
    if (isSymbol(val)) {
      return Symbol.prototype.valueOf.call(val);
    }
    return typeof val + " | " + String(val);
  };
  var requirePrimitiveKey = function requirePrimitiveKey2(val) {
    if (!isPrimitive(val)) {
      throw new TypeError("key must not be an object");
    }
  };
  var globalCache = {
    clear: function clear() {
      delete commonjsGlobal[globalKey];
      cache = ensureCache();
    },
    "delete": function deleteKey(key) {
      requirePrimitiveKey(key);
      delete cache[getPrimitiveKey(key)];
      return !globalCache.has(key);
    },
    get: function get(key) {
      requirePrimitiveKey(key);
      return cache[getPrimitiveKey(key)];
    },
    has: function has(key) {
      requirePrimitiveKey(key);
      return getPrimitiveKey(key) in cache;
    },
    set: function set(key, value) {
      requirePrimitiveKey(key);
      var primitiveKey = getPrimitiveKey(key);
      var props = {};
      props[primitiveKey] = value;
      var predicates = {};
      predicates[primitiveKey] = trueThunk;
      define(cache, props, predicates);
      return globalCache.has(key);
    },
    setIfMissingThenGet: function setIfMissingThenGet(key, valueThunk) {
      if (globalCache.has(key)) {
        return globalCache.get(key);
      }
      var item = valueThunk();
      globalCache.set(key, item);
      return item;
    }
  };
  globalCache_1 = globalCache;
  return globalCache_1;
}
export {
  requireGlobalCache as __require
};
