import type { App } from 'vue'

import cssinjs from './_util/cssinjs'
// 导入所有组件
import * as components from './components'

export * from './_util/cssinjs'
// 批量导出组件
export * from './components'
export { default as theme } from './theme'

// 创建安装函数
export function install(app: App) {
  Object.keys(components).forEach((key) => {
    const component = (components as Record<string, any>)[key]
    if (component.install) {
      app.use(component)
    }
  })
  app.use(cssinjs.StyleProvider)
  app.config.globalProperties.$message = components.message
  app.config.globalProperties.$notification = components.notification
  app.config.globalProperties.$destroyAll = components.Modal.destroyAll
  return app
}

export { cssinjs }

// 默认导出插件对象
export default {
  install,
}
