import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import directives from '@/directives' // 自定义指令集
import { i18n } from '@/stores' // 国际化语言
import layouts from "./components/layouts" // 布局组件
import ElementPlus from 'element-plus'
import * as ElementIcons from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import './assets/themes/style.less' // 主题样式
import { timerInterceptor } from '@/utils/timer'
import { useGlobalStore } from '@/stores'

const app = createApp(App)
app.use(i18n)
app.use(router)
app.use(directives)
app.use(ElementPlus)
app.use(layouts)
app.mount('#app')

// 等待 html 加载完成
document.addEventListener('DOMContentLoaded', () => {
    const { screenAdapter } = useGlobalStore()
    // 适配客户端
    screenAdapter()
    // 监听窗口大小变化
    window.addEventListener('resize', timerInterceptor.setDebounce(() => screenAdapter()))
}, false)

// 注册全局图标
for (const [key, value] of Object.entries(ElementIcons)) {
    app.component(key, value)
}