import { ElMessageBox, ElMessage } from 'element-plus'
import { h } from 'vue'

export const MsgSuccess = (message) => {
  ElMessage.success({
    message: message,
    type: 'success',
    // showClose: true,
    duration: 3000
  })
}

export const MsgInfo = (message) => {
  ElMessage.info({
    message: message,
    type: 'info',
    // showClose: true,
    duration: 3000
  })
}

export const MsgWarning = (message) => {
  ElMessage.warning({
    message: message,
    type: 'warning',
    // showClose: true,
    duration: 3000
  })
}

export const MsgError = (message) => {
  ElMessage.error({
    message: message,
    type: 'error',
    showClose: true,
    duration: 3000
  })
}

export const MsgAlert = (title, description, options) => {
  const defaultOptions = {
    confirmButtonText: '确认',
    ...options
  }
  return ElMessageBox.alert(description, title, defaultOptions)
}

/**
 * 删除知识库
 * @param 参数 message: {title, description,type}
 */

export const MsgConfirm = (title, description, options) => {
  const defaultOptions = {
    showCancelButton: true,
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    ...options
  }
  return ElMessageBox.confirm(description, title, defaultOptions)
}


/** 定制化弹框 */
export const MsgConfirmCustom = (title, description , options) => {
  const defaultOptions = {
    showCancelButton: true,
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    dangerouslyUseHTMLString: true,
    customClass: 'msg-box-custom',
    ...options
  }
  const des = h('div', {}, [
    h('p', {}, description)
  ])
  // 去掉默认类型
  if(defaultOptions?.type) delete defaultOptions.type
  return ElMessageBox.confirm(
    des,  
    title, 
     defaultOptions
  )
}

