import Vue from 'vue'
import { getQueryParam } from '@/utils'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
//Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

// vxe-table
import { VxeUI, VxeUpload, VxeDatePicker } from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
Vue.use(VxeUpload)
Vue.use(VxeDatePicker)
import VxeTable from 'vxe-table'
import "vxe-table/styles/index.scss"
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
import ExcelJS from 'exceljs'
VxeTable.use(VXETablePluginExportXLSX, {
  ExcelJS
})
Vue.use(VxeTable)

Vue.config.productionTip = false

//vant
import Vant from 'vant'
import 'vant/lib/index.css';
Vue.use(Vant)
import domZIndex from 'dom-zindex'
domZIndex.setCurrent(2000)

// treeselect
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
Vue.component('Treeselect', Treeselect)

import CardContainer from '@/layout/CardContainer.vue'
Vue.component('CardContainer', CardContainer)
//moment
import moment from 'moment'
moment.locale('zh-cn')
Vue.prototype.$moment = moment;

import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)

import { setToken,getToken } from "@/utils/auth"
if(window.top !== window.self) {
  // 当前页面在iframe中
  window._IN_IFRAME = true;
  Vue.config.errorHandler = (err, vm, info) => {
    top?._addError(err.message, err.stack)
    console.error(err)
  }
}
if (window.__POWERED_BY_WUJIE__) {
  let instance;
  window.__WUJIE_MOUNT = () => {
    instance = new Vue({
      router,
      store,
      render: h => h(App),
      beforeCreate() {
        Vue.prototype.$bus = this
      }
    }).$mount("#app")
    window.MODULE_NAME = window.$wujie?.props?.module_name;
    console.log('token-wujie',window.MODULE_NAME)
    setToken(window.$wujie?.props?.auth_token)
    router.push('/')
  };
  window.__WUJIE_UNMOUNT = () => {
    instance.$destroy();
  };
} else {
  window.MODULE_NAME = getQueryParam('module_name')
  new Vue({
    router,
    store,
    render: h => h(App),
    beforeCreate() {
      Vue.prototype.$bus = this
    }
  }).$mount("#app")
}
