import { jsx as e } from "@emotion/react/jsx-runtime";
import y, { useMemo as c, useTransition as R, useState as F, useRef as S, createElement as b, useEffect as M } from "react";
import { WindowContainerComponentStyled as P } from "../../slots/WindowBaseSlots.js";
import { PropagateLoaderSpinner as x } from "../../../extended/React-Spinners/PropagateLoaderSpinner/PropagateLoaderSpinner.js";
import { useHostRuntime as E } from "../../../../contexts/HostRuntimeContext/HostRuntimeContext.js";
import { useShellObservability as g } from "../../../../contexts/ShellObservabilityContext/ShellObservabilityContext.js";
import { projectMFHostRuntimeTools as C } from "../../../MFLoader/helpers/projectMFHostRuntimeTools/projectMFHostRuntimeTools.js";
import { WindowToolsMFProvider as O } from "../../contexts/WindowToolsMFContext/WindowToolsMFContext.js";
import { DynamicMFParmsProvider as W } from "../../contexts/DynamicMFParmsContext/DynamicMFParmsContext.js";
import { MFObservabilityProvider as H } from "../../contexts/MFObservabilityContext/MFObservabilityContext.js";
import { MFHostRuntimeToolsProvider as N } from "../../contexts/MFHostRuntimeToolsContext/MFHostRuntimeToolsContext.js";
const j = (l) => {
  const { component: o, dynamicMFStore: a, windowTools: d, componentProps: i, emergeType: p } = l, s = E(), u = g(), f = c(() => C(s), [s]), [, w] = R(), [n, h] = F(!1), v = S(performance.now()), T = c(() => {
    if (!n)
      return null;
    const r = performance.now(), t = typeof o == "function" ? b(o, i) : o, m = performance.now() - r;
    return process.env.NODE_ENV === "development" && m > 100 && console.warn(`⚠️ WindowBase component rendering took ${m.toFixed(2)}ms`), t;
  }, [n, o, i]);
  return M(() => {
    w(() => {
      h(!0);
    });
    const r = setTimeout(() => {
      const t = performance.now() - v.current;
      process.env.NODE_ENV === "development" && t > 500 && console.warn(`⏱️ WindowBase total mount time: ${t.toFixed(2)}ms`);
    }, 0);
    return () => clearTimeout(r);
  }, []), /* @__PURE__ */ e(O, { ...d, children: /* @__PURE__ */ e(W, { store: a, children: /* @__PURE__ */ e(N, { value: f, children: /* @__PURE__ */ e(H, { value: u, children: /* @__PURE__ */ e(
    P,
    {
      ownerState: { emergeType: p },
      children: n ? (
        // Once the mount request committed, keep the local component visible.
        T
      ) : (
        // Keep the spinner only until the first component mount request commits.
        /* @__PURE__ */ e(
          "div",
          {
            style: {
              position: "absolute",
              display: "flex",
              justifyContent: "center",
              alignItems: "center",
              width: "100%",
              height: "100%",
              zIndex: 1e3
            },
            children: /* @__PURE__ */ e(x, {})
          }
        )
      )
    }
  ) }) }) }) });
};
y.memo(j);
export {
  j as WindowBaseComponent
};
