import { ref } from "vue";
import type { QForm } from "quasar"


export const useExpenseForm = () => {
    const formRef     = ref<QForm | null>(null);
    const triedSubmit = ref(false);

    const validateAnd = async (fn: ()=> void | Promise<void>) => {
        triedSubmit.value = true;
        const ok = await formRef.value?.validate(true);
        if(!ok) return false;
        await fn();
        return true;
    };

    return { 
        formRef,
        validateAnd,
    };
}