import Vue from 'vue'

import Cookies from 'js-cookie'

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

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

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
import './utils/error-log' // error log

import * as filters from './filters' // global filters
import './plugins/vxe-table'
import 'xe-utils'

import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import cal from './utils/calculation'
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
import VXETablePluginRenderer from 'vxe-table-plugin-renderer'
import 'vxe-table-plugin-renderer/dist/style.css'
import VueSocketIO from 'vue-socket.io'

VXETable.use(VXETablePluginExportXLSX)
VXETable.use(VXETablePluginRenderer)

Vue.prototype.cal = cal
Vue.use(VXETable)
import print from './utils/print' //能不能单独引用
Vue.use(print)

// ...

String.prototype.format = function(args) {
  if (arguments.length > 0) {
    var result = this;
    if (arguments.length == 1 && typeof(args) == "object") {
      for (var key in args) {
        var reg = new RegExp("({" + key + "})", "g");
        result = result.replace(reg, args[key]);
      }
    } else {
      for (var i = 0; i < arguments.length; i++) {
        if (arguments[i] == undefined) {
          return "";
        } else {
          var reg = new RegExp("({[" + i + "]})", "g");
          result = result.replace(reg, arguments[i]);
        }
      }
    }
    return result;
  } else {
    return this;
  }
}

import { GlobalWorkerOptions } from 'pdfjs-dist';
GlobalWorkerOptions.workerSrc = 'pdf.worker.js';

/**
 * 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(ElementUI, {
  size: Cookies.get('size') || 'mini' // set element-ui default size
})

import dataV from '@jiaminghi/data-view'
Vue.config.productionTip = false
Vue.use(dataV)

import VueWorker from 'vue-worker' // Web worker插件
Vue.use(VueWorker)

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.use(new VueSocketIO({
  debug: false,
  connection: process.env.VUE_APP_WEBSOCKET,  //
  options: { autoConnect:false,path: "",transports: ['websocket', 'xhr-polling', 'jsonp-polling'], } //Optional options
}))

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

Vue.config.devtools = true
