import Vue from 'vue';
import axios from 'axios';
import VueAxios from 'vue-axios';
import 'bootstrap';
import Loading from 'vue-loading-overlay';
import 'vue-loading-overlay/dist/vue-loading.css';
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue';
import VCharts from 'v-charts'
import App from './App.vue';
import router from './router';
import store from './store';
import Swal from 'sweetalert2';

Vue.use(VCharts);
Vue.use(VueAxios, axios);
Vue.component('Loading', Loading);
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue);

Vue.use(IconsPlugin);

Vue.config.productionTip = false;

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

function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}

router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth) {
    console.log('pass');
    next();
    /* axios.get('http://www.googo.org:8050/api/auth/user_status', { 
      headers: {
        'Authorization' : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMCwiZXhwIjoxNjIwNzg5Mzc4LCJzdWIiOjIwfQ.C-S2gPHkZ0RnejcfCFVoYKiwsNuMVH5QZdNqSKvZPZs"
      }
    }).then(res => {
        let userid = res.data.data.user_id;
        axios.get('http://www.googo.org:8050/api/user_groups_data/20').then(res => {
          if(res.data.length === 0){
            next({ path: '/serviceselection'});
          }else {
            next();
          }
        });
      }); */
  } else {
    next()
  }
})