import Vue from 'vue'
const myvue = new Vue()
// 二次封装msgbox弹框
export function mymsgbox({
  msgboxtitle = '提示',
  msgboxtype = 'info',
  msgboxmessage = '是否提交？',
  msgboxshowCancelButton = true,
  msgboxconfirmButtonText = '确定',
  msgboxcancelButttonText = '取消',
  msgboxcloseOnClickModal = false,
  notifythentitle = '提交成功',
  notifythentype = 'success',
  notifythenduration = 2000
} = {}) {
  const dom = myvue.$createElement
  return new Promise((resolve, reject) => {
    myvue
      .$msgbox({
        title: msgboxtitle,
        type: msgboxtype,
        message: dom('p', null, [dom('span', null, msgboxmessage)]),
        showCancelButton: msgboxshowCancelButton,
        confirmButtonText: msgboxconfirmButtonText,
        cancelButttonText: msgboxcancelButttonText,
        closeOnClickModal: msgboxcloseOnClickModal,
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            // 点击确定
            resolve({ action, instance, done })
          } else {
            // 点击取消和 X 图标
            reject({ action, instance, done })
          }
        }
      })
      .then((cation) => {
        myvue.$notify({
          title: notifythentitle,
          type: notifythentype,
          duration: notifythenduration
        })
      })
      .catch((error) => {})
  })
}

// 二次封装Notification 弹出框
export function myNotification({ notifytitle = '错误', notifymessage = '', notifytype = 'error', notifyposition = 'top-right', notifyduration = 2000 } = {}) {
  myvue.$notify({
    title: notifytitle,
    message: notifymessage,
    type: notifytype,
    position: notifyposition,
    duration: notifyduration
  })
}

// element中notify和message所有弹窗的显示时长
export const popupduration = 2000
