import { jsx as e, jsxs as n } from "react/jsx-runtime";
import { useContext as g, useRef as E, useState as F, useEffect as u } from "react";
import { createPortal as T } from "react-dom";
import { W as $, N as j, c as D, d as M, e as P } from "./core-Da43q-pO.js";
const q = ({
  open: l,
  onClose: a,
  title: t,
  size: f = "md",
  children: h,
  footer: r,
  closeOnOverlay: y = !0,
  closeOnEscape: c = !0,
  fullscreenable: v,
  zIndex: d,
  className: _,
  style: N,
  displayStyle: i
}) => {
  const { t: b } = $(), p = g(j), m = E(null), [s, C] = F(!1), k = D("modal", i), w = M("modal", i);
  if (P(m, l), u(() => {
    if (!l || !c)
      return;
    const o = (L) => {
      L.key === "Escape" && a();
    };
    return document.addEventListener("keydown", o), () => document.removeEventListener("keydown", o);
  }, [l, c, a]), u(() => (l ? document.body.style.overflow = "hidden" : document.body.style.overflow = "", () => {
    document.body.style.overflow = "";
  }), [l]), !l || typeof document > "u")
    return null;
  const x = /* @__PURE__ */ e(
    "div",
    {
      className: "nice-modal-overlay",
      style: d ? { zIndex: d } : void 0,
      onClick: y ? a : void 0,
      children: /* @__PURE__ */ n(
        "div",
        {
          ref: m,
          className: `nice-modal nice-modal--${s ? "full" : f} nice-modal--ds-${w} ${_ || ""}`,
          style: { ...k, ...N },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": t,
          onClick: (o) => o.stopPropagation(),
          children: [
            t && /* @__PURE__ */ n("div", { className: "nice-modal__header", children: [
              /* @__PURE__ */ e("h2", { className: "nice-modal__title", children: t }),
              /* @__PURE__ */ n("div", { className: "nice-modal__header-actions", children: [
                v && /* @__PURE__ */ e(
                  "button",
                  {
                    type: "button",
                    className: "nice-modal__fullscreen",
                    onClick: () => C((o) => !o),
                    "aria-label": s ? "Exit fullscreen" : "Fullscreen",
                    children: s ? "⇲" : "⇱"
                  }
                ),
                /* @__PURE__ */ e(
                  "button",
                  {
                    type: "button",
                    className: "nice-modal__close",
                    onClick: a,
                    "aria-label": b("controls.close", "Close"),
                    children: /* @__PURE__ */ e(
                      "svg",
                      {
                        width: "24",
                        height: "24",
                        viewBox: "0 0 20 20",
                        fill: "currentColor",
                        "aria-hidden": "true",
                        children: /* @__PURE__ */ e("path", { d: "M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" })
                      }
                    )
                  }
                )
              ] })
            ] }),
            /* @__PURE__ */ e("div", { className: "nice-modal__body", children: h }),
            r && /* @__PURE__ */ e("div", { className: "nice-modal__footer", children: r })
          ]
        }
      )
    }
  );
  return T(x, p?.portalTarget ?? document.body);
};
export {
  q as N
};
