import { useEffect } from 'react';
import { useForm } from '../../../useForm';
export const useLogic = ({ validationSchema, defaultValues, mainFilters, quickFilters, secondaryFilters, isModalOpen, setIsModalOpen, onSubmit, form, }) => {
    const modalForm = useForm({
        validationSchema,
        defaultValues: form.getValues(),
    });
    const onCloseModal = () => {
        setIsModalOpen(false);
        modalForm.reset();
    };
    const onResetModal = () => {
        modalForm.reset(defaultValues);
    };
    const onSubmitModal = (submittedValues) => {
        onSubmit(submittedValues);
        setIsModalOpen(false);
    };
    useEffect(() => {
        if (isModalOpen) {
            modalForm.reset(form.getValues());
        }
    }, [isModalOpen]);
    return {
        modalForm,
        onCloseModal,
        onResetModal,
        onSubmitModal,
        mainFilters,
        quickFilters,
        secondaryFilters,
        isModalOpen,
    };
};
