import { jsx as m } from "@emotion/react/jsx-runtime";
import R from "react";
import { MemonizedWindowBaseMicroFrontend as C } from "../../../../../../../WindowBase/subcomponents/MicroFrontend/MicroFrontend.js";
import { WindowBaseComponent as D } from "../../../../../../../WindowBase/subcomponents/Component/index.js";
import { TEST_PROP_ID as N } from "../../../../../../../../test/constants_no_mock.js";
import { getNameDataTestId as $ } from "../../../../../../../../test/getNameDataTestId.js";
import { AREAS_VIEWER_CLASS_NAME as k } from "../../../../../../constants.js";
import { useWindow as P } from "./hooks/useWindow.js";
import { WindowBaseStyled as b } from "../../../../slots/AreasViewerSlots.js";
import { shallow as l } from "zustand/shallow";
import { useAreasStore as c } from "../../../../../../hooks/useAreas/index.js";
const F = (p) => {
  const { areaId: e, windowId: r } = p, {
    emergeType: i,
    moduleId: u,
    winType: f,
    title: w,
    subTitle: I,
    editionInfo: T,
    iconUrl: A,
    version: h,
    buildTime: y,
    moduleCount: d,
    selected: E,
    mfProps: S,
    component: g,
    loading: B,
    status: s,
    dynamicMFStore: a,
    windowTools: t,
    onTouch: W,
    memoizedActions: _,
    loggedUser: v
  } = P(r, e), x = c(
    (n) => e ? n.hashAreas[e]?.maximizedId : void 0,
    l
  ), z = c(
    (n) => {
      const o = e ? n.hashAreas[e] : void 0;
      return o && o.currentBreakpoint && o.layouts && o.layouts[o.currentBreakpoint] && o.layouts[o.currentBreakpoint].find(
        (M) => M.i === r
      )?.colapsed || !1;
    },
    l
  );
  return s === void 0 ? null : /* @__PURE__ */ m(
    b,
    {
      title: `${w}${d ? `:${d}` : ""}`,
      subTitle: I,
      editionInfo: T,
      iconUrl: A,
      isLoading: B,
      onClose: () => t.close(),
      version: h,
      buildTime: y,
      actions: _,
      windowId: r,
      selected: E,
      maximized: !!x,
      onMouseDown: W,
      emergeType: i,
      collapsed: z,
      ...process.env.NODE_ENV !== "production" ? {
        [N]: $(
          k,
          "windowRoot",
          `${i}`
        )
      } : {},
      children: s === "loaded" ? f === "microfrontend" ? /* @__PURE__ */ m(
        C,
        {
          emergeType: i,
          moduleId: u,
          dynamicMFStore: a,
          windowTools: t,
          loggedUser: v,
          ...S
        }
      ) : /* @__PURE__ */ m(
        D,
        {
          id: r,
          emergeType: i,
          dynamicMFStore: a,
          windowTools: t,
          component: g
        }
      ) : null
    }
  );
};
R.memo(F);
export {
  F as Window
};
