import { jsx as o } from "@emotion/react/jsx-runtime";
import f, { useCallback as p } from "react";
import { useAreasStore as c } from "../../../../../../hooks/useAreas/index.js";
import { Window as h } from "../Window/Window.js";
import { useIsMobile as u } from "@m4l/graphics";
import { WrapperWindowModalStyled as g } from "../../../../slots/AreasViewerSlots.js";
import { useStateRef as b } from "../../../../../../../../hooks/useStateRef/index.js";
import { DragResizeWindowRND as R } from "../../../../../../../DragResizeWindowRND/DragResizeWindowRND.js";
import { Dialog as M } from "../../../../../../../extended/mui/Dialog/Dialog.js";
const y = f.forwardRef(
  (t, e) => /* @__PURE__ */ o(M, { ref: e, ...t })
), z = (t) => {
  const { windowId: e } = t, { onClose: r } = c((i) => i.hashWindows[e]), { width: d = 400, height: a = 200, minWindowWidth: l = 400, minWindowHeight: s = 200 } = c(
    (i) => i.hashWindows[e].emergeType === "modal" ? i.hashWindows[e].modalProps : {
      width: 400,
      height: 200,
      minWindowWidth: 400,
      minWindowHeight: 200
    }
  ), m = u(), [n, w] = b(null), W = p(() => n ? /* @__PURE__ */ o(
    R,
    {
      containerElement: n ?? void 0,
      containerSize: {
        containerWidth: n.clientWidth,
        containerHeight: n.clientHeight
      },
      minWindowWidth: l,
      minWindowHeight: s,
      bounds: { left: 0, top: 0, right: 0, bottom: 0 },
      resizeHandles: ["se", "nw", "sw", "ne", "n", "e", "s", "w"],
      defaultPosition: {
        vertical: { height: a },
        horizontal: { width: d }
      },
      children: /* @__PURE__ */ o(h, { windowId: e, areaId: void 0 })
    }
  ) : null, [n, e, l, s, a, d]);
  return /* @__PURE__ */ o(
    y,
    {
      open: !0,
      scroll: "paper",
      onKeyDown: (i) => {
        i.key === "Escape" && r?.(e);
      },
      "aria-labelledby": "child-modal-title",
      "aria-describedby": "child-modal-description",
      maxWidth: !1,
      fullWidth: m,
      fullScreen: !1,
      disableEnforceFocus: !0,
      onClose: r,
      children: /* @__PURE__ */ o(
        g,
        {
          ref: w,
          children: m ? /* @__PURE__ */ o(h, { ...t }) : /* @__PURE__ */ o(W, {})
        }
      )
    }
  );
}, k = f.memo(z);
export {
  k as AreaMemonizedWindowModal,
  z as AreaWindowModal
};
