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