import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
VXETable.config({
  'column-config': {
    resizable: true
  },
  button: {
    size: 'mini'
  }
})
import 'vxe-table/lib/style.css'
Vue.use(VXETable)
import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
VXETable.use(VXETablePluginElement)
const jnpf = require('./utils/jnpf').default

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/element-variables.scss'
import './assets/scss/common.scss'

import '@/styles/index.scss' // global css
import './assets/scss/theme.scss' // 主题

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
Vue.use(VueAwesomeSwiper)

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

import i18n from './lang' // internationalization
import './permission' // permission control
import './utils/error-log' // error log
import { message } from './utils/message'

import * as filters from './filters' // global filters

// 自定义按钮权限指令
import permission from '@/directive/permission'
Vue.use(permission)

Vue.use(Element, {
  size: jnpf.storageGet('size') || 'mini', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
// 批量引入组件
import components from './components'
Vue.use(components)

// 添加实例属性
Object.assign(Vue.prototype, {
  define: require('./utils/define'), // 常量
  jnpf, // 公共方法
  formValidate: require('./utils/formValidate').default, // 表单验证
  $message: message
})

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

Vue.config.productionTip = false

// 按需引入需要的语言包皮肤等资源
require('brace/ext/emmet') // 如果是lang=html时需引入
require('brace/ext/language_tools') // language extension

require('brace/mode/sql')
require('brace/snippets/sql')
require('brace/mode/java')
require('brace/snippets/java')
require('brace/mode/javascript')
require('brace/snippets/javascript')
require('brace/theme/monokai')
require('brace/theme/solarized_dark')
require('brace/theme/chrome')
// 注册组件后即可使用
import Editor from 'bin-ace-editor'
Vue.component(Editor.name, Editor)
Vue.prototype.apiVariableSetItem = function (key, value) {
  if (key === 'API_VARIABLE_CHANGE') {
    let newStorageEvent = document.createEvent('StorageEvent')
    const storage = {
      setItem: function (k, val) {
        sessionStorage.setItem(k, val)
        newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null)
        window.dispatchEvent(newStorageEvent)
      }
    }
    return storage.setItem(key, value)
  }
}
const vm = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: (h) => h(App)
})
export default vm
