import Vue from 'vue'
import storage from 'store'

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/zh-CN' // lang i18n
// 样式
import './assets/styles/element-variables.scss'
import '@/assets/styles/index.scss' // global css
// 引入animate动画
import animate from 'animate.css'
// 权限指令
import checkPer from '@/utils/permission'
import permission from './directive/permission'
// 数据字典
import dict from './utils/Dict'
// 代码高亮
import VueHighlightJS from 'vue-highlightjs'
import 'highlight.js/styles/atom-one-dark.css'
// 全局过滤器
import * as filters from './filters' // global filters

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

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

import { initData } from '@/api/data'

/**
 * 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()
}
Vue.use(checkPer)
Vue.use(permission)
Vue.use(dict)
Vue.use(VueHighlightJS)
Vue.use(animate)

// 默认设置弹窗点击遮罩不关闭
ElementUI.Dialog.props.closeOnClickModal.default = false
// 默认设置锁定滚动位置
ElementUI.Dialog.props.lockScroll.default = false
// 默认设置锁定滚动位置
ElementUI.MessageBox.setDefaults({
  closeOnClickModal: false,
  lockScroll: false,
})
// set ElementUI lang to EN
Vue.use(ElementUI, {
  size: storage.get('size') || 'medium', // set element-ui default size
  locale,
})

// 注册过滤器
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key])
})
Vue.config.productionTip = false

fetch('static/setting/setting.json')
  .then((response) => response.json())
  .then((data) => {
    console.log(data)
    Vue.prototype.$setting = data
  })

initData('system/configure/getBasicConfigure').then((res) => {
  let data = res.data
  Vue.prototype.$basicinfo = data
  document.title = data.company_short_name + '-' + data.platform_name

  new Vue({
    el: '#app',
    router,
    store,
    render: (h) => h(App),
  })
})
