import { useEffect, useRef, useState } from "react";
function useModalFormState(isOpen, init, onReset) {
    const [state, setState] = useState(init);
    const initRef = useRef(init);
    initRef.current = init;
    const onResetRef = useRef(onReset);
    onResetRef.current = onReset;
    const wasOpenRef = useRef(false);
    useEffect(()=>{
        if (isOpen && !wasOpenRef.current) {
            setState(initRef.current());
            onResetRef.current?.();
        }
        wasOpenRef.current = isOpen;
    }, [
        isOpen
    ]);
    return [
        state,
        setState
    ];
}
export { useModalFormState };
