import r from "classnames";
import n from "react";
import "./accelbyte-widgets375.mjs";
import { EDITOR_PREVIEWER_ID as c } from "./accelbyte-widgets78.mjs";
import { SSRHelper as l } from "./accelbyte-widgets242.mjs";
import p from "react-dom";
import "react-feather";
import "./accelbyte-widgets517.mjs";
import "./accelbyte-widgets361.mjs";
import "./accelbyte-widgets319.mjs";
import "./accelbyte-widgets667.mjs";
function u() {
  return l.isSSR() ? null : document.createElement("div");
}
function i(o) {
  if (l.isSSR())
    return null;
  const e = o ? "editorModalWrapper" : "modal-root";
  let t = document.getElementById(e);
  return t || (t = document.createElement("div"), t.id = e, t.style.zIndex = "50", o ? h(t) : document.body.appendChild(t)), t;
}
function h(o) {
  const e = document.getElementById(c);
  e && e.appendChild(o);
}
class S extends n.Component {
  constructor(e) {
    super(e), this.modalRoot = i(this.props.isPreviewMode), this.containerElement = u();
  }
  componentDidMount() {
    this.modalRoot || (this.modalRoot = i()), this.modalRoot && this.containerElement && this.modalRoot.appendChild(this.containerElement);
  }
  componentWillUnmount() {
    this.modalRoot && this.containerElement && this.modalRoot.removeChild(this.containerElement);
  }
  renderModal() {
    const { overlayBackground: e, overlayClassName: t, children: a, className: d, dataQa: m } = this.props;
    return /* @__PURE__ */ n.createElement("div", { className: r("modalOverlay", t), style: e }, /* @__PURE__ */ n.createElement("section", { onClick: (s) => s.stopPropagation(), className: r("modalContainer", d), "data-qa-id": m }, a));
  }
  renderModalOverlay() {
    const { visible: e } = this.props;
    return e ? /* @__PURE__ */ n.createElement("div", { className: "modalOverlay editorModalOverlay" }, this.renderModal()) : /* @__PURE__ */ n.createElement("div", null);
  }
  render() {
    const { visible: e, isPreviewMode: t } = this.props;
    return t ? this.renderModalOverlay() : !e || !this.containerElement ? /* @__PURE__ */ n.createElement("div", null) : p.createPortal(this.renderModalOverlay(), this.containerElement);
  }
}
const b = (o) => /* @__PURE__ */ n.createElement("div", { className: r("body", o.className) }, o.children);
export {
  S as Modal,
  b as ModalBody
};
