import { jsx as l } from "@emotion/react/jsx-runtime";
import { useModal as w } from "../../hooks/useModal/index.js";
import { useIsMobile as b } from "@m4l/graphics";
import { useStateRef as P } from "../../hooks/useStateRef/index.js";
import { Paper as S } from "@mui/material";
import { useSizeContainer as W } from "../../hooks/useSizeContainer/index.js";
import { DialogRootStyled as C, PaperModalDialogStyled as x } from "./slots/ModalDialogSlots.js";
import { DragResizeWindowRND as M } from "../DragResizeWindowRND/DragResizeWindowRND.js";
const D = (e, a) => (i) => {
  const n = W(e), { initialWidth: r, initialHeight: o = 100, maxWidth: t, maxHeight: s } = a;
  if (!e || !n)
    return null;
  const d = Math.max(0, window.innerWidth / 2 - (r ?? 100) / 2);
  return /* @__PURE__ */ l(
    M,
    {
      containerElement: e,
      containerSize: n,
      minWindowWidth: t,
      minWindowHeight: s,
      bounds: { left: 0, top: 0, right: 0, bottom: 0 },
      resizeHandles: ["se", "nw", "sw", "ne", "n", "e", "s", "w"],
      defaultPosition: {
        vertical: { height: o },
        horizontal: { left: d, width: r ?? 100 }
      },
      children: /* @__PURE__ */ l(x, { ...i, children: i.children })
    }
  );
}, H = (e) => /* @__PURE__ */ l(
  S,
  {
    ...e
  }
), V = () => {
  const {
    open: e,
    initialWidth: a = 600,
    initialHeight: i = 400,
    maxWidth: n,
    maxHeight: r,
    window: o,
    fullScreen: t,
    variant: s,
    isCloseable: d,
    closeModal: c
  } = w(), m = b(), [f, p] = P(null), h = {
    windowConfirmVariant: s
  }, u = typeof o == "function" ? o() : o, g = t || m ? H : D(f, {
    initialWidth: a,
    //Si la ventana del navegador es menor a la altura inicial, se utiliza ajusta para que sea menor a la ventana
    initialHeight: i,
    maxWidth: n,
    maxHeight: r
  });
  return /* @__PURE__ */ l(
    C,
    {
      isCloseable: d,
      closeModal: c,
      ref: p,
      role: "dialog-modal",
      "data-fullscreen": t || m ? "true" : "false",
      ownerState: h,
      open: e,
      fullScreen: t || m,
      "aria-labelledby": "child-modal-title",
      PaperComponent: g,
      disableEnforceFocus: !0,
      disableRestoreFocus: !0,
      children: u
    }
  );
};
export {
  V as ModalDialog
};
