import * as Icons from "lucide-react";
function isEntityConfig(config) {
  return "ui" in config && typeof config.ui === "object" && config.ui !== null && "dashboard" in config.ui;
}
function isChildEntityConfig(config) {
  return "parent" in config && typeof config.parent === "string";
}
function serializeEntityConfig(config) {
  var _a;
  const iconName = ((_a = Object.entries(Icons).find(
    ([, icon2]) => icon2 === config.icon
  )) == null ? void 0 : _a[0]) || "Box";
  const { icon, i18n, ...rest } = config;
  return {
    ...rest,
    iconName,
    i18nFallbackLocale: (i18n == null ? void 0 : i18n.fallbackLocale) || "en"
  };
}
function serializeChildEntityConfig(config) {
  return {
    ...config,
    iconName: "Box",
    // Default icon for child entities
    i18nFallbackLocale: "en"
    // Default locale
  };
}
function serializeConfig(config) {
  if (isChildEntityConfig(config)) {
    return serializeChildEntityConfig(config);
  } else {
    return serializeEntityConfig(config);
  }
}
function deserializeEntityConfig(config) {
  const icon = Icons[config.iconName] || Icons.Box;
  const { iconName, i18nFallbackLocale, ...rest } = config;
  return {
    ...rest,
    icon,
    i18n: {
      fallbackLocale: i18nFallbackLocale,
      loaders: {}
      // Loaders are not serializable, will be handled separately
    }
  };
}
function deserializeChildEntityConfig(config) {
  const { iconName, i18nFallbackLocale, ...rest } = config;
  return {
    ...rest
  };
}
function serializeEntities(entities) {
  return entities.map(serializeConfig);
}
function deserializeEntities(entities) {
  return entities.map((config) => {
    if ("parent" in config && typeof config.parent === "string") {
      return deserializeChildEntityConfig(config);
    } else {
      return deserializeEntityConfig(config);
    }
  });
}
export {
  deserializeChildEntityConfig,
  deserializeEntities,
  deserializeEntityConfig,
  serializeChildEntityConfig,
  serializeConfig,
  serializeEntities,
  serializeEntityConfig
};
