import { inspectList, inspectProperty, truncate, truncator } from "./helpers.js";

//#region ../../node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.js
const getArrayName = (array) => {
	if (typeof Buffer === "function" && array instanceof Buffer) return "Buffer";
	if (array[Symbol.toStringTag]) return array[Symbol.toStringTag];
	return array.constructor.name;
};
function inspectTypedArray(array, options) {
	const name = getArrayName(array);
	options.truncate -= name.length + 4;
	const nonIndexProperties = Object.keys(array).slice(array.length);
	if (!array.length && !nonIndexProperties.length) return `${name}[]`;
	let output = "";
	for (let i = 0; i < array.length; i++) {
		const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`;
		options.truncate -= string.length;
		if (array[i] !== array.length && options.truncate <= 3) {
			output += `${truncator}(${array.length - array[i] + 1})`;
			break;
		}
		output += string;
	}
	let propertyContents = "";
	if (nonIndexProperties.length) propertyContents = inspectList(nonIndexProperties.map((key) => [key, array[key]]), options, inspectProperty);
	return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
}

//#endregion
export { inspectTypedArray as default };