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