"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_array = require('../primordials/array.js');
const require_primordials_date = require('../primordials/date.js');
const require_primordials_reflect = require('../primordials/reflect.js');
const require_strings_format = require('../strings/format.js');
const require_env_socket = require('../env/socket.js');
const require_node_util = require('../node/util.js');
const require_debug__internal = require('./_internal.js');
const require_debug_namespace = require('./namespace.js');
const require_spinner_default = require('../spinner/default.js');
const require_debug_caller_info = require('./caller-info.js');
let src_external_debug = require("../external/debug");
src_external_debug = require_runtime.__toESM(src_external_debug);

//#region src/debug/output.ts
/**
* @file Output entrypoints — `debug` / `debugCache` / `debugDir` / `debugLog`
*   and their `*Ns` namespace variants, plus `debuglog` (node-util-compatible)
*   and `debugtime` (start/end timers). Each output function gates through
*   `isEnabled`, prefixes the caller name from `getCallerInfo`, pauses any
*   active spinner across the write, and uses the lazy `pointingTriangle` glyph
*   for the divider.
*/
/**
* Debug output with caller info (wrapper for debugNs with default namespace).
*/
function debug(...args) {
	debugNs("*", ...args);
}
/**
* Cache debug function with caller info.
*
* @example
*   ;```typescript
*   debugCache('hit', 'socket-sdk:scans:abc123')
*   debugCache('miss', 'socket-sdk:scans:xyz', { ttl: 60000 })
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function debugCache(operation, key, meta) {
	if (!/* @__PURE__ */ require_env_socket.getSocketDebug()) return;
	const prefix = `[CACHE] ${/* @__PURE__ */ require_debug_caller_info.getCallerInfo(3) || "cache"} ${/* @__PURE__ */ require_debug__internal.getPointingTriangle()} ${operation}: ${key}`;
	const args = meta !== void 0 ? [prefix, meta] : [prefix];
	require_primordials_reflect.ReflectApply(require_debug__internal.logger.info, require_debug__internal.logger, args);
}
/**
* Debug output for cache operations with caller info. First argument is the
* operation type (hit/miss/set/clear). Second argument is the cache key or
* message. Optional third argument is metadata object.
*/
function debugCacheNs(namespacesOrOpts, operation, key, meta) {
	const options = /* @__PURE__ */ require_debug_namespace.extractOptions(namespacesOrOpts);
	const { namespaces } = options;
	if (!/* @__PURE__ */ require_debug_namespace.isEnabled(namespaces)) return;
	const prefix = `[CACHE] ${/* @__PURE__ */ require_debug_caller_info.getCallerInfo(4) || "cache"} ${/* @__PURE__ */ require_debug__internal.getPointingTriangle()} ${operation}: ${key}`;
	const logArgs = meta !== void 0 ? [prefix, meta] : [prefix];
	const spinnerInstance = options.spinner || require_spinner_default.getDefaultSpinner();
	const wasSpinning = spinnerInstance?.isSpinning;
	spinnerInstance?.stop();
	require_primordials_reflect.ReflectApply(require_debug__internal.logger.info, require_debug__internal.logger, logArgs);
	if (wasSpinning) spinnerInstance?.start();
}
/**
* Debug output for object inspection (wrapper for debugDirNs with default
* namespace).
*/
function debugDir(obj, inspectOpts) {
	debugDirNs("*", obj, inspectOpts);
}
/**
* Debug output for object inspection with caller info.
*/
function debugDirNs(namespacesOrOpts, obj, inspectOpts) {
	const options = /* @__PURE__ */ require_debug_namespace.extractOptions(namespacesOrOpts);
	const { namespaces } = options;
	if (!/* @__PURE__ */ require_debug_namespace.isEnabled(namespaces)) return;
	/* c8 ignore start */
	const callerName = /* @__PURE__ */ require_debug_caller_info.getCallerInfo(4) || "anonymous";
	/* c8 ignore stop */
	const pointingTriangle = /* @__PURE__ */ require_debug__internal.getPointingTriangle();
	let opts = inspectOpts;
	/* c8 ignore start */
	if (opts === void 0) {
		const debugOpts = src_external_debug.default.inspectOpts;
		if (debugOpts) opts = {
			...debugOpts,
			showHidden: debugOpts.showHidden === null ? void 0 : debugOpts.showHidden,
			depth: debugOpts.depth === null || typeof debugOpts.depth === "boolean" ? void 0 : debugOpts.depth
		};
	}
	/* c8 ignore stop */
	const spinnerInstance = options.spinner || require_spinner_default.getDefaultSpinner();
	const wasSpinning = spinnerInstance?.isSpinning;
	spinnerInstance?.stop();
	require_debug__internal.logger.info(`[DEBUG] ${callerName} ${pointingTriangle} object inspection:`);
	require_debug__internal.logger.dir(obj, inspectOpts);
	if (wasSpinning) spinnerInstance?.start();
}
/**
* Debug logging function (wrapper for debugLogNs with default namespace).
*/
function debugLog(...args) {
	debugLogNs("*", ...args);
}
/**
* Debug logging function with caller info.
*/
function debugLogNs(namespacesOrOpts, ...args) {
	const options = /* @__PURE__ */ require_debug_namespace.extractOptions(namespacesOrOpts);
	const { namespaces } = options;
	if (!/* @__PURE__ */ require_debug_namespace.isEnabled(namespaces)) return;
	/* c8 ignore start */
	const callerName = /* @__PURE__ */ require_debug_caller_info.getCallerInfo(4) || "anonymous";
	/* c8 ignore stop */
	const pointingTriangle = /* @__PURE__ */ require_debug__internal.getPointingTriangle();
	const text = require_primordials_array.ArrayPrototypeAt(args, 0);
	const logArgs = typeof text === "string" ? [/* @__PURE__ */ require_strings_format.applyLinePrefix(`${callerName} ${pointingTriangle} ${text}`, { prefix: "[DEBUG] " }), ...require_primordials_array.ArrayPrototypeSlice(args, 1)] : [`[DEBUG] ${callerName} ${pointingTriangle}`, ...args];
	const spinnerInstance = options.spinner || require_spinner_default.getDefaultSpinner();
	const wasSpinning = spinnerInstance?.isSpinning;
	spinnerInstance?.stop();
	require_primordials_reflect.ReflectApply(require_debug__internal.logger.info, require_debug__internal.logger, logArgs);
	if (wasSpinning) spinnerInstance?.start();
}
/**
* Debug output with caller info.
*/
function debugNs(namespacesOrOpts, ...args) {
	const options = /* @__PURE__ */ require_debug_namespace.extractOptions(namespacesOrOpts);
	const { namespaces } = options;
	if (!/* @__PURE__ */ require_debug_namespace.isEnabled(namespaces)) return;
	/* c8 ignore start */
	const name = /* @__PURE__ */ require_debug_caller_info.getCallerInfo(4) || "anonymous";
	/* c8 ignore stop */
	const pointingTriangle = /* @__PURE__ */ require_debug__internal.getPointingTriangle();
	const text = require_primordials_array.ArrayPrototypeAt(args, 0);
	const logArgs = typeof text === "string" ? [/* @__PURE__ */ require_strings_format.applyLinePrefix(`${name} ${pointingTriangle} ${text}`, { prefix: "[DEBUG] " }), ...require_primordials_array.ArrayPrototypeSlice(args, 1)] : args;
	const spinnerInstance = options.spinner || require_spinner_default.getDefaultSpinner();
	const wasSpinning = spinnerInstance?.isSpinning;
	spinnerInstance?.stop();
	require_primordials_reflect.ReflectApply(require_debug__internal.logger.info, require_debug__internal.logger, logArgs);
	if (wasSpinning) spinnerInstance?.start();
}
/**
* Create a Node.js util.debuglog compatible function. Returns a function that
* conditionally writes debug messages to stderr.
*/
/*@__NO_SIDE_EFFECTS__*/
function debuglog(section) {
	return (/* @__PURE__ */ require_node_util.getNodeUtil()).debuglog(section);
}
/**
* Create timing functions for measuring code execution time. Returns an object
* with start() and end() methods, plus a callable function.
*/
/*@__NO_SIDE_EFFECTS__*/
function debugtime(label) {
	const util = /* @__PURE__ */ require_node_util.getNodeUtil();
	let startTime;
	const impl = () => {
		if (startTime === void 0) startTime = require_primordials_date.DateNow();
		else {
			const duration = require_primordials_date.DateNow() - startTime;
			util.debuglog("time")(`${label}: ${duration}ms`);
			startTime = void 0;
		}
	};
	impl.start = () => {
		startTime = require_primordials_date.DateNow();
	};
	impl.end = () => {
		if (startTime !== void 0) {
			const duration = require_primordials_date.DateNow() - startTime;
			util.debuglog("time")(`${label}: ${duration}ms`);
			startTime = void 0;
		}
	};
	return impl;
}

//#endregion
exports.debug = debug;
exports.debugCache = debugCache;
exports.debugCacheNs = debugCacheNs;
exports.debugDir = debugDir;
exports.debugDirNs = debugDirNs;
exports.debugLog = debugLog;
exports.debugLogNs = debugLogNs;
exports.debugNs = debugNs;
exports.debuglog = debuglog;
exports.debugtime = debugtime;