import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import print from 'vue3-print-nb'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import dayjs from 'dayjs'
import App from './App.vue'
import pinia from './store'
import router from './router'
import useSettingsStore from './store/modules/settings'
import request from '@/api/index'
// 自定义指令
import directive from '@/utils/directive'
// 加载 svg 图标
import 'virtual:svg-icons-register'
// 全局样式
import '@/assets/styles/globals.scss'
// 加载 iconify 图标（element plus）
import { downloadAndInstall } from '@/iconify-ep'
import { hasPermission } from '@/utils/composables/permission'
import buttonPerm from '@/utils/buttonPerm'
// 引入打印插件
if (useSettingsStore().app.iconifyOfflineUse) {
  downloadAndInstall()
}
const app = createApp(App)
app.config.globalProperties.hasPerm = hasPermission
app.config.globalProperties.buttonPerm = buttonPerm
app.config.globalProperties.dayjs = dayjs
app.use(print)
app.use(ElementPlus)
app.use(pinia)
app.use(router)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
directive(app)

axios.get('./config/config.json').then((result) => {
  request.defaults.baseURL = result.data.baseUrl // 设置默认请求网址
  app.config.globalProperties.config = result.data
  window.localStorage.setItem('baseURL', result.data.baseUrl)
  app.mount('#app')
}).catch((error) => {
  console.error(`get baseConfig error...${error}`)
})
