"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_paths__internal = require('../paths/_internal.js');
const require_node_fs = require('../node/fs.js');
const require_globs_defaults = require('../globs/defaults.js');
const require_globs_matcher = require('../globs/matcher.js');

//#region src/fs/inspect.ts
/**
* @file Filesystem inspection helpers — `stat` / `lstat` wrappers that return
*   `undefined` instead of throwing, and the directory / symlink / emptiness
*   predicates layered on top. Every entry point catches errors and reduces
*   them to a falsy result; callers that need the underlying error code should
*   use `node:fs` directly.
*/
/**
* Check if a path is a directory asynchronously. Returns `true` for
* directories, `false` for files or non-existent paths.
*
* @example
*   ;```ts
*   if (await isDir('./src')) {
*     console.log('src is a directory')
*   }
*   ```
*
* @param filepath - Path to check.
*
* @returns `true` if path is a directory, `false` otherwise
*/
/*@__NO_SIDE_EFFECTS__*/
async function isDir(filepath) {
	return !!(await /* @__PURE__ */ safeStat(filepath))?.isDirectory();
}
/**
* Check if a directory is empty synchronously. A directory is considered empty
* if it contains no files after applying ignore patterns. Uses glob patterns to
* filter ignored files.
*
* @example
*   ;```ts
*   // Check if directory is completely empty
*   isDirEmptySync('./build')
*
*   // Check if directory is empty, ignoring .DS_Store files
*   isDirEmptySync('./cache', { ignore: ['.DS_Store'] })
*   ```
*
* @param dirname - Directory path to check.
* @param options - Options including ignore patterns.
*
* @returns `true` if directory is empty (or doesn't exist), `false` otherwise
*/
/*@__NO_SIDE_EFFECTS__*/
function isDirEmptySync(dirname, options) {
	const { ignore = require_globs_defaults.defaultIgnore } = {
		__proto__: null,
		...options
	};
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		const files = fs.readdirSync(dirname);
		const { length } = files;
		if (length === 0) return true;
		const matcher = /* @__PURE__ */ require_globs_matcher.getGlobMatcher(ignore, { cwd: /* @__PURE__ */ require_paths__internal.pathLikeToString(dirname) });
		let ignoredCount = 0;
		for (let i = 0; i < length; i += 1) {
			const file = files[i];
			if (file && matcher(file)) ignoredCount += 1;
		}
		return ignoredCount === length;
	} catch {
		return false;
	}
}
/**
* Check if a path is a directory synchronously. Returns `true` for directories,
* `false` for files or non-existent paths.
*
* @example
*   ;```ts
*   if (isDirSync('./src')) {
*     console.log('src is a directory')
*   }
*   ```
*
* @param filepath - Path to check.
*
* @returns `true` if path is a directory, `false` otherwise
*/
/*@__NO_SIDE_EFFECTS__*/
function isDirSync(filepath) {
	return !!(/* @__PURE__ */ safeStatSync(filepath))?.isDirectory();
}
/**
* Check if a path is a symbolic link synchronously. Uses `lstat` to check the
* link itself, not the target.
*
* @example
*   ;```ts
*   if (isSymlinkSync('./my-link')) {
*     console.log('Path is a symbolic link')
*   }
*   ```
*
* @param filepath - Path to check.
*
* @returns `true` if path is a symbolic link, `false` otherwise
*/
/*@__NO_SIDE_EFFECTS__*/
function isSymlinkSync(filepath) {
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		return fs.lstatSync(filepath).isSymbolicLink();
	} catch {}
	return false;
}
/**
* Safely get file stats asynchronously, returning undefined on error. Useful
* for checking file existence and properties without error handling. Returns
* undefined for any error (file not found, permission denied, etc.).
*
* @example
*   ;```ts
*   // Check if file exists and get its stats
*   const stats = await safeStat('./file.txt')
*   if (stats) {
*     console.log('File size:', stats.size)
*     console.log('Modified:', stats.mtime)
*   }
*   ```
*
* @param filepath - Path to check.
*
* @returns Promise resolving to Stats object, or undefined on error
*/
/*@__NO_SIDE_EFFECTS__*/
async function safeStat(filepath) {
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		return await fs.promises.stat(filepath);
	} catch {}
}
/**
* Safely get file stats synchronously, returning undefined on error. Useful for
* checking file existence and properties without error handling. Returns
* undefined for any error (file not found, permission denied, etc.).
*
* @example
*   ;```ts
*   // Check if file exists and get its size
*   const stats = safeStatSync('./file.txt')
*   if (stats) {
*     console.log('File size:', stats.size)
*     console.log('Is directory:', stats.isDirectory())
*   }
*   ```
*
* @param filepath - Path to check.
*
* @returns Stats object, or undefined on error
*/
/*@__NO_SIDE_EFFECTS__*/
function safeStatSync(filepath) {
	const fs = /* @__PURE__ */ require_node_fs.getNodeFs();
	try {
		return fs.statSync(filepath, {
			__proto__: null,
			throwIfNoEntry: false
		});
	} catch {}
}

//#endregion
exports.isDir = isDir;
exports.isDirEmptySync = isDirEmptySync;
exports.isDirSync = isDirSync;
exports.isSymlinkSync = isSymlinkSync;
exports.safeStat = safeStat;
exports.safeStatSync = safeStatSync;