import * as React from "react";
import * as ReactDOM from "react-dom";
import { hashHistory } from "react-router";
import configureStore from "./store/configureStore";
import { syncHistoryWithStore } from "react-router-redux";
import { createClient } from "../common/worker";
import { ElectronClient } from "../common/electron/worker";
import "../../node_modules/bootstrap/dist/css/bootstrap.css";
import "../assets/css/app.css";
import { AppContainer } from "react-hot-loader";
import Root from "./root";
import { buildRoutes } from "./routes";

createClient(() => new ElectronClient());
const store = configureStore({});
const history = syncHistoryWithStore(hashHistory, store);
const routes = buildRoutes();

ReactDOM.render(
    <AppContainer>
        <Root store={store} history={history} routes={routes} />
    </AppContainer>,
    document.getElementById("root"),
);

const m = module as any;
if (m.hot) 
{
    m.hot.accept("./root", () => {
        // tslint:disable-next-line:variable-name
        const NewRoot = require("./root").default;
        const newRoutes = buildRoutes();
        ReactDOM.render(
            <AppContainer>
                <NewRoot store={store} history={history} routes={newRoutes} />
            </AppContainer>,
            document.getElementById("root"),
        );
    });
}