"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const reactClient = require("@contember/react-client");
const ui = require("@contember/ui");
const reactI18n = require("@contember/react-i18n");
const OutdatedApplicationChecker = require("./Application/OutdatedApplicationChecker.cjs");
const DevBar = require("./Dev/DevBar.cjs");
const DataViewPageNameKeyProvider = require("./DataViewPageNameKeyProvider.cjs");
const reactIdentity = require("@contember/react-identity");
const NavigationProvider = require("./NavigationProvider/NavigationProvider.cjs");
const IdentityProvider = require("./Identity/IdentityProvider.cjs");
const reactRouting = require("@contember/react-routing");
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 = reactBinding.Environment.create().withVariables(props.envVariables).withDimensions(props.defaultDimensions ?? {});
  const Providers = props.providers ?? ui.Providers;
  return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.EnvironmentContext.Provider, { value: rootEnv, children: /* @__PURE__ */ jsxRuntime.jsx(reactI18n.I18nProvider, { localeCode: props.defaultLocale, dictionaries: props.dictionaries, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouting.RoutingContext.Provider, { value: routing, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouting.RequestProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
    reactClient.ContemberClient,
    {
      apiBaseUrl: props.apiBaseUrl,
      sessionToken: props.sessionToken,
      loginToken: props.loginToken,
      project: projectSlug,
      stage: props.stage,
      children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.EnvironmentExtensionProvider, { extension: reactIdentity.projectEnvironmentExtension, state: projectSlug ?? null, children: /* @__PURE__ */ jsxRuntime.jsx(DataViewPageNameKeyProvider.DataViewPageNameKeyProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(NavigationProvider.NavigationProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(IdentityProvider.IdentityProvider, { onInvalidIdentity: props.onInvalidIdentity, children: /* @__PURE__ */ jsxRuntime.jsxs(Providers, { portalProviderProps: props.portalProviderProps, styleProviderProps: props.styleProviderProps, children: [
        /* @__PURE__ */ jsxRuntime.jsx(OutdatedApplicationChecker.OutdatedApplicationChecker, {}),
        props.children,
        /* @__PURE__ */ jsxRuntime.jsx(DevBar.ApplicationDevBar, { panels: props.devBarPanels })
      ] }) }) }) }) })
    }
  ) }) }) }) });
};
exports.ApplicationEntrypoint = ApplicationEntrypoint;
//# sourceMappingURL=ApplicationEntrypoint.cjs.map
