// 引入unocss css
import '@/plugins/unocss'

import '@/assets/css-vars.css'
import '@/components/mt-edit/assets/css/custom_ani.css'
import 'animate.css'
import 'virtual:svg-icons-register'

// 导入全局的svg图标
import '@/plugins/svgIcon'

import VueTianditu from 'vue-tianditu'

// 初始化多语言
import { setupI18n } from '@/plugins/vueI18n'

// 引入状态管理
import { setupStore } from '@/store'

// 全局组件
import { setupGlobCom } from '@/components'

// 引入 element-plus
import { setupElementPlus } from '@/plugins/elementPlus'

// 引入 form-create
import { setupFormCreate } from '@/plugins/formCreate'

// 引入全局样式
import '@/styles/index.scss'

// 引入动画
import '@/plugins/animate.css'

// 路由
import router, { setupRouter } from '@/router'

// 指令
import { setupAuth, setupMountedFocus } from '@/directives'

import { createApp } from 'vue'

import App from './App.vue'

import './permission'

import '@/plugins/tongji' // 百度统计
import Logger from '@/utils/Logger'
import mqttTool from '@/utils/mqttTool' // Mqtt工具
import { setupAppVersionCheck } from '@/utils/appVersion'
import { setupReloadOnChunkError } from '@/utils/reloadOnChunkError'

import VueDOMPurifyHTML from 'vue-dompurify-html' // 解决v-html 的安全隐患

import DataVVue3 from '@kjgl77/datav-vue3'

setupReloadOnChunkError(router)
setupAppVersionCheck(router)

// 创建实例
const setupAll = async () => {
  console.time('app:init')
  const app = createApp(App)

  console.time('app:setupI18n')
  await setupI18n(app)
  console.timeEnd('app:setupI18n')

  console.time('app:setupStore')
  setupStore(app)
  console.timeEnd('app:setupStore')

  console.time('app:setupGlobCom')
  setupGlobCom(app)
  console.timeEnd('app:setupGlobCom')

  console.time('app:setupElementPlus')
  setupElementPlus(app)
  console.timeEnd('app:setupElementPlus')

  console.time('app:setupFormCreate')
  setupFormCreate(app)
  console.timeEnd('app:setupFormCreate')

  console.time('app:setupRouter')
  setupRouter(app)
  console.timeEnd('app:setupRouter')

  // directives 指令
  console.time('app:setupDirectives')
  setupAuth(app)
  setupMountedFocus(app)
  console.timeEnd('app:setupDirectives')

  console.time('router:isReady')
  await router.isReady()
  console.timeEnd('router:isReady')

  console.time('app:usePluginsAfterRouterReady')
  app.use(DataVVue3)

  app.use(DataVVue3)

  app.use(VueDOMPurifyHTML)
  app.config.globalProperties.$mqttTool = mqttTool

  app.use(VueTianditu, {
    v: '4.0',
    tk: import.meta.env.VITE_TK
  })
  console.timeEnd('app:usePluginsAfterRouterReady')

  console.time('app:mount')
  app.mount('#app')
  console.timeEnd('app:mount')
  console.timeEnd('app:init')
}

setupAll()

Logger.prettyPrimary(`欢迎使用`, import.meta.env.VITE_APP_TITLE)
