import { normaliseOptions } from "./helpers.js";
import inspectArray from "./array.js";
import inspectTypedArray from "./typedarray.js";
import inspectDate from "./date.js";
import inspectFunction from "./function.js";
import inspectMap from "./map.js";
import inspectNumber from "./number.js";
import inspectBigInt from "./bigint.js";
import inspectRegExp from "./regexp.js";
import inspectSet from "./set.js";
import inspectString from "./string.js";
import inspectSymbol from "./symbol.js";
import promise_default from "./promise.js";
import inspectObject from "./object.js";
import inspectClass from "./class.js";
import inspectArguments from "./arguments.js";
import inspectObject$1 from "./error.js";
import inspectHTML, { inspectNodeCollection } from "./html.js";

//#region ../../node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.js
const chaiInspect = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("chai/inspect") : "@@chai/inspect";
const nodeInspect = Symbol.for("nodejs.util.inspect.custom");
const constructorMap = /* @__PURE__ */ new WeakMap();
const stringTagMap = {};
const baseTypesMap = {
	undefined: (value, options) => options.stylize("undefined", "undefined"),
	null: (value, options) => options.stylize("null", "null"),
	boolean: (value, options) => options.stylize(String(value), "boolean"),
	Boolean: (value, options) => options.stylize(String(value), "boolean"),
	number: inspectNumber,
	Number: inspectNumber,
	bigint: inspectBigInt,
	BigInt: inspectBigInt,
	string: inspectString,
	String: inspectString,
	function: inspectFunction,
	Function: inspectFunction,
	symbol: inspectSymbol,
	Symbol: inspectSymbol,
	Array: inspectArray,
	Date: inspectDate,
	Map: inspectMap,
	Set: inspectSet,
	RegExp: inspectRegExp,
	Promise: promise_default,
	WeakSet: (value, options) => options.stylize("WeakSet{…}", "special"),
	WeakMap: (value, options) => options.stylize("WeakMap{…}", "special"),
	Arguments: inspectArguments,
	Int8Array: inspectTypedArray,
	Uint8Array: inspectTypedArray,
	Uint8ClampedArray: inspectTypedArray,
	Int16Array: inspectTypedArray,
	Uint16Array: inspectTypedArray,
	Int32Array: inspectTypedArray,
	Uint32Array: inspectTypedArray,
	Float32Array: inspectTypedArray,
	Float64Array: inspectTypedArray,
	Generator: () => "",
	DataView: () => "",
	ArrayBuffer: () => "",
	Error: inspectObject$1,
	HTMLCollection: inspectNodeCollection,
	NodeList: inspectNodeCollection
};
const inspectCustom = (value, options, type, inspectFn) => {
	if (chaiInspect in value && typeof value[chaiInspect] === "function") return value[chaiInspect](options);
	if (nodeInspect in value && typeof value[nodeInspect] === "function") return value[nodeInspect](options.depth, options, inspectFn);
	if ("inspect" in value && typeof value.inspect === "function") return value.inspect(options.depth, options);
	if ("constructor" in value && constructorMap.has(value.constructor)) return constructorMap.get(value.constructor)(value, options);
	if (stringTagMap[type]) return stringTagMap[type](value, options);
	return "";
};
const toString = Object.prototype.toString;
function inspect(value, opts = {}) {
	const options = normaliseOptions(opts, inspect);
	const { customInspect } = options;
	let type = value === null ? "null" : typeof value;
	if (type === "object") type = toString.call(value).slice(8, -1);
	if (type in baseTypesMap) return baseTypesMap[type](value, options);
	if (customInspect && value) {
		const output = inspectCustom(value, options, type, inspect);
		if (output) {
			if (typeof output === "string") return output;
			return inspect(output, options);
		}
	}
	const proto = value ? Object.getPrototypeOf(value) : false;
	if (proto === Object.prototype || proto === null) return inspectObject(value, options);
	if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) return inspectHTML(value, options);
	if ("constructor" in value) {
		if (value.constructor !== Object) return inspectClass(value, options);
		return inspectObject(value, options);
	}
	if (value === Object(value)) return inspectObject(value, options);
	return options.stylize(String(value), type);
}

//#endregion
export { inspect };