import Vue from 'vue'

import Cookies from 'js-cookie'

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

import Element from 'element-ui'
import './styles/element-variables.scss'

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

// import Antd from 'ant-design-vue'
// import 'ant-design-vue/dist/antd.css';

// Vue.use(Antd)
import VueCodemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
Vue.use(VueCodemirror)

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

import { getDicts } from '@/api/admin/dict/data'
import { getItems, setItems } from '@/api/table'
import { getConfigKey } from '@/api/admin/sys-config'
import { parseTime, resetForm, addDateRange, selectDictLabel, /* download,*/ selectItemsLabel,timeConversion } from '@/utils/costum'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
// import './utils/tracing'   //引入trace
import axios from 'axios'
import 'lib-flexible/flexible'

import Viser from 'viser-vue'
Vue.use(Viser)

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

import Pagination from '@/components/Pagination'
import BasicLayout from '@/layout/BasicLayout'

import VueParticles from 'vue-particles'
Vue.use(VueParticles)

import '@/utils/dialog'
Vue.prototype.$http = axios;
import * as Echarts5 from 'echarts5'
Vue.prototype.$echarts5 = Echarts5;

import 'vis/dist/vis.css'
import elTableInfiniteScroll from 'el-table-infinite-scroll';
Vue.use(elTableInfiniteScroll);
import qs from 'qs'
Vue.prototype.$qs = qs;
import VueContextMenu from 'vue-contextmenu'
Vue.use(VueContextMenu)
//应用拓扑
// const front = 'http://observe-ui.cecf.base:8580/top/'
// const iframeUrl = front + "/sg/top/"
const front = 'http://observe-ui.cestong.com.cn/'
const iframeUrl = front
Vue.prototype.iframeUrl = iframeUrl
// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getItems = getItems
Vue.prototype.setItems = setItems
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectItemsLabel = selectItemsLabel
Vue.prototype.timeConversion = timeConversion
// Vue.prototype.download = download

// 全局组件挂载
Vue.component('Pagination', Pagination)
Vue.component('BasicLayout', BasicLayout)

Vue.prototype.msgSuccess = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'success' })
}

Vue.prototype.msgError = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'error' })
}

Vue.prototype.msgInfo = function(msg) {
  this.$message.info(msg)
}

Vue.use(permission)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

import VueDND from 'awe-dnd'
Vue.use(VueDND)

import 'remixicon/fonts/remixicon.css'

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
window.refreshTime = setInterval(() => {
  store.dispatch('user/refreshTokenFn')
}, 1000 * 60 * 20)
// function setTokenRefresh() {
//   // 设置刷新 token 的时间（提前 5 分钟）
//   const expireTime = localStorage.getItem('expireTime')
//   const refreshTime = Number(expireTime) - 50 * 60 * 1000 // 提前 10 分钟刷新
//   console.log('main---refreshTime---', refreshTime)
//   const delay = refreshTime - Date.now()
//   console.log('main0---delay-----', delay)
//   if (delay > 0) {
//     window.refreshTime = setTimeout(() => {
//       store.dispatch('user/refreshTokenFn')
//     }, delay)
//   }
// }
// setTokenRefresh()
Vue.config.productionTip = false

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