"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_node_fs = require('../node/fs.js');
const require_node_path = require('../node/path.js');
const require_sorts_natural = require('../sorts/natural.js');
const require_fs_inspect = require('./inspect.js');

//#region src/fs/read-dir.ts
/**
* @file Async/sync directory listing — returns directory names only (filtering
*   out files), with optional emptiness suppression and natural-order sorting.
*   Glob-based ignore patterns are evaluated only when `includeEmpty: false`
*   triggers a per-entry emptiness probe.
*/
/**
* Process directory entries and filter for directories. Filters entries to
* include only directories, optionally excluding empty ones. Applies ignore
* patterns and natural sorting.
*
* @param dirents - Directory entries from readdir.
* @param dirname - Parent directory path.
* @param options - Filtering and sorting options.
*
* @returns Array of directory names, optionally sorted
*/
/*@__NO_SIDE_EFFECTS__*/
function innerReadDirNames(dirents, dirname, options) {
	const { ignore, includeEmpty = true, sort = true } = {
		__proto__: null,
		...options
	};
	const path = /* @__PURE__ */ require_node_path.getNodePath();
	const names = dirents.filter((d) => d.isDirectory() && (includeEmpty || !/* @__PURE__ */ require_fs_inspect.isDirEmptySync(path.join(dirname || d.parentPath, d.name), { ignore }))).map((d) => d.name);
	return sort ? names.sort(require_sorts_natural.naturalCompare) : names;
}
/**
* Read directory names asynchronously with filtering and sorting. Returns only
* directory names (not files), with optional filtering for empty directories
* and glob-based ignore patterns. Results are naturally sorted by default.
*
* @example
*   ;```ts
*   // Get all subdirectories, sorted naturally
*   const dirs = await readDirNames('./packages')
*
*   // Get non-empty directories only
*   const nonEmpty = await readDirNames('./cache', { includeEmpty: false })
*
*   // Get directories without sorting
*   const unsorted = await readDirNames('./src', { sort: false })
*   ```
*
* @param dirname - Directory path to read.
* @param options - Options for filtering and sorting.
*
* @returns Array of directory names, empty array on error
*/
/*@__NO_SIDE_EFFECTS__*/
async function readDirNames(dirname, options) {
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		return /* @__PURE__ */ innerReadDirNames(await fs.promises.readdir(dirname, {
			__proto__: null,
			encoding: "utf8",
			withFileTypes: true
		}), String(dirname), options);
	} catch {}
	return [];
}
/**
* Read directory names synchronously with filtering and sorting. Returns only
* directory names (not files), with optional filtering for empty directories
* and glob-based ignore patterns. Results are naturally sorted by default.
*
* @example
*   ;```ts
*   // Get all subdirectories, sorted naturally
*   const dirs = readDirNamesSync('./packages')
*
*   // Get non-empty directories only, ignoring node_modules
*   const nonEmpty = readDirNamesSync('./src', {
*     includeEmpty: false,
*     ignore: ['node_modules'],
*   })
*   ```
*
* @param dirname - Directory path to read.
* @param options - Options for filtering and sorting.
*
* @returns Array of directory names, empty array on error
*/
/*@__NO_SIDE_EFFECTS__*/
function readDirNamesSync(dirname, options) {
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		return /* @__PURE__ */ innerReadDirNames(fs.readdirSync(dirname, {
			__proto__: null,
			encoding: "utf8",
			withFileTypes: true
		}), String(dirname), options);
	} catch {}
	return [];
}

//#endregion
exports.innerReadDirNames = innerReadDirNames;
exports.readDirNames = readDirNames;
exports.readDirNamesSync = readDirNamesSync;