"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_object = require('../primordials/object.js');
const require_primordials_reflect = require('../primordials/reflect.js');
const require_logger__internal = require('./_internal.js');
const require_logger_symbols = require('./symbols.js');
const require_logger_node = require('./node.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);

//#region src/logger/console.ts
/**
* @file Lazy `Console` construction + dynamic prototype mirroring for `Logger`.
*   Both helpers exist as free functions (rather than `Logger` static methods)
*   because:
*
*   - `constructConsole` caches the resolved `node:console` module so multiple
*     `new Logger()` calls don't pay the require cost more than once. Caching
*     at the function level is simpler than a class field that has to thread
*     through all callers.
*   - `ensurePrototypeInitialized` walks `globalConsole` once at first use and
*     copies any console method that isn't already on `Logger.prototype`. Doing
*     this lazily (rather than at module load) is what lets the logger be
*     imported during early Node.js bootstrap before stdout is ready, which
*     would otherwise crash with `ERR_CONSOLE_WRITABLE_STREAM`. Note on the
*     apparent circular import with `core.ts`: `ensurePrototypeInitialized`
*     mutates `Logger.prototype`, so it imports `Logger` from `./core`.
*     `core.ts` calls `ensurePrototypeInitialized()` from inside a method body,
*     so the import cycle never resolves at module-load time — by the time
*     `ensurePrototypeInitialized` actually runs, both modules are fully
*     evaluated. Same pattern as `fs/path-cache` ↔ `fs/_internal`.
*/
let _Console;
let _prototypeInitialized = false;
/**
* Construct a new Console instance.
*/
/*@__NO_SIDE_EFFECTS__*/
function constructConsole(...args) {
	/* c8 ignore next - Lazy-init second-call branch; module-singleton. */
	if (_Console === void 0) _Console = (/* @__PURE__ */ require("node:console")).Console;
	return require_primordials_reflect.ReflectConstruct(_Console, args);
}
/**
* Lazily add dynamic console methods to Logger prototype.
*
* This is deferred until first access to avoid calling
* Object.entries(globalConsole) during early Node.js bootstrap before stdout is
* ready.
*/
function ensurePrototypeInitialized() {
	if (_prototypeInitialized) return;
	_prototypeInitialized = true;
	const entries = [[require_logger_symbols.getKGroupIndentationWidthSymbol(), {
		...require_logger__internal.consolePropAttributes,
		value: 2
	}], [Symbol.toStringTag, {
		__proto__: null,
		configurable: true,
		value: "logger"
	}]];
	for (const { 0: key, 1: value } of require_primordials_object.ObjectEntries(require_logger__internal.globalConsole)) if (!require_logger_node.Logger.prototype[key] && typeof value === "function") {
		const { [key]: func } = { [key](...args) {
			/* c8 ignore start */
			let con = require_logger__internal.privateConsole.get(this);
			if (con === void 0) {
				const ctorArgs = require_logger__internal.privateConstructorArgs.get(this) ?? [];
				require_logger__internal.privateConstructorArgs.delete(this);
				if (ctorArgs.length) con = /* @__PURE__ */ constructConsole(...ctorArgs);
				else {
					con = /* @__PURE__ */ constructConsole({
						stdout: node_process.default.stdout,
						stderr: node_process.default.stderr
					});
					for (const { 0: k, 1: method } of require_logger__internal.boundConsoleEntries) con[k] = method;
				}
				require_logger__internal.privateConsole.set(this, con);
			}
			/* c8 ignore stop */
			const result = con[key](...args);
			/* c8 ignore next */
			return result === void 0 || result === con ? this : result;
		} };
		entries.push([key, {
			...require_logger__internal.consolePropAttributes,
			value: func
		}]);
	}
	require_primordials_object.ObjectDefineProperties(require_logger_node.Logger.prototype, require_primordials_object.ObjectFromEntries(entries));
}

//#endregion
exports.constructConsole = constructConsole;
exports.ensurePrototypeInitialized = ensurePrototypeInitialized;