/*
 Rookeries - Entrypoint for browser app

 @copyright (c) Copyright 2013-2017 Dorian Pula
 @license AGPL v3
 @author Dorian Pula [dorian.pula@amber-penguin-software.ca]
 */


import {h, render} from 'preact';  /** @jsx h*/

import '../static/css/rookeries-css.css';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from 'preact-redux';

import appStore from './store';
import {fetchPage, fetchSiteInfo, fetchSiteMenu, initialUser, loadTheme} from './actions';
import {RookeriesApp} from './containers/App';

// Initialize application
appStore.dispatch(fetchSiteInfo());
appStore.dispatch(initialUser());
appStore.dispatch(fetchSiteMenu());
appStore.dispatch(loadTheme());

const location = window.location.pathname.substring(1);
appStore.dispatch(fetchPage(location));

const RookeriesApp_ = (
  <Provider store={ appStore }>
    <BrowserRouter>
      <RookeriesApp />
    </BrowserRouter>
  </Provider>
);

render(RookeriesApp_, document.getElementById('ui-target'));
