let _injectionWidgetEntries = null;
function registerInjectionWidgets(entries) {
  if (_injectionWidgetEntries !== null && process.env.NODE_ENV === "development") {
    console.debug("[Bootstrap] Injection widgets re-registered (this may occur during HMR)");
  }
  _injectionWidgetEntries = entries;
}
function getInjectionWidgets() {
  if (!_injectionWidgetEntries) {
    if (typeof window !== "undefined") {
      return [];
    }
    throw new Error("[Bootstrap] Injection widgets not registered. Call registerInjectionWidgets() at bootstrap.");
  }
  return _injectionWidgetEntries;
}
let entriesPromise = null;
async function getEntries() {
  if (!entriesPromise) {
    const promise = Promise.resolve().then(() => getInjectionWidgets());
    entriesPromise = promise.catch((err) => {
      if (entriesPromise === promise) {
        entriesPromise = null;
      }
      throw err;
    });
  }
  return entriesPromise;
}
const cache = /* @__PURE__ */ new Map();
async function findEntry(loaderKey) {
  const entries = await getEntries();
  return entries.find((entry) => entry.key === loaderKey);
}
async function loadInjectionWidgetModule(loaderKey) {
  const entry = await findEntry(loaderKey);
  if (!entry) return null;
  if (!cache.has(loaderKey)) {
    cache.set(
      loaderKey,
      entry.loader().then((mod) => {
        const candidate = mod;
        const maybeDefault = mod.default;
        return maybeDefault ?? candidate;
      })
    );
  }
  return cache.get(loaderKey) ?? null;
}
export {
  getInjectionWidgets,
  loadInjectionWidgetModule,
  registerInjectionWidgets
};
//# sourceMappingURL=widgetRegistry.js.map
