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 main from './pages/contentcore/templateDiff.vue'

Vue.use(components)

Vue.use(ELEMENT)

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')) {
    if (err.response.data.loginURL) {
      window.location.href = err.response.data.loginURL + encodeURIComponent(location.href)
      return
    }
    window.location.href = 'index.html'
    return
  }
  return Promise.reject(new Error(err))
})

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

window.appInit()
