import { createApp } from 'vue'
import point from './components/point.vue'
import message from './components/message.vue'
import vuetify from '@/plugins/vuetify'

// Curtain('point', { message: '遮帘弹窗通知！' })

const toastMessage  = (type, options)  => {
  const componentName = type === 'point' ? point : type === 'message' ? message : null

  const rootNode = document.createElement("div")
  document.querySelector('.v-application').appendChild(rootNode)
  const app = createApp(componentName, options)
  app.use(vuetify)
  app.mount(rootNode)
  const { timeout } = options || {}
  if ((timeout - 0)) {
    setTimeout(() => {
      app.unmount()
      rootNode.remove()
    }, (timeout-0))
  }
}

// toastMessage.point = (options) => {
//   toastMessage('point', options)
// }

// 注册插件app.use()会自动执行install函数
toastMessage.install = (app) => {
  app.config.globalProperties.Curtain = toastMessage
}

export default toastMessage
