import Vue from 'vue'
import App from './app/App'
import router from './router'
import BootstrapVue from 'bootstrap-vue'
import vuexI18n from 'vuex-i18n'
import langEn from './resources/locales/locale-en'
import VeeValidate from 'vee-validate'
import { sync } from 'vuex-router-sync'
import store from '@/store'
import '@@@/assets/Icon'
import Icon from 'vue-awesome/components/Icon'
import VueSweetalert2 from 'vue-sweetalert2'
import Helpers from '@/plugins/helpers'
import '../../registerServiceWorker'

// Initialize Bootstrap
Vue.use(BootstrapVue)

// Initialize I18n store
Vue.use(vuexI18n.plugin, store)

// SweetAlert
Vue.use(VueSweetalert2)

// set up translation
let lang =
  localStorage.getItem('SELECTED_LANGUAGE') && JSON.parse(localStorage.getItem('SELECTED_LANGUAGE')).key !== undefined
    ? JSON.parse(localStorage.getItem('SELECTED_LANGUAGE')).key.toLowerCase()
    : 'en'
Vue.i18n.add('en', langEn)

// set the start locale to use
Vue.i18n.set(lang)
Vue.i18n.fallback('en')

// Sync Routes to store
sync(store, router)

// Custom Icon
Vue.component('icon', Icon)

// Validator
const config = {
  inject: false,
}
Vue.use(VeeValidate, config)

Vue.use(Helpers)

/* eslint-disable no-new */
export default new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#treeapp')
