import { createElement } from "react";
import { Environment, EnvironmentContext } from "@contember/binding";
import { ContemberClient } from "@contember/react-client";
import { StyleProvider, ToasterProvider, DialogProvider, SectionTabsProvider, Toaster } from "@contember/ui";
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";
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__ */ createElement(StyleProvider, null, /* @__PURE__ */ createElement(EnvironmentContext.Provider, {
    value: rootEnv
  }, /* @__PURE__ */ createElement(I18nProvider, {
    localeCode: props.defaultLocale,
    dictionaries: props.dictionaries
  }, /* @__PURE__ */ createElement(RoutingContext.Provider, {
    value: routing
  }, /* @__PURE__ */ createElement(RequestProvider, null, /* @__PURE__ */ createElement(ToasterProvider, null, /* @__PURE__ */ createElement(ContemberClient, {
    apiBaseUrl: props.apiBaseUrl,
    sessionToken: props.sessionToken,
    loginToken: props.loginToken,
    project: projectSlug,
    stage: props.stage
  }, /* @__PURE__ */ createElement(DialogProvider, null, /* @__PURE__ */ createElement(NavigationProvider, null, /* @__PURE__ */ createElement(IdentityProvider, {
    onInvalidIdentity: props.onInvalidIdentity
  }, /* @__PURE__ */ createElement(SectionTabsProvider, null, props.children))), /* @__PURE__ */ createElement(Toaster, null)))))))));
};
export { ApplicationEntrypoint };
//# sourceMappingURL=ApplicationEntrypoint.js.map
