import Vue from 'vue'

import { AlertPlugin, ConfirmPlugin, ToastPlugin } from 'vux'

Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(ToastPlugin)

// type:  success, warn, cancel, text
export const showToast = ({ type = 'success', text } = {}) => {
    Vue.$vux.toast.show({
        type,
        text
    })
}

export const showAlert = ({ title = '提示', content } = {}) => {
    return new Promise((resolve, reject) => {
        Vue.$vux.alert.show({
            title,
            content,
            onShow () {
                resolve('show')
            },
            onHide () {
                // eslint-disable-next-line prefer-promise-reject-errors
                reject('hide')
            }
        })
    })
}

export const showConfirm = ({ title = '提示', content, confirmText = '确认', cancelText = '取消', showCancelButton = true, showConfirmButton = true } = {}) => {
    return new Promise((resolve, reject) => {
        Vue.$vux.confirm.show({
            title,
            content,
            confirmText,
            cancelText,
            showCancelButton,
            showConfirmButton,
            onConfirm  () {
                resolve('confirm')
            },
            onCancel  () {
                // eslint-disable-next-line prefer-promise-reject-errors
                reject('cancel')
            }
        })
    })
}
