"use strict";

import React from 'react';
import { ModalBackground } from '../styledModalComponents';
import { useDispatch } from 'react-redux';
import { setActiveModal } from '../../../roomStore/chatSettingsSlice';
import { MODAL_TYPES } from '../../../helpers/constants/MODAL_TYPES';
import { MODAL_COMPONENTS } from '../../../helpers/constants/MODAL_COMPONENTS';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const Modal = ({
  children,
  modal,
  setOpenModal
}) => {
  const dispatch = useDispatch();
  const handleCloseModal = () => setOpenModal();
  const handleBackButtonClick = () => dispatch(setActiveModal(MODAL_TYPES.SETTINGS));
  const renderModalContent = () => {
    if (!modal) {
      return null;
    }
    const ModalComponent = MODAL_COMPONENTS[modal];
    if (!ModalComponent) {
      return null;
    }
    const handleClose = modal === MODAL_TYPES.MANAGE_DATA || modal === MODAL_TYPES.VISIBILITY || modal === MODAL_TYPES.REFERRALS || modal === MODAL_TYPES.DOCUMENT_SHARES || modal === MODAL_TYPES.PROFILE_SHARES || modal === MODAL_TYPES.BLOCKED_USERS ? handleBackButtonClick : handleCloseModal;
    return /*#__PURE__*/_jsx(ModalComponent, {
      handleCloseModal: handleClose
    });
  };
  return modal && /*#__PURE__*/_jsxs(ModalBackground, {
    id: "modal-background",
    style: {
      position: 'absolute',
      top: 0,
      left: 0,
      right: 0,
      bottom: 0
    },
    children: [renderModalContent(), children]
  });
};
export default Modal;
//# sourceMappingURL=Modal.js.map