import { jsx, jsxs } from "react/jsx-runtime";
import { Environment, EnvironmentContext, EnvironmentExtensionProvider } from "@contember/binding";
import { ContemberClient } from "@contember/react-client";
import { StyleProvider, ToasterProvider, DialogProvider, SectionTabsProvider, Toaster } from "@contember/ui";
import { OutdatedApplicationChecker } from "./Application/OutdatedApplicationChecker.js";
import { ApplicationDevBar } from "./Dev/DevBar.js";
import { I18nProvider } from "../i18n/I18nProvider.js";
import { RoutingContext } from "../routing/RoutingContext.js";
import { RequestProvider } from "../routing/RequestContext.js";
import { NavigationProvider } from "./NavigationProvider/NavigationProvider.js";
import { IdentityProvider } from "./Identity/IdentityProvider.js";
import { projectEnvironmentExtension } from "./Project/ProjectEnvironmentExtension.js";
const validateProps = (props) => {
  if (typeof props.apiBaseUrl !== "string") {
    throw new Error(`The ENV variables haven't been set. Check your \`.env.development.local\` file.`);
  }
};
const ApplicationEntrypoint = (props) => {
  validateProps(props);
  const projectSlug = props.project === "__PROJECT_SLUG__" ? window.location.pathname.split("/")[1] : props.project;
  const basePath = props.basePath === "./" ? `/${projectSlug}/` : props.basePath ?? "/";
  const routing = {
    basePath,
    routes: props.routes ?? { index: { path: "/" } },
    defaultDimensions: props.defaultDimensions
  };
  const rootEnv = Environment.create().withVariables(props.envVariables).withDimensions(props.defaultDimensions ?? {});
  return /* @__PURE__ */ jsx(StyleProvider, { children: /* @__PURE__ */ jsx(EnvironmentContext.Provider, { value: rootEnv, children: /* @__PURE__ */ jsx(I18nProvider, { localeCode: props.defaultLocale, dictionaries: props.dictionaries, children: /* @__PURE__ */ jsx(RoutingContext.Provider, { value: routing, children: /* @__PURE__ */ jsx(RequestProvider, { children: /* @__PURE__ */ jsx(ToasterProvider, { children: /* @__PURE__ */ jsx(
    ContemberClient,
    {
      apiBaseUrl: props.apiBaseUrl,
      sessionToken: props.sessionToken,
      loginToken: props.loginToken,
      project: projectSlug,
      stage: props.stage,
      children: /* @__PURE__ */ jsx(EnvironmentExtensionProvider, { extension: projectEnvironmentExtension, state: projectSlug ?? null, children: /* @__PURE__ */ jsxs(DialogProvider, { children: [
        /* @__PURE__ */ jsx(NavigationProvider, { children: /* @__PURE__ */ jsxs(IdentityProvider, { onInvalidIdentity: props.onInvalidIdentity, children: [
          /* @__PURE__ */ jsx(OutdatedApplicationChecker, {}),
          /* @__PURE__ */ jsx(SectionTabsProvider, { children: props.children }),
          /* @__PURE__ */ jsx(ApplicationDevBar, { panels: props.devBarPanels })
        ] }) }),
        /* @__PURE__ */ jsx(Toaster, {})
      ] }) })
    }
  ) }) }) }) }) }) });
};
export {
  ApplicationEntrypoint
};
//# sourceMappingURL=ApplicationEntrypoint.js.map
