import { jsx as o, jsxs as g } from "@emotion/react/jsx-runtime";
import { useMemo as h, useCallback as A, useId as X } from "react";
import { unstable_HistoryRouter as Y } from "react-router-dom";
import { createBrowserHistory as oo } from "history";
import eo from "eventemitter3";
import _ from "nprogress";
import { DeviceTypeProvider as to, ThemeSettingsProvider as ro, LocalesProvider as so, getLocaleFromNetwork as io, AppearanceComponentProvider as no } from "@m4l/graphics";
import { axiosOperation as ao, EnvironmentProvider as mo, HostToolsProvider as lo, NetworkProvider as po, AuthProvider as co, useAuth as ho, useEnvironment as uo, useNetwork as vo } from "@m4l/core";
import { WrapperAppBarContentChildrenStyled as fo, WrapperContentChildrenStyled as Ao } from "./slots/MFIsolationAppSlots.js";
import { MFIsolationAppErrorBoundary as _o } from "./MFIsolationAppErrorBoundary.js";
import Po from "../ToastContainer/helpers/toaster.js";
import { ShellObservabilityProvider as Io } from "../../contexts/ShellObservabilityContext/ShellObservabilityContext.js";
import { MFAuthApp as bo } from "./subcomponents/MFAuthApp/MFAuthApp.js";
import { BaseModule as yo } from "../BaseModule/BaseModule.js";
import { SettingsLayout as ko } from "../SettingsLayout/SettingsLayout.js";
import { ToastContainer as wo } from "../ToastContainer/ToastContainer.js";
import { PopupsProvider as go } from "../popups/components/PopupsProvider/contexts/PopupsContext/PopupsContext.js";
import { AreasProvider as Ro } from "../areas/contexts/AreasContext/index.js";
import { AppBarSettings as Fo } from "./subcomponents/AppBarSettings/AppBarSettings.js";
import { HostRuntimeProvider as Lo } from "../../contexts/HostRuntimeContext/HostRuntimeContext.js";
import { MFObservabilityProvider as So } from "../WindowBase/contexts/MFObservabilityContext/MFObservabilityContext.js";
const R = oo({ window });
function Co(u) {
  const { children: v, hostRuntime: s, resolveHostRuntime: i } = u, { user: n } = ho(), {
    database: a,
    hostApiIcons: m,
    hostApiLocal: l,
    hostApiRemote: p
  } = uo(), { networkOperation: d } = vo(), f = h(() => i ? i({
    database: a,
    hostApiIcons: m,
    hostApiLocal: l,
    hostApiRemote: p,
    networkOperation: d,
    sessionId: n?.sessionId
  }) ?? s : s, [
    a,
    m,
    l,
    p,
    s,
    d,
    i,
    n?.sessionId
  ]);
  return /* @__PURE__ */ o(Lo, { value: f, children: v });
}
function Xo(u) {
  const {
    children: v,
    user: s,
    pwd: i,
    database: n = "domain",
    // 'domain
    hostApiLocal: a,
    host_api_local: m,
    hostApiIcons: l,
    host_api_icons: p,
    hostApiRemote: d,
    host_api_remote: f,
    host_static_assets: F,
    environment_assets: L,
    moduleId: P,
    skeletonFlags: S,
    moduleNameField: C,
    privileges: E,
    componentsDictionary: M,
    onLoad: T,
    activeAreasNetwork: x = !1,
    activeCookiesFromNetwork: H = !1,
    // observedDivRef,
    moduleDictionaryLoaded: N,
    forcedDeviceType: B,
    areasStoreId: I,
    areasStoreDevtoolsEnabled: b,
    appBarSettings: D = !0,
    axiosOperation: O = ao,
    googleMapsApiKey: j,
    hostRuntime: W,
    observability: y,
    resolveHostRuntime: $
  } = u, k = a ?? m ?? "", c = d ?? f ?? "", K = l ?? p ?? `${c}/main/icons`, e = h(() => new eo(), []), Z = A(
    (t, r) => {
      e.on(t, r);
    },
    [e]
  ), q = A(
    (t, r) => {
      if (r === null) {
        e.removeListener(t);
        return;
      }
      e.removeListener(t, r);
    },
    [e]
  ), z = A(
    (t, r) => {
      e.emit(t, r);
    },
    [e]
  ), G = () => {
    _.configure({
      showSpinner: !0
    }), _.start();
  }, J = () => {
    _.done();
  }, Q = h(
    () => ({
      host: "",
      isLocalhost: !0,
      domain_token: "lab1",
      domainToken: "lab1",
      database: n,
      host_api_local: k,
      hostApiLocal: k,
      host_api_remote: c,
      hostApiRemote: c,
      hostRemote: c,
      host_static_assets: F,
      environment_assets: L,
      hostApiIcons: K,
      googleMapsApiKey: j
    }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    []
  ), w = X(), U = Po(w), V = h(
    () => ({
      history: R,
      toast: U,
      startProgress: G,
      stopProgress: J,
      events_add_listener: Z,
      events_remove_listener: q,
      events_emit: z
    }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    []
  );
  return /* @__PURE__ */ o(mo, { ...Q, children: /* @__PURE__ */ o(lo, { ...V, children: /* @__PURE__ */ o(po, { axiosOperation: O, children: /* @__PURE__ */ o(Io, { value: y, children: /* @__PURE__ */ o(So, { value: y, children: /* @__PURE__ */ o(
    Y,
    {
      history: R,
      future: { v7_startTransition: !0, v7_relativeSplatPath: !0 },
      children: /* @__PURE__ */ o(to, { forcedDeviceType: B, children: /* @__PURE__ */ o(co, { children: /* @__PURE__ */ o(bo, { user: s, pwd: i, children: /* @__PURE__ */ o(ro, { children: /* @__PURE__ */ o(so, { isMicroFrontEnd: !1, getLocaleFromNetwork: io, children: /* @__PURE__ */ o(
        yo,
        {
          moduleId: P,
          privileges: E,
          skeletonFlags: S,
          componentsDictionary: M,
          moduleNameField: C,
          moduleDictionaryLoaded: N,
          children: /* @__PURE__ */ o(_o, { moduleId: P, children: /* @__PURE__ */ g(no, { children: [
            /* @__PURE__ */ o(ko, {}),
            /* @__PURE__ */ o(wo, { containerId: w }),
            " ",
            /* @__PURE__ */ o(
              Co,
              {
                hostRuntime: W,
                resolveHostRuntime: $,
                children: /* @__PURE__ */ o(
                  go,
                  {
                    baseZindex: 1e3,
                    storeId: I,
                    storeDevtoolsEnabled: b,
                    children: /* @__PURE__ */ o(
                      Ro,
                      {
                        storeId: I,
                        storeDevtoolsEnabled: b,
                        onLoad: T,
                        loadAreasFromNetwork: x,
                        loadCookiesFromNetwork: H,
                        children: /* @__PURE__ */ g(fo, { children: [
                          D && /* @__PURE__ */ o(Fo, {}),
                          /* @__PURE__ */ o(Ao, { children: v })
                        ] })
                      }
                    )
                  }
                )
              }
            )
          ] }) })
        }
      ) }) }) }) }) })
    }
  ) }) }) }) }) });
}
export {
  Xo as MFIsolationApp
};
