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

const AlertConstructor = Vue.extend(Alert)

function showAlert(message,type,duration = 5000){
    const instance = new AlertConstructor({
        propsData:{message,type,duration}
    })

    const vm = instance.$mount()
    document.body.appendChild(vm.$el)
    instance.$on('close',() => {
        document.body.removeChild(vm.$el)
        instance.$destroy()
    })
    return instance
}

export default {
    install(){
        Vue.prototype.$alert = showAlert
    }
}