// src/product-framework/product-routing.ts
var BUILTIN_PRODUCT_SLUGS = {
  "exxat-prism": "prism",
  "exxat-one-schools": "one-schools",
  "exxat-one-sites": "one-sites"
};
function builtInProductSlug(product) {
  if (product === "exxat-custom") return "custom";
  return BUILTIN_PRODUCT_SLUGS[product];
}
var RESERVED_PRODUCT_ROOT_SEGMENTS = /* @__PURE__ */ new Set([
  "library",
  "settings",
  "help",
  "columns",
  "tokens-themes",
  "login",
  "logout",
  "oauth",
  "dashboard",
  "custom",
  "prism",
  "one-schools",
  "one-sites"
]);
var BUILTIN_SLUGS = {
  prism: "exxat-prism",
  "one-schools": "exxat-one-schools",
  "one-sites": "exxat-one-sites",
  custom: "exxat-custom"
};
function isBuiltInProductSlug(slug) {
  return slug in BUILTIN_SLUGS;
}
function isReservedProductRootSegment(slug) {
  return RESERVED_PRODUCT_ROOT_SEGMENTS.has(slug);
}
function customProductSlugFromSuffix(suffix) {
  const slug = suffix.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
  return slug || "custom-product";
}
function resolveProductFromPath(pathname, customProducts = []) {
  const segment = pathname.replace(/^\/+/, "").split("/", 1)[0] ?? "";
  if (!segment) return null;
  const builtIn = BUILTIN_SLUGS[segment];
  if (builtIn) {
    return { product: builtIn };
  }
  for (let i = 0; i < customProducts.length; i++) {
    const brand = customProducts[i];
    if (!brand?.suffix?.trim()) continue;
    if (customProductSlugFromSuffix(brand.suffix) === segment) {
      return { product: "exxat-custom", customIndex: i };
    }
  }
  return null;
}
function productRouteSlug(product, customProducts = [], activeCustomIndex = 0) {
  if (product === "exxat-custom") {
    const brand = customProducts[activeCustomIndex] ?? customProducts[0];
    if (brand?.suffix?.trim()) {
      return customProductSlugFromSuffix(brand.suffix);
    }
    return "custom";
  }
  return builtInProductSlug(product);
}
function validateCustomProductSuffix(suffix, customProducts, excludeIndex) {
  const trimmed = suffix.trim();
  if (!trimmed) return "Enter a product name after Exxat.";
  const slug = customProductSlugFromSuffix(trimmed);
  if (isReservedProductRootSegment(slug) || isBuiltInProductSlug(slug)) {
    return `"${trimmed}" conflicts with a reserved route \u2014 pick another name.`;
  }
  const duplicate = customProducts.some(
    (cp, i) => i !== excludeIndex && cp.suffix?.trim() && customProductSlugFromSuffix(cp.suffix) === slug
  );
  if (duplicate) {
    return `A product named "${trimmed}" already exists.`;
  }
  return null;
}
export {
  RESERVED_PRODUCT_ROOT_SEGMENTS,
  customProductSlugFromSuffix,
  isBuiltInProductSlug,
  isReservedProductRootSegment,
  productRouteSlug,
  resolveProductFromPath,
  validateCustomProductSuffix
};
//# sourceMappingURL=product-routing.js.map