"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var console_exports = {};
__export(console_exports, {
  constructConsole: () => constructConsole,
  ensurePrototypeInitialized: () => ensurePrototypeInitialized
});
module.exports = __toCommonJS(console_exports);
var import_node_process = __toESM(require("node:process"));
var import_object = require("../primordials/object");
var import_reflect = require("../primordials/reflect");
var import_internal = require("./_internal");
var import_logger = require("./logger");
var import_symbols = require("./symbols");
let _Console;
let _prototypeInitialized = false;
// @__NO_SIDE_EFFECTS__
function constructConsole(...args) {
  if (_Console === void 0) {
    const nodeConsole = require("node:console");
    _Console = nodeConsole.Console;
  }
  return (0, import_reflect.ReflectConstruct)(
    _Console,
    // eslint-disable-line no-undef
    args
  );
}
function ensurePrototypeInitialized() {
  if (_prototypeInitialized) {
    return;
  }
  _prototypeInitialized = true;
  const entries = [
    [
      (0, import_symbols.getKGroupIndentationWidthSymbol)(),
      {
        ...import_internal.consolePropAttributes,
        value: 2
      }
    ],
    [
      Symbol.toStringTag,
      {
        __proto__: null,
        configurable: true,
        value: "logger"
      }
    ]
  ];
  for (const { 0: key, 1: value } of (0, import_object.ObjectEntries)(import_internal.globalConsole)) {
    if (!import_logger.Logger.prototype[key] && typeof value === "function") {
      const { [key]: func } = {
        [key](...args) {
          let con = import_internal.privateConsole.get(this);
          if (con === void 0) {
            const ctorArgs = import_internal.privateConstructorArgs.get(this) ?? [];
            import_internal.privateConstructorArgs.delete(this);
            if (ctorArgs.length) {
              con = /* @__PURE__ */ constructConsole(...ctorArgs);
            } else {
              con = /* @__PURE__ */ constructConsole({
                stdout: import_node_process.default.stdout,
                stderr: import_node_process.default.stderr
              });
              for (const { 0: k, 1: method } of import_internal.boundConsoleEntries) {
                con[k] = method;
              }
            }
            import_internal.privateConsole.set(this, con);
          }
          const result = con[key](...args);
          return result === void 0 || result === con ? this : result;
        }
      };
      entries.push([
        key,
        {
          ...import_internal.consolePropAttributes,
          value: func
        }
      ]);
    }
  }
  (0, import_object.ObjectDefineProperties)(import_logger.Logger.prototype, (0, import_object.ObjectFromEntries)(entries));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  constructConsole,
  ensurePrototypeInitialized
});
