import Confirm from "@/components/Confirm.vue"
import Vue from "vue"

const ConfirmConstructor = Vue.extend(Confirm)

function showConfirm(title,message,btnTxt){
    const instance = new ConfirmConstructor({
        propsData:{title,message,btnTxt}
    })

    const vm = instance.$mount()
    document.body.appendChild(vm.$el)
    return instance.open().then(result => {
    cleanup()
    return result
  })

  function cleanup() {
    document.body.removeChild(vm.$el)
    instance.$destroy()
  }
}

export default {
    install(){
        Vue.prototype.$confirm = showConfirm
    }
}