import { a as useWidgetsCore, j as jsxRuntimeExports, I as I18nextProvider, W as WidgetsCoreContextProvider, c as WidgetsLoggerContextProvider, F as FeaturesContextProvider } from "./root-BsFnDowq.js";
import { Q as QueryClient, h as QueryClientProvider, E as ErrorBoundary, j as Error$1, L as Loader } from "./root-BQd9WFWt.js";
import { r as reactExports } from "./index-BiJIPbhw.js";
import { a as i18n } from "./stream-f51FBDtW.js";
const CurrentSpaceContext = reactExports.createContext(void 0);
function CurrentSpaceContextProvider(props) {
  const core = useWidgetsCore();
  const state = reactExports.useState(props.initialSpaceId);
  const [currentSpaceId, setCurrentSpaceId] = state;
  reactExports.useEffect(() => {
    core.emit("space", currentSpaceId);
  }, [currentSpaceId]);
  reactExports.useEffect(() => {
    core.on("space", setCurrentSpaceId);
    return () => {
      core.off("space", setCurrentSpaceId);
    };
  }, [core]);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(CurrentSpaceContext.Provider, { value: state, children: props.children });
}
function useCurrentSpace() {
  const context = reactExports.useContext(CurrentSpaceContext);
  if (context === void 0) {
    throw new Error("useCurrentSpace must be used within a CurrentSpaceContext.Provider");
  }
  return context;
}
const Notifications = reactExports.lazy(() => import("./notifications-CGpkJwOt.js"));
function Root(props) {
  const { t } = i18n;
  const queryClient = reactExports.useRef();
  queryClient.current ?? (queryClient.current = new QueryClient({
    defaultOptions: {
      queries: {
        staleTime: Infinity,
        // Queries should never be refetched
        // Failed queries are not subject to staleTime, disable refetch
        refetchOnReconnect: false,
        refetchOnWindowFocus: false
      }
    }
  }));
  return /* @__PURE__ */ jsxRuntimeExports.jsx(I18nextProvider, { i18n, children: /* @__PURE__ */ jsxRuntimeExports.jsx(QueryClientProvider, { client: queryClient.current, children: /* @__PURE__ */ jsxRuntimeExports.jsx(WidgetsCoreContextProvider, { core: props.core, children: /* @__PURE__ */ jsxRuntimeExports.jsx(WidgetsLoggerContextProvider, { logger: props.logger, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FeaturesContextProvider, { features: props.features, children: /* @__PURE__ */ jsxRuntimeExports.jsx(CurrentSpaceContextProvider, { initialSpaceId: props.config.space, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
    ErrorBoundary,
    {
      fallbackRender: ({ error, resetErrorBoundary }) => /* @__PURE__ */ jsxRuntimeExports.jsx(Error$1, { error, reset: resetErrorBoundary, supportUrl: props.config.supportUrl }),
      onReset: () => {
        var _a;
        return (_a = queryClient.current) == null ? void 0 : _a.clear();
      },
      children: /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { label: t("loading") }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Notifications, {}) })
    }
  ) }) }) }) }) }) });
}
const root = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Root
}, Symbol.toStringTag, { value: "Module" }));
export {
  root as r,
  useCurrentSpace as u
};
//# sourceMappingURL=root-B4z3bnWk.js.map
