import { toInternalExternalRouteRef } from '../frontend-plugin-api/src/routing/ExternalRouteRef.esm.js'; function resolveRouteBindings(bindRoutes, config, routesById) { const result = /* @__PURE__ */ new Map(); const disabledExternalRefs = /* @__PURE__ */ new Set(); if (bindRoutes) { const bind = (externalRoutes, targetRoutes) => { for (const [key, value] of Object.entries(targetRoutes)) { const externalRoute = externalRoutes[key]; if (!externalRoute) { throw new Error(`Key ${key} is not an existing external route`); } if (value) { result.set(externalRoute, value); } else if (value === false) { disabledExternalRefs.add(externalRoute); } } }; bindRoutes({ bind }); } const bindings = config.getOptionalConfig("app.routes.bindings")?.get(); if (bindings) { for (const [externalRefId, targetRefId] of Object.entries(bindings)) { if (!isValidTargetRefId(targetRefId)) { throw new Error( `Invalid config at app.routes.bindings['${externalRefId}'], value must be a non-empty string or false` ); } const externalRef = routesById.externalRoutes.get(externalRefId); if (!externalRef) { throw new Error( `Invalid config at app.routes.bindings, '${externalRefId}' is not a valid external route` ); } if (result.has(externalRef) || disabledExternalRefs.has(externalRef)) { continue; } if (targetRefId === false) { disabledExternalRefs.add(externalRef); } else { const targetRef = routesById.routes.get(targetRefId); if (!targetRef) { throw new Error( `Invalid config at app.routes.bindings['${externalRefId}'], '${targetRefId}' is not a valid route` ); } result.set(externalRef, targetRef); } } } for (const externalRef of routesById.externalRoutes.values()) { if (!result.has(externalRef) && !disabledExternalRefs.has(externalRef)) { const defaultRefId = toInternalExternalRouteRef(externalRef).getDefaultTarget(); if (defaultRefId) { const defaultRef = routesById.routes.get(defaultRefId); if (defaultRef) { result.set(externalRef, defaultRef); } } } } return result; } function isValidTargetRefId(value) { if (value === false) { return true; } if (typeof value === "string" && value) { return true; } return false; } export { resolveRouteBindings }; //# sourceMappingURL=resolveRouteBindings.esm.js.map