import _ from 'lodash'
import Vue from 'vue'
import axios from 'axios'
import ELEMENT from 'element-ui'

import config from './config/index.js'
import components from './components/index.js'
import directives from './directives/index.js'
import filters from './filters/index.js'
import MixinELEMENT from './mixins/index.js'

import licenseRequest from './pages/platform/licenseRequest.vue'

Vue.use(MixinELEMENT)
Vue.use(ELEMENT)
Vue.use(components)
Vue.use(directives)
Vue.use(filters)

if (process.env.NODE_ENV === 'development') {
  Vue.config.devtools = true
}
_.merge(axios.defaults, config.axios)

axios.interceptors.response.use(res => {
  return res
}, err => {
  if (err.message.includes('code 401')) {
    window.location.href = 'index.html'
    return
  }
  return Promise.reject(new Error(err))
})

window.appInit = async function () {
  window.app = new Vue({
    el: '#licenseRequest',
    render: h => h(licenseRequest)
  })
}
window.appInit()
