import { createApp } from 'vue'
import App from './App.vue'
// 引入 antd样式表， 否则没有message提示
// import { message } from 'ant-design-vue';
// import 'ant-design-vue/dist/antd.less'
import './global.less' // global style
// pro-layout vue版本组件
import ProLayout from '@ant-design-vue/pro-layout'
// 导入 pro-layout 的样式文件
import '@ant-design-vue/pro-layout/dist/style.less'
// vue路由

import router from './router'
// antd css 文件
import 'ant-design-vue/dist/antd.variable.min.css'
// 使用 pinia 替换掉 vuex
import { createPinia } from 'pinia'

//引入bootstrap图标库
import 'bootstrap-icons/font/bootstrap-icons.css'

import icons from './icons'

import infoBox from '@/utils/infoBox'

import { setGlobalApp } from '@/config/appConfig'

// 图片预览组件  https://mirari.cc/2021/05/31/Vue3%E5%9B%BE%E7%89%87%E6%B5%8F%E8%A7%88%E7%BB%84%E4%BB%B6v-viewer%EF%BC%8C%E6%94%AF%E6%8C%81%E6%97%8B%E8%BD%AC%E3%80%81%E7%BC%A9%E6%94%BE%E3%80%81%E7%BF%BB%E8%BD%AC%E7%AD%89%E6%93%8D%E4%BD%9C/
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'
import { VueClipboard } from '@soerenmartius/vue3-clipboard' //复制插件 https://github.com/soerenmartius/vue3-clipboard
import { setSiteInfos } from './oemconfig'
// userStore

import { useUserStore } from '@/store/modules/user'
import mitt from 'mitt'

// @ts-ignore
import { SYS_NAME_MAP } from 'UIC/util/sysNameKit.js'

const app = createApp(App)

// 创建pinia对象实例
const store = createPinia()
const oem = createPinia()

// 先使用oem对象
app.use(oem)

setSiteInfos().then(() => {
  // @ts-ignore : 改变网站信息
  window.$CHANGE_INDEX_SITE_INFO()

  // 设置全局app对象
  setGlobalApp(app)
  app.config.globalProperties.$mittBus=mitt()

  app.config.globalProperties.$access = function (entId) {
    let accessList = useUserStore().userInfo.entIdList
    return accessList && accessList.indexOf(entId) >= 0
  }

  app.config.globalProperties.$hasAgentEnt = function () {
    return useUserStore().userInfo.isHasAgentEnt === true // undefined 也返回false
  }

  app.config.globalProperties.$hasMemberEnt = function () {
    return useUserStore().userInfo.isHasMemberEnt === true // undefined 也返回false
  }

  app.config.globalProperties.$infoBox = infoBox

  app.config.globalProperties.$SYS_NAME_MAP = SYS_NAME_MAP

  app
    .use(store)
    .use(icons)
    .use(router)
    .use(ProLayout)
    .use(VueClipboard)
    .use(VueViewer)
    .mount('#app')
})
