import { h } from 'vue';
import { Dialog } from 'quasar';
import VnConfirm from 'components/ui/VnConfirm.vue';

export function useVnConfirm() {
    const openConfirmationModal = (
        title,
        message,
        promise,
        successFn,
        customHTML = {}
    ) => {
        const { component, props } = customHTML;
        Dialog.create({
            component: h(
                VnConfirm,
                {
                    title: title,
                    message: message,
                    promise: promise,
                },
                { customHTML: () => h(component, props) }
            ),
        }).onOk(async () => {
            if (successFn) successFn();
        });
    };

    return { openConfirmationModal };
}
