import React from "react";
import JDmodal from "../modal/Modal";
import JDpreloader, { IPreloaderConfigProps } from "../preloader/Preloader";
import portalElement from "../../utils/portalElement";
import { createPortal } from "react-dom";
import { useModal } from "../../hooks/hook";

export interface IPreloaderModalProps extends IPreloaderConfigProps {}

const PreloaderModal: React.FC<IPreloaderModalProps> = ({ loading }) => {
  const modalHook = useModal();
  return createPortal(
    <JDmodal {...modalHook} isOpen={loading || false}>
      <JDpreloader loading={true} size="large" />
    </JDmodal>,
    portalElement()
  );
};

export default PreloaderModal;
