"use client";
class ClientEntityRegistry {
  entities = /* @__PURE__ */ new Map();
  /**
   * Register a new entity configuration
   */
  register(config) {
    this.entities.set(config.slug, config);
  }
  /**
   * Get entity configuration by name
   */
  get(name) {
    return this.entities.get(name);
  }
  /**
   * Get all registered entities
   */
  getAll() {
    return Array.from(this.entities.values());
  }
  /**
   * Get only enabled entities
   */
  getEnabled() {
    return this.getAll().filter((entity) => entity.enabled);
  }
  /**
   * Clear all registered entities
   */
  clear() {
    this.entities.clear();
  }
}
const clientEntityRegistry = new ClientEntityRegistry();
function setServerEntities(entities) {
  for (const entity of entities) {
    clientEntityRegistry.register(entity);
  }
  console.log(`[EntityRegistry] Client-side: registered ${entities.length} entities from server`);
}
function getAllEntityConfigs() {
  const clientEntities = clientEntityRegistry.getAll();
  if (clientEntities.length > 0) {
    return clientEntities;
  }
  try {
    const { ENTITY_REGISTRY } = require("@nextsparkjs/registries/entity-registry");
    const { Package } = require("lucide-react");
    return Object.values(ENTITY_REGISTRY).map((entry) => {
      const config = entry.config;
      return {
        ...config,
        icon: config.icon || Package,
        // Use fallback icon if original is missing
        i18n: config.i18n ? {
          ...config.i18n,
          loaders: {}
          // Remove loader functions (functions can't be serialized to client)
        } : void 0
      };
    }).filter((config) => config.slug);
  } catch (error) {
    console.error("[EntityRegistry] Failed to load from build-time registry:", error);
    return [];
  }
}
function getEnabledEntities() {
  return clientEntityRegistry.getEnabled();
}
function registerEntity(config) {
  clientEntityRegistry.register(config);
}
function getEntityConfig(name) {
  return clientEntityRegistry.get(name);
}
export {
  clientEntityRegistry,
  getAllEntityConfigs,
  getEnabledEntities,
  getEntityConfig,
  registerEntity,
  setServerEntities
};
