import ButtonType from "../Button/ButtonTypes";
import ComponentLoader from "../ComponentLoader/ComponentLoader";
import ErrorMessage from "../ErrorMessage/ErrorMessage";
import BasicForm from "../Forms/BasicForm";
import Modal from "../Modal/Modal";
import React, { useEffect, useRef, useState } from "react";
const BasicFormModal = (props) => {
    const [isLoading, setIsLoading] = useState(Boolean(props.isLoading));
    const formRef = useRef(null);
    useEffect(() => {
        setIsLoading(Boolean(props.isLoading));
    }, [props.isLoading]);
    return (React.createElement(Modal, Object.assign({}, props, { submitButtonType: ButtonType.Submit, isLoading: isLoading, onSubmit: () => {
            formRef.current.submitForm();
        } }),
        React.createElement(React.Fragment, null,
            isLoading && React.createElement(ComponentLoader, null),
            props.error && React.createElement(ErrorMessage, { message: props.error }),
            !isLoading && (React.createElement(BasicForm, Object.assign({}, props.formProps, { hideSubmitButton: true, ref: formRef, onLoadingChange: (isFormLoading) => {
                    setIsLoading(isFormLoading);
                }, onSubmit: (data) => {
                    var _a;
                    (_a = props.onSubmit) === null || _a === void 0 ? void 0 : _a.call(props, data);
                } }))))));
};
export default BasicFormModal;
//# sourceMappingURL=BasicFormModal.js.map