import { __exports as sync } from '../../../../../../../../_virtual/sync6.mjs';
import '../../../../../../@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.mjs';
import '../constants.mjs';
import '../utils/index.mjs';
import './common.mjs';
import { __exports as out } from '../../../../../../../../_virtual/index5.mjs';
import { __exports as constants } from '../../../../../../../../_virtual/constants.mjs';
import { __exports as utils$1 } from '../../../../../../../../_virtual/index7.mjs';
import { __exports as common$1 } from '../../../../../../../../_virtual/common2.mjs';

Object.defineProperty(sync, "__esModule", {
  value: true
});
sync.readdir = sync.readdirWithFileTypes = sync.read = void 0;
const fsStat = out;
const constants_1 = constants;
const utils = utils$1;
const common = common$1;
function read(directory, settings) {
  if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
    return readdirWithFileTypes(directory, settings);
  }
  return readdir(directory, settings);
}
sync.read = read;
function readdirWithFileTypes(directory, settings) {
  const dirents = settings.fs.readdirSync(directory, {
    withFileTypes: true
  });
  return dirents.map(dirent => {
    const entry = {
      dirent,
      name: dirent.name,
      path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
    };
    if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) {
      try {
        const stats = settings.fs.statSync(entry.path);
        entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
      } catch (error) {
        if (settings.throwErrorOnBrokenSymbolicLink) {
          throw error;
        }
      }
    }
    return entry;
  });
}
sync.readdirWithFileTypes = readdirWithFileTypes;
function readdir(directory, settings) {
  const names = settings.fs.readdirSync(directory);
  return names.map(name => {
    const entryPath = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
    const stats = fsStat.statSync(entryPath, settings.fsStatSettings);
    const entry = {
      name,
      path: entryPath,
      dirent: utils.fs.createDirentFromStats(name, stats)
    };
    if (settings.stats) {
      entry.stats = stats;
    }
    return entry;
  });
}
sync.readdir = readdir;

export { sync as default };
