/* FORGE — mittelstand screens registry. Each act registers its routes here.
   Format: { path: "/build/routing", mode: "build", title: "Routing canvas", renderer: () => <Component /> }
   Wave A1+ agents push to MITTELSTAND_ROUTES from their act registries. */

const MITTELSTAND_ROUTES = (typeof window !== "undefined" && Array.isArray(window.MITTELSTAND_ROUTES))
  ? window.MITTELSTAND_ROUTES
  : [];

function registerMittelstandRoute(route) {
  // De-dupe by path so reloading a single act registry doesn't double-register
  const ix = MITTELSTAND_ROUTES.findIndex(function(r) { return r.path === route.path; });
  if (ix >= 0) {
    MITTELSTAND_ROUTES[ix] = route;
  } else {
    MITTELSTAND_ROUTES.push(route);
  }
  return route;
}

function listMittelstandRoutes() {
  return MITTELSTAND_ROUTES.slice();
}

if (typeof window !== "undefined") {
  window.MITTELSTAND_ROUTES        = MITTELSTAND_ROUTES;
  window.registerMittelstandRoute  = registerMittelstandRoute;
  window.listMittelstandRoutes     = listMittelstandRoutes;
}
