import Vue from 'vue'
import Router from 'vue-router'
import BootstrapVue from 'bootstrap-vue'
import store from '../store/index'
// Components
import Schedules from '../components/Schedules'
import Dj from '../components/Dj'
import Announces from '../components/Announces'
import Downloads from '../components/Downloads'
import Settings from '../components/Settings'
import Information from '../components/Information'
import Streaming from '../components/Streaming'
import Bluetooth from '../components/Bluetooth'
import Login from '../components/Login';
import Config from '../components/Config';

Vue.use(Router)
Vue.use(BootstrapVue)

const router = new Router({
  // mode: 'history',

  routes: [
    {
      path: '/',
      name: 'Home',
      redirect: 'Schedules'
    },
    {
      path: '/Schedules',
      name: 'Schedules',
      component: Schedules
    },
    {
      path: '/Dj',
      name: 'DJ',
      component: Dj
    },
    {
      path: '/Announces',
      name: 'Announces',
      component: Announces
    },
    {
      path: '/Downloads',
      name: 'Downloads',
      component: Downloads
    },
    {
      path: '/Settings',
      name: 'Settings',
      component: Settings
    },
    {
      path: '/Information',
      name: 'Information',
      component: Information
    },
    {
      path: '/Stream',
      name: 'Stream',
      component: Streaming
    },
    {
      path: '/Bluetooth',
      name: 'Bluetooth',
      component: Bluetooth
    },
    {
      path:'/Login',
      name:'Login',
      component: Login
    },
    {
      path: '/Config',
      name:'Config',
      component:Config
    }
  ]
})

router.beforeEach((to, from, next) => {
  switch (to.path) {
    // DJ Enabled Check
    case '/Dj':
      if (store.state.config.hasDj === '0') {
        next('/')
      } else {
        next()
      }
      break
    // Bluetooth Enabled Check
    case '/Bluetooth':
      if (!store.state.config.hasBluetooth) {
        next('/')
      } else {
        next()
      }
      break

    default:
      next()
      break
  }
  // if (to.path === '/Dj') {
  //   // DJ Enabled Check
  //   if (store.state.config.hasDj === '0') {
  //     next('/')
  //   } else {
  //     next()
  //   }
  // } else {
  //   next()
  // }
})

export default router
