import { h, render } from 'preact'
import { Provider } from 'react-redux'
import { BrowserRouter, Route } from 'react-router-dom'
// import client from './client'

import { store, history } from './store'
import * as socket from './socket'
import util from './util'

import Header from './common/header.component'
import AudioPlayer from './common/audioPlayer/audioPlayer.component'
import System from './system/system.component'
import Dashboard from './dashboard/dashboard.component'
import modules from './modules'

const module_list = Object.keys(modules).map(name => {
  const module = modules[name]
  return (
    <Route path={'/' + module.name} component={module.router} />
  )
})

const app = (
  <Provider store={store}>
    <BrowserRouter>
      <div>
        <Route exact path='/' component={Dashboard} />
        <Route path='/system/' component={System} />
        <Route path='/dashboard/' component={Dashboard} />
        {module_list}
        <Route path='/' component={Header} />
        <AudioPlayer />
      </div>
    </BrowserRouter>
  </Provider>
)

render(app, document.getElementById('container'))
