var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: (newValue) => all[name] = () => newValue
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);

// src/loader.ts
import { existsSync, readdirSync, readFileSync } from "fs";
import { join } from "path";

class ComponentLoader {
  components = new Map;
  register(name, module, template, path) {
    this.components.set(name, {
      name,
      module,
      template,
      path: path || name
    });
  }
  get(name) {
    return this.components.get(name);
  }
  has(name) {
    return this.components.has(name);
  }
  getNames() {
    return Array.from(this.components.keys());
  }
  getAll() {
    return Array.from(this.components.values());
  }
  clear() {
    this.components.clear();
  }
  async loadFromDirectory(name, dirPath) {
    try {
      const modulePath = join(dirPath, "component.ts");
      const moduleExport = await import(modulePath);
      const module = moduleExport.default;
      const templatePath = join(dirPath, "component.hypen");
      const template = readFileSync(templatePath, "utf-8");
      this.register(name, module, template, dirPath);
      console.log(`✓ Loaded component: ${name} from ${dirPath}`);
    } catch (error) {
      console.error(`✗ Failed to load component ${name} from ${dirPath}:`, error);
      throw error;
    }
  }
  async loadFromComponentsDir(baseDir) {
    try {
      if (!existsSync(baseDir)) {
        console.warn(`⚠ Components directory not found: ${baseDir}`);
        return;
      }
      const entries = readdirSync(baseDir, { withFileTypes: true });
      for (const entry of entries) {
        if (!entry.isDirectory())
          continue;
        const componentDir = join(baseDir, entry.name);
        const hypenPath = join(componentDir, "component.hypen");
        if (existsSync(hypenPath)) {
          await this.loadFromDirectory(entry.name, componentDir);
        }
      }
      console.log(`✓ Loaded ${this.components.size} components from ${baseDir}`);
    } catch (error) {
      console.error(`✗ Failed to load components from ${baseDir}:`, error);
      throw error;
    }
  }
}
var componentLoader = new ComponentLoader;
export {
  componentLoader,
  ComponentLoader
};

//# debugId=0631A1CC07796D5464756E2164756E21
