"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var getters_exports = {};
__export(getters_exports, {
  createConstantsObject: () => createConstantsObject,
  createLazyGetter: () => createLazyGetter,
  defineGetter: () => defineGetter,
  defineLazyGetter: () => defineLazyGetter,
  defineLazyGetters: () => defineLazyGetters
});
module.exports = __toCommonJS(getters_exports);
var import_sentinels = require("../constants/sentinels");
var import_map_set = require("../primordials/map-set");
var import_object = require("../primordials/object");
var import_reflect = require("../primordials/reflect");
var import_sort = require("./sort");
// @__NO_SIDE_EFFECTS__
function createConstantsObject(props, options_) {
  const options = { __proto__: null, ...options_ };
  const attributes = (0, import_object.ObjectFreeze)({
    __proto__: null,
    getters: options.getters ? (0, import_object.ObjectFreeze)(
      // oxlint-disable-next-line socket/prefer-undefined-over-null -- Object.setPrototypeOf requires `null` for null-prototype objects.
      (0, import_object.ObjectSetPrototypeOf)((0, import_sort.toSortedObject)(options.getters), null)
    ) : void 0,
    internals: options.internals ? (0, import_object.ObjectFreeze)(
      // oxlint-disable-next-line socket/prefer-undefined-over-null
      (0, import_object.ObjectSetPrototypeOf)((0, import_sort.toSortedObject)(options.internals), null)
    ) : void 0,
    mixin: options.mixin ? (0, import_object.ObjectFreeze)(
      (0, import_object.ObjectDefineProperties)(
        { __proto__: null },
        (0, import_object.ObjectGetOwnPropertyDescriptors)(options.mixin)
      )
    ) : void 0,
    props: props ? (
      // oxlint-disable-next-line socket/prefer-undefined-over-null
      (0, import_object.ObjectFreeze)((0, import_object.ObjectSetPrototypeOf)((0, import_sort.toSortedObject)(props), null))
    ) : void 0
  });
  const lazyGetterStats = (0, import_object.ObjectFreeze)({
    __proto__: null,
    initialized: new import_map_set.SetCtor()
  });
  const object = defineLazyGetters(
    {
      __proto__: null,
      [import_sentinels.kInternalsSymbol]: (0, import_object.ObjectFreeze)({
        __proto__: null,
        get attributes() {
          return attributes;
        },
        get lazyGetterStats() {
          return lazyGetterStats;
        },
        ...attributes.internals
      }),
      kInternalsSymbol: import_sentinels.kInternalsSymbol,
      ...attributes.props
    },
    attributes.getters,
    lazyGetterStats
  );
  if (attributes.mixin) {
    (0, import_object.ObjectDefineProperties)(
      object,
      (0, import_sort.toSortedObjectFromEntries)(
        (0, import_sort.objectEntries)((0, import_object.ObjectGetOwnPropertyDescriptors)(attributes.mixin)).filter(
          (p) => !(0, import_object.ObjectHasOwn)(object, p[0])
        )
      )
    );
  }
  return (0, import_object.ObjectFreeze)(object);
}
// @__NO_SIDE_EFFECTS__
function createLazyGetter(name, getter, stats) {
  const UNCOMPUTED = {};
  let lazyValue = UNCOMPUTED;
  const { [name]: lazyGetter } = {
    [name]() {
      if (lazyValue === UNCOMPUTED) {
        stats?.initialized?.add(name);
        lazyValue = getter();
      }
      return lazyValue;
    }
  };
  return lazyGetter;
}
function defineGetter(object, propKey, getter) {
  (0, import_object.ObjectDefineProperty)(object, propKey, {
    get: getter,
    enumerable: false,
    configurable: true
  });
  return object;
}
function defineLazyGetter(object, propKey, getter, stats) {
  return defineGetter(object, propKey, /* @__PURE__ */ createLazyGetter(propKey, getter, stats));
}
function defineLazyGetters(object, getterDefObj, stats) {
  if (getterDefObj !== null && typeof getterDefObj === "object") {
    const keys = (0, import_reflect.ReflectOwnKeys)(getterDefObj);
    for (let i = 0, { length } = keys; i < length; i += 1) {
      const key = keys[i];
      defineLazyGetter(object, key, getterDefObj[key], stats);
    }
  }
  return object;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createConstantsObject,
  createLazyGetter,
  defineGetter,
  defineLazyGetter,
  defineLazyGetters
});
