"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledModalComponents = require("../styledModalComponents");
var _reactRedux = require("react-redux");
var _chatSettingsSlice = require("../../../roomStore/chatSettingsSlice");
var _MODAL_TYPES = require("../../../helpers/constants/MODAL_TYPES");
var _MODAL_COMPONENTS = require("../../../helpers/constants/MODAL_COMPONENTS");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Modal = ({
  children,
  modal,
  setOpenModal
}) => {
  const dispatch = (0, _reactRedux.useDispatch)();
  const handleCloseModal = () => setOpenModal();
  const handleBackButtonClick = () => dispatch((0, _chatSettingsSlice.setActiveModal)(_MODAL_TYPES.MODAL_TYPES.SETTINGS));
  const renderModalContent = () => {
    if (!modal) {
      return null;
    }
    const ModalComponent = _MODAL_COMPONENTS.MODAL_COMPONENTS[modal];
    if (!ModalComponent) {
      return null;
    }
    const handleClose = modal === _MODAL_TYPES.MODAL_TYPES.MANAGE_DATA || modal === _MODAL_TYPES.MODAL_TYPES.VISIBILITY || modal === _MODAL_TYPES.MODAL_TYPES.REFERRALS || modal === _MODAL_TYPES.MODAL_TYPES.DOCUMENT_SHARES || modal === _MODAL_TYPES.MODAL_TYPES.PROFILE_SHARES || modal === _MODAL_TYPES.MODAL_TYPES.BLOCKED_USERS ? handleBackButtonClick : handleCloseModal;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(ModalComponent, {
      handleCloseModal: handleClose
    });
  };
  return modal && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styledModalComponents.ModalBackground, {
    id: "modal-background",
    style: {
      position: 'absolute',
      top: 0,
      left: 0,
      right: 0,
      bottom: 0
    },
    children: [renderModalContent(), children]
  });
};
var _default = exports.default = Modal;
//# sourceMappingURL=Modal.js.map