"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Directory_exports = {};
__export(Directory_exports, {
  Directory: () => Directory
});
module.exports = __toCommonJS(Directory_exports);
var import_FilesystemNode = require("./FilesystemNode.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class Directory extends import_FilesystemNode.FilesystemNode {
  kind = "directory";
  /**
   * Return the native filesystem path for this directory, if available.  Throws by default; platform-specific
   * subclasses (e.g. NodeJsDirectory) override this.
   */
  get path() {
    throw new Error("This directory does not expose a native path");
  }
  /**
   * Open an existing entry at a relative path.  Returns a {@link File} or {@link Directory} based on what exists,
   * or throws {@link FileNotFoundError} if the path does not exist.
   */
  async open(path) {
    const segments = path.split(/[/\\]/).filter((s2) => s2 !== "");
    if (segments.length === 0) {
      return this;
    }
    let current = this;
    for (let i = 0; i < segments.length - 1; i++) {
      current = current.directory(segments[i]);
    }
    const lastName = segments[segments.length - 1];
    const handle = current.file(lastName);
    const s = await handle.stat();
    if (s.type === "directory") {
      return current.directory(lastName);
    }
    return handle;
  }
  /**
   * Get a {@link File} handle at a relative path.  The file need not exist yet.
   */
  create(path) {
    const segments = path.split(/[/\\]/).filter((s) => s !== "");
    let current = this;
    for (let i = 0; i < segments.length - 1; i++) {
      current = current.directory(segments[i]);
    }
    return current.file(segments[segments.length - 1]);
  }
  /**
   * List file names in this directory.
   */
  async files() {
    const result = Array();
    for await (const entry of this.entries()) {
      if (entry.kind === "file") {
        result.push(entry.name);
      }
    }
    return result;
  }
  /**
   * List subdirectory names in this directory.
   */
  async directories() {
    const result = Array();
    for await (const entry of this.entries()) {
      if (entry.kind === "directory") {
        result.push(entry.name);
      }
    }
    return result;
  }
  /**
   * Acquire an exclusive lock on this directory.  Returns a release function.
   *
   * The default implementation is a no-op.  Platform-specific subclasses (e.g. NodeJsDirectory) override this to
   * provide real locking with stale-lock detection.
   */
  lock() {
    return () => {
    };
  }
}
//# sourceMappingURL=Directory.js.map
