/* eslint-disable */
import Vue from 'vue'
import EvaIcons from 'vue-eva-icons'
import axios from 'axios'
import moment from 'moment'
import App from './App.vue'
import router from './router'
import store from './store'
import * as VueGoogleMaps from 'vue2-google-maps'
import Vuetify from 'vuetify'
import VueSocialSharing from 'vue-social-sharing'
import VueCurrencyInput from 'vue-currency-input'
import VueFloatLabel from 'vue-float-label'
import VueCryptojs from 'vue-cryptojs'
import VueAnalytics from 'vue-analytics'
import JsonExcel from 'vue-json-excel'
import VModal from 'vue-js-modal'
import vueFloatLabel from 'vue-float-label'
import 'vue-loaders/dist/vue-loaders.css'
import VueLoaders from 'vue-loaders'
import VueQuillEditor from 'vue-quill-editor'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

Vue.use(VueQuillEditor /* { default global options } */ )
Vue.use(VueLoaders)
Vue.use(VueSocialSharing)
Vue.use(EvaIcons)
Vue.use(Vuetify)
Vue.use(VueFloatLabel)
Vue.use(VueCryptojs)
Vue.component('downloadExcel', JsonExcel)
Vue.use(BootstrapVue)
Vue.use(IconsPlugin)

Vue.use(VueGoogleMaps, {
        load: {
            key: 'AIzaSyBpubKVyM2HwrJreGsENtKbWd38AhNTC0w',
            libraries: 'places,directions', // This is required if you use the Autocomplete plugin
            // OR: libraries: 'places,drawing'
            // OR: libraries: 'places,drawing,visualization'
            // (as you require)

            //// If you want to set the version, you can do so:
            // v: '3.26',
        },
    })
    //More info @ https://webdeasy.de/en/vue-analytics-en/
Vue.use(VueAnalytics, {
    id: 'UA-128891091-1',
    router,
})

Vue.config.productionTip = false
axios.defaults.baseURL = 'http://localhost:57260'
    //axios.defaults.baseURL = 'https://www.pvsl.co.za:86/'
    //
axios.defaults.baseURL = 'http://training.provision-sa.com:120/'

Vue.prototype.$axios = axios
const pluginOptions = {
    /* see config reference */
    globalOptions: {
        currency: ['ZAR', null, { prefix: 'R' }][2],
        precision: 0,
    },
}
Vue.use(VueCurrencyInput, pluginOptions)
Vue.prototype.$http = axios
const token = localStorage.getItem('token')
if (token) {
    Vue.prototype.$http.defaults.headers.common.Authorization = token
}

router.beforeEach((to, from, next) => {
    if (to.matched.some((record) => record.meta.requiresAuth)) {
        if (store.getters.isLoggedIn) {
            next()
            return
        }
        next('/users/login')
    } else {
        next()
    }
})

Vue.filter('toCurrency', (value) => {
    if (typeof value !== 'number') {
        return value
    }
    const formatter = new Intl.NumberFormat('en-US', {
        minimumFractionDigits: 0,
    })
    return `R ${formatter.format(value)}`
})

Vue.filter('toProper', (value) => {
    if (typeof value !== 'string') {
        console.log(typeof value)
        return value
    }
    value = value.replace(/([a-z])([A-Z])/g, '$1 $2')
    return value.charAt(0).toUpperCase() + value.slice(1)
})

Vue.filter('toDate', (value) =>
    value.substring(0, value.length > 9 ? 10 : value.length),
)

Vue.filter('toTime', (value) => moment(String(value)).format('hh:mm'))

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

Vue.use(VModal)