import MConfirm from "./m-confirm.vue"
import Vue from 'vue'


const ConfirmConstructor = Vue.extend(MConfirm)

export default function confirm({
    cancel,
    confirm,
    title,
    content,
    cancelTxt,
    confirmTxt,
    hideCancel
}) {
    let instance = new ConfirmConstructor({
        propsData: {
            title,
            content,
            cancelTxt,
            confirmTxt,
            hideCancel
        }
    })

    instance.cancel = () => {
        cancel && cancel();
        setTimeout(() => {
            close()
        }, 400);
    }
    instance.confirm = () => {
        if (confirm) {
            confirm()
        } else {
            setTimeout(() => {
                close()
            }, 400);
        }
    }

    instance.$mount();
    document.body.appendChild(instance.$el)

}