import { jsx as t } from "@emotion/react/jsx-runtime";
import { forwardRef as eo, useRef as no, useEffect as to, useMemo as io } from "react";
import { shallow as p } from "zustand/shallow";
import { usePopupsStore as i } from "../../../PopupsProvider/hooks/usePopupsStore.js";
import { PopupDragWindowRootStyled as ro } from "../../slots/popupsViewerSlots.js";
import { usePopups as so } from "../../../PopupsProvider/hooks/usePopups.js";
import { TEST_PROP_ID as po } from "../../../../../../test/constants_no_mock.js";
import { POPUPS_VIEWER_CLASS_NAME as mo } from "../../constants.js";
import { getNameDataTestId as ao } from "../../../../../../test/getNameDataTestId.js";
import { MemonizedWindowBaseMicroFrontend as lo } from "../../../../../WindowBase/subcomponents/MicroFrontend/MicroFrontend.js";
import { WindowBaseComponent as uo } from "../../../../../WindowBase/subcomponents/Component/index.js";
import { deepShallow as co } from "../../../../../../utils/deepShallow.js";
import { WindowBase as fo } from "../../../../../WindowBase/WindowBase.js";
const Eo = eo((z, b) => {
  const { popupId: o, containerElement: R, containerSize: T, style: x, onResizeStart: C, onResizeStop: D, onDragStart: y, onDragStop: E, loggedUser: m } = z, n = i((e) => e.hashPopups[o], co), { bringPopupOnFront: I } = i((e) => e.popupsActions, p), { close: M } = i((e) => e.popupActions, p), a = no(null), { collapsed: W, maximized: V } = i(
    (e) => ({
      collapsed: e.hashPopups[o]?.collapsed || !1,
      maximized: e.hashPopups[o]?.maximized || !1
    }),
    p
  ), {
    moduleId: d,
    winType: l,
    title: _,
    iconUrl: A,
    dynamicMFStore: r,
    windowTools: s,
    mfProps: u,
    component: c,
    componentProps: f,
    //onTouch,
    memoizedActions: v,
    loading: H,
    version: N,
    status: O,
    subTitle: w,
    buildTime: B,
    editionInfo: h,
    zIndex: g,
    variant: F = "normal",
    draggable: L = !0,
    resizable: U = !0,
    defaultPosition: j,
    bounds: k,
    onMouseDown: P,
    allowHeightResizeContainer: q,
    allowWidthResizeContainer: G,
    maxHeight: J,
    maxWidth: K,
    minHeight: Q,
    minWidth: X,
    selected: Y,
    ...S
  } = so(o), Z = {
    status: O,
    variant: F,
    subTitle: w,
    editionInfo: h,
    zIndex: g,
    collapsed: W,
    maximized: V
  }, $ = (e) => {
    I(o), P && P(e);
  };
  to(() => {
    n.enforceVisibleCount && n.enforceVisibleCount > 0 && a.current?.ensureVisible();
  }, [n.enforceVisibleCount, o]);
  const oo = io(() => l === "microfrontend" ? /* @__PURE__ */ t(
    lo,
    {
      emergeType: "popup",
      moduleId: d,
      dynamicMFStore: r,
      windowTools: s,
      loggedUser: m,
      ...u ?? { debugPort: 0, prefix: "" }
    }
  ) : /* @__PURE__ */ t(
    uo,
    {
      id: o,
      emergeType: "popup",
      dynamicMFStore: r,
      windowTools: s,
      component: c,
      componentProps: f
    }
  ), [l, c, f, d, r, s, m, u, o]);
  return n ? /* @__PURE__ */ t(
    ro,
    {
      ownerState: Z,
      windowRef: b,
      ref: a,
      onResizeStart: C,
      onResizeStop: D,
      onDragStart: y,
      onDragStop: E,
      hidden: n.status === "hidden",
      onMouseDown: $,
      containerElement: R,
      containerSize: T,
      bounds: k,
      draggable: L,
      resizable: U,
      defaultPosition: j,
      style: { ...x, zIndex: g },
      allowHeightResizeContainer: q,
      allowWidthResizeContainer: G,
      maxHeight: J,
      maxWidth: K,
      minHeight: Q,
      minWidth: X,
      ...S,
      children: /* @__PURE__ */ t(
        fo,
        {
          ...S,
          version: N,
          onClose: () => M(o),
          title: _ ?? "",
          subTitle: w,
          iconUrl: A,
          editionInfo: h,
          actions: v,
          isLoading: H,
          windowId: o,
          selected: Y,
          emergeType: "popup",
          variant: "outlined",
          buildTime: B,
          ...process.env.NODE_ENV !== "production" ? {
            [po]: ao(
              mo,
              "root"
            )
          } : {},
          children: oo
        }
      )
    }
  ) : null;
});
export {
  Eo as Popup
};
