import React from 'react'
import { Route, IndexRoute } from 'react-router'
import CoreLayout from 'layouts/CoreLayout'

import {
    TerminalView,
    BasicSQLiView,
    NetworkScanningView,
    IoTyLabView
} from 'views'

import {
  // Browser,
  // CodeEditor
} from 'components'

import {auth} from 'utils/auth'

function checkAuth (nextState, replace) {
  if (auth.loggedIn()) {
    replace({
      pathname: '/login',
      state: { nextPathname: nextState.location.pathname }
    })
  }
}

function requireAuth (nextState, replace) {
  if (!auth.loggedIn()) {
    replace({
      pathname: '/login',
      state: { nextPathname: nextState.location.pathname }
    })
  }
}

const routes = [
  <Route path='/terminal/:vlqType' component={TerminalView} onEnter={requireAuth} />,
  <Route path='/basicsqli' component={BasicSQLiView} onEnter={requireAuth} />,
  <Route path='/network-scanning' component={NetworkScanningView} onEnter={requireAuth} />,
  <Route path='/iot' component={IoTyLabView} />
]

export default {
  routes
}
