import { e as useWidgetsCore, j as jsxRuntimeExports, Q as QueryClient, I as I18nextProvider, k as QueryClientProvider, W as WidgetsCoreContextProvider, l as WidgetsLoggerContextProvider, F as FeaturesContextProvider, E as ErrorBoundary, L as Loader, h as useTranslation, m as interweave, H as Hyperlink } from "./root-ERA_nxjG.js";
import { j as tx } from "./core-BL1C1e3f.js";
import { r as reactExports } from "./index-DtmNFEFh.js";
import { b as i18n } from "./stream-CDVnrTgp.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-n7jyqluM.js"));
function Root(props) {
  const { t } = i18n;
  const queryClient = reactExports.useRef();
  queryClient.current ?? (queryClient.current = new QueryClient({
    defaultOptions: {
      queries: {
        // eslint-disable-next-line unicorn/prefer-number-properties
        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: ({ resetErrorBoundary }) => /* @__PURE__ */ jsxRuntimeExports.jsx(Error$1, { 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 }) })
    }
  ) }) }) }) }) }) });
}
function Error$1(props) {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex h-full w-full flex-col items-center justify-center px-8", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-base font-semibold leading-tight text-zinc-900", children: t("error.message") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-light leading-tight text-zinc-700", children: interweave(t("error.next-steps"), {
      c0: /* @__PURE__ */ jsxRuntimeExports.jsx(
        Hyperlink,
        {
          href: props.supportUrl ?? void 0,
          className: tx({ "text-brand-900 underline": props.supportUrl })
        }
      )
    }) }),
    props.reset ? /* @__PURE__ */ jsxRuntimeExports.jsx(
      "button",
      {
        type: "button",
        className: "!mt-4 rounded-full border border-brand-700 bg-brand-900 px-4 py-2 text-sm text-white hover:border-brand-900 hover:bg-brand-700 focus:border-brand-900 focus:bg-brand-700 active:border-zinc-100 active:bg-brand-900",
        onClick: props.reset,
        children: t("error.reset")
      }
    ) : null
  ] }) });
}
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-V_sqR5h1.js.map
