import { createApp, reactive } from 'vue'
import App from './App.vue'
import router from './router'
import { setupStore } from '@/stores/index'
import { registerIcons } from '@/utils/common'
import mitt from 'mitt'
import VxeUI from 'vxe-pc-ui'
import VXETable from 'vxe-table'
import XEUtils from 'xe-utils'
import 'vxe-pc-ui/lib/style.css'
import 'vxe-table/lib/style.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/display.css'
import '@fortawesome/fontawesome-free/css/all.css'
import '@/styles/index.scss'
import '@/assets/font/iconfont.css'
import { ElDialog } from 'element-plus'
import BaiduMap from 'vue-baidu-map-3x'
import BaiduMapOffline from 'vue-baidu-map-offline'

import ExcelJS from 'exceljs'
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
// 方式1：NPM 安装，注入 ExcelJS 对象
VXETable.use(VXETablePluginExportXLSX, {
    ExcelJS
})
VxeUI.setConfig({
    table: {
        columnConfig: {
            useKey: true
        }
    }
})
// 全局注册 tooltip 组件
window.XEUtils = XEUtils

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

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

// 创建实例
const setupAll = async () => {
    const app = createApp(App)

    //开启离线地图
    app.use(BaiduMapOffline, {
        offline: true,
        offlineConfig: {
            imgext: '.png',
            customstyle: '',
            tiles_dir: '',
            tiles_hybrid: '',
            tiles_self: '',
            tiles_v_dir: '',
            tiles_satellite_dir: '',
            tiles_road_dir: '',
            tiles_v_road_dir: '',
            home: './plugin/offline/'
        }
    })
    app.use(BaiduMap, {
        // ak: 'Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK',
        ak: 'RpQi6WNFZ9tseKzhdwOQsXwFsoVntnsN',
        v: '3.0'
    })

    await setupI18n(app)
    app.use(router)
    setupStore(app)
    app.use(VxeUI)
    app.use(ElementPlus)
    app.use(VXETable)
   
    ;(app._context.components.ElDialog as typeof ElDialog).props.closeOnClickModal.default = false
    registerIcons(app) // icons

    app.config.globalProperties.eventBus = mitt()
    // 配置全局变量
    app.config.globalProperties.$allVariables = reactive({
        butLoading: false
    })
    setupFormCreate(app)

    await router.isReady()

    app.mount('#app')
}

setupAll()
