import { __exports as sync } from '../../../../../../../../_virtual/sync6.mjs';
import { __require as requireOut } from '../../../../../../@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.mjs';
import { __require as requireConstants } from '../constants.mjs';
import { __require as requireUtils } from '../utils/index.mjs';
import { __require as requireCommon } from './common.mjs';

var hasRequiredSync;
function requireSync() {
  if (hasRequiredSync) return sync;
  hasRequiredSync = 1;
  Object.defineProperty(sync, "__esModule", {
    value: true
  });
  sync.readdir = sync.readdirWithFileTypes = sync.read = void 0;
  const fsStat = requireOut();
  const constants_1 = requireConstants();
  const utils = requireUtils();
  const common = requireCommon();
  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;
  return sync;
}

export { requireSync as __require };
