import classNames from "classnames";
import React, { useContext, useState } from "react";
import { RicosContext } from "./../../ricos-context/index.js";
import { FocusManager } from "./../../_shared/focus-manager/focus-manager.js";
import { UiComponentsProvider } from "./../../ui-components/index.js";
import styles from "../statics/styles/drawer-scss.js";
const Dialog = ({ children, closeModal, zIndex, modalConfig }) => {
  const onModalClick = (e) => e.stopPropagation();
  const onOverlayClick = (e) => {
    if (modalConfig.onClickOutside && typeof modalConfig.onClickOutside === "function") {
      modalConfig.onClickOutside(e);
      return;
    }
    closeModal();
  };
  const { jsdomMode } = useContext(RicosContext);
  const [ref, setRef] = useState(null);
  return /* @__PURE__ */ React.createElement(
    FocusManager,
    {
      focusTrapOptions: {
        returnFocusOnDeactivate: false
      },
      jsdomMode
    },
    /* @__PURE__ */ React.createElement("div", { onClick: onOverlayClick, className: styles.overlay, style: { zIndex }, tabIndex: 0 }, /* @__PURE__ */ React.createElement(
      "div",
      {
        onClick: onModalClick,
        className: classNames(styles.content, styles.dialog),
        ref: setRef
      },
      ref && /* @__PURE__ */ React.createElement(UiComponentsProvider, { containerEl: ref }, React.cloneElement(React.Children.only(children)))
    ))
  );
};
export {
  Dialog
};
//# sourceMappingURL=dialog.js.map
