import { createVNode, render } from 'vue'
import MessageConstructor from './Message.vue'

const Message = function(options) {
  console.log(options)
  options = options || {}
  if (typeof options === 'string') {
    options = {
      message: options
    }
  }

  const vnode = createVNode(MessageConstructor, options)
  const container = document.createElement('div')
  render(vnode, container)
  document.body.appendChild(container)
  vnode.component.proxy.show()
}

Message.success = function(message, options) {
  console.log(message, options)
  return Message({
    message,
    type: 'success',
    ...options
  })
}

Message.warning = function(message, options) {
  return Message({
    message,
    type: 'warning',
    ...options
  })
}

Message.info = function(message, options) {
  return Message({
    message,
    type: 'info',
    ...options
  })
}

Message.error = function(message, options) {
  return Message({
    message,
    type: 'error',
    ...options
  })
}

export default Message