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