import { u as useWidgetsCore, j as jsxRuntimeExports, Q as QueryClient, I as I18nextProvider, e as i18n, b as QueryClientProvider, W as WidgetsCoreContextProvider, c as WidgetsLoggerContextProvider, F as FeaturesContextProvider } from "./root-CqOwVDsl.js";
import { r as reactExports } from "./index-BKyMaBlO.js";
import { E as ErrorBoundary, a as Error$1, L as Loader } from "./loader-5BGkTPnX.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 Settings = reactExports.lazy(() => import("./settings-CTEDmdKf.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.config.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(Settings, { actions: props.actions }) })
    }
  ) }) }) }) }) }) });
}
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-py22CADe.js.map
