import { jsx as e, jsxs as r } from "react/jsx-runtime";
import { $ as g, n as $, c as E, l as F, A as j } from "./core-Dpfb_THi.js";
import { useContext as A, useRef as M, useState as P, useEffect as u } from "react";
import { createPortal as R } from "react-dom";
const z = ({
  open: l,
  onClose: o,
  title: t,
  size: f = "md",
  children: h,
  footer: s,
  closeOnOverlay: v = !0,
  closeOnEscape: c = !0,
  fullscreenable: y,
  zIndex: d,
  className: _,
  style: b,
  displayStyle: i
}) => {
  const { t: N } = g(), k = A($), m = M(null), [n, p] = P(!1), w = E("modal", i), x = F("modal", i);
  if (j(m, l), u(() => {
    if (!l || !c)
      return;
    const a = (L) => {
      L.key === "Escape" && o();
    };
    return document.addEventListener("keydown", a), () => document.removeEventListener("keydown", a);
  }, [l, c, o]), u(() => (l ? document.body.style.overflow = "hidden" : document.body.style.overflow = "", () => {
    document.body.style.overflow = "";
  }), [l]), !l || typeof document > "u")
    return null;
  const C = /* @__PURE__ */ e(
    "div",
    {
      className: "nice-modal-overlay",
      style: d ? { zIndex: d } : void 0,
      onClick: v ? o : void 0,
      children: /* @__PURE__ */ r(
        "div",
        {
          ref: m,
          className: `nice-modal nice-modal--${n ? "full" : f} nice-modal--ds-${x} ${_ || ""}`,
          style: { ...w, ...b },
          role: "dialog",
          "aria-modal": "true",
          "aria-label": t,
          onClick: (a) => a.stopPropagation(),
          children: [
            t && /* @__PURE__ */ r("div", { className: "nice-modal__header", children: [
              /* @__PURE__ */ e("h2", { className: "nice-modal__title", children: t }),
              /* @__PURE__ */ r("div", { className: "nice-modal__header-actions", children: [
                y && /* @__PURE__ */ e(
                  "button",
                  {
                    type: "button",
                    className: "nice-modal__fullscreen",
                    onClick: () => p((a) => !a),
                    "aria-label": n ? "Exit fullscreen" : "Fullscreen",
                    children: n ? "⇲" : "⇱"
                  }
                ),
                /* @__PURE__ */ e(
                  "button",
                  {
                    type: "button",
                    className: "nice-modal__close",
                    onClick: o,
                    "aria-label": N("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 }),
            s && /* @__PURE__ */ e("div", { className: "nice-modal__footer", children: s })
          ]
        }
      )
    }
  );
  return R(C, k?.portalTarget ?? document.body);
};
export {
  z as N
};
