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 { jsxDEV } from "react/jsx-dev-runtime";
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";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/ApplicationEntrypoint.tsx";
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__ */ jsxDEV(StyleProvider, {
    children: /* @__PURE__ */ jsxDEV(EnvironmentContext.Provider, {
      value: rootEnv,
      children: /* @__PURE__ */ jsxDEV(I18nProvider, {
        localeCode: props.defaultLocale,
        dictionaries: props.dictionaries,
        children: /* @__PURE__ */ jsxDEV(RoutingContext.Provider, {
          value: routing,
          children: /* @__PURE__ */ jsxDEV(RequestProvider, {
            children: /* @__PURE__ */ jsxDEV(ToasterProvider, {
              children: /* @__PURE__ */ jsxDEV(ContemberClient, {
                apiBaseUrl: props.apiBaseUrl,
                sessionToken: props.sessionToken,
                loginToken: props.loginToken,
                project: projectSlug,
                stage: props.stage,
                children: /* @__PURE__ */ jsxDEV(EnvironmentExtensionProvider, {
                  extension: projectEnvironmentExtension,
                  state: projectSlug ?? null,
                  children: /* @__PURE__ */ jsxDEV(DialogProvider, {
                    children: [/* @__PURE__ */ jsxDEV(NavigationProvider, {
                      children: /* @__PURE__ */ jsxDEV(IdentityProvider, {
                        onInvalidIdentity: props.onInvalidIdentity,
                        children: [/* @__PURE__ */ jsxDEV(OutdatedApplicationChecker, {}, void 0, false, {
                          fileName: _jsxFileName,
                          lineNumber: 67,
                          columnNumber: 14
                        }, void 0), /* @__PURE__ */ jsxDEV(SectionTabsProvider, {
                          children: props.children
                        }, void 0, false, {
                          fileName: _jsxFileName,
                          lineNumber: 68,
                          columnNumber: 14
                        }, void 0)]
                      }, void 0, true, {
                        fileName: _jsxFileName,
                        lineNumber: 66,
                        columnNumber: 13
                      }, void 0)
                    }, void 0, false, {
                      fileName: _jsxFileName,
                      lineNumber: 65,
                      columnNumber: 12
                    }, void 0), /* @__PURE__ */ jsxDEV(Toaster, {}, void 0, false, {
                      fileName: _jsxFileName,
                      lineNumber: 73,
                      columnNumber: 12
                    }, void 0)]
                  }, void 0, true, {
                    fileName: _jsxFileName,
                    lineNumber: 64,
                    columnNumber: 11
                  }, void 0)
                }, void 0, false, {
                  fileName: _jsxFileName,
                  lineNumber: 63,
                  columnNumber: 10
                }, void 0)
              }, void 0, false, {
                fileName: _jsxFileName,
                lineNumber: 56,
                columnNumber: 9
              }, void 0)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 55,
              columnNumber: 8
            }, void 0)
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 54,
            columnNumber: 7
          }, void 0)
        }, void 0, false, {
          fileName: _jsxFileName,
          lineNumber: 53,
          columnNumber: 6
        }, void 0)
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 52,
        columnNumber: 5
      }, void 0)
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 51,
      columnNumber: 4
    }, void 0)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 50,
    columnNumber: 3
  }, void 0);
};
export {
  ApplicationEntrypoint
};
//# sourceMappingURL=ApplicationEntrypoint.js.map
