import { DEFAULT_GET_METADATA_OPTIONS } from "../metadata-types.js";
import { relative } from "node:path";
//#region src/lib/utilities/formatting.ts
/**
* Format an absolute path as either absolute or relative, based on the `absolute` option.
* When relative, paths identical to `basePath` are returned as `'.'`.
* Correctly handles Windows paths (normalizes to POSIX) and ignores URLs.
*/
function formatPath(absolutePath, basePath, absolute = DEFAULT_GET_METADATA_OPTIONS.absolute) {
	if (/^[a-z]+:\/\//i.test(absolutePath)) return absolutePath;
	if (absolute) return absolutePath.replaceAll("\\", "/");
	const relativePath = relative(basePath, absolutePath).replaceAll("\\", "/");
	return relativePath === "" ? "." : relativePath;
}
/**
* Process an array of items in batches to avoid resource limits.
*/
async function batchMap(items, mapper, batchSize = 50) {
	const results = [];
	for (let index = 0; index < items.length; index += batchSize) {
		const chunk = items.slice(index, index + batchSize);
		const chunkResults = await Promise.all(chunk.map(async (item) => mapper(item)));
		results.push(...chunkResults);
	}
	return results;
}
//#endregion
export { batchMap, formatPath };
