let _dashboardWidgetEntries = null;
function registerDashboardWidgets(entries) {
  if (_dashboardWidgetEntries !== null && process.env.NODE_ENV === "development") {
    console.debug("[Bootstrap] Dashboard widgets re-registered (this may occur during HMR)");
  }
  _dashboardWidgetEntries = entries;
}
function getDashboardWidgets() {
  if (!_dashboardWidgetEntries) {
    if (typeof window !== "undefined") {
      return [];
    }
    throw new Error("[Bootstrap] Dashboard widgets not registered. Call registerDashboardWidgets() at bootstrap.");
  }
  return _dashboardWidgetEntries;
}
let entriesPromise = null;
async function getEntries() {
  if (!entriesPromise) {
    const promise = Promise.resolve().then(() => getDashboardWidgets());
    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 loadDashboardWidgetModule(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 {
  getDashboardWidgets,
  loadDashboardWidgetModule,
  registerDashboardWidgets
};
//# sourceMappingURL=widgetRegistry.js.map
