import { Message } from 'element-ui'
let messageInstance = null
const resetMessage = options => {
  if (messageInstance) {
    messageInstance.close()
  }
  messageInstance = Message(options)
}
;['error', 'success', 'info', 'warning'].forEach(type => {
  resetMessage[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    switch (options.type) {
      case 'success':
        options.duration = 1000
        break
      case 'warning':
      case 'error':
        options.duration = 3000
        break
      default:
        options.duration = 3000
        break
    }
    return resetMessage(options)
  }
})
export const message = resetMessage
