import { NotificationContainer } from "arm-core-layouts";
import React, { useEffect } from "react";
import { connect } from "react-redux";
import { HashRouter, Route, Switch } from "react-router-dom";

import AppActions from "../app/AppActions.js";
import { AppConstants } from "../constants/AppConstants.js";
import MasterPage from "./MasterPage.jsx";
import NotFound from "./NotFoundPage.jsx";
import PrivateRoute from "./PrivateRoute.jsx";
import Standalone from "./Standalone.jsx";
import AliveStatusMessage from "./account/AliveStatusMessage.jsx";
import Login from "./account/Login.jsx";
import SessionExpired from "./account/SessionExpired.jsx";
import Loading from "./shared/Loading.jsx";
import Notify from "./shared/Notify.jsx";
import TestMasterPage from "./test/TestMasterPage.jsx";


export default function MasterPageBase(props){
    const { preLoginLoadUtilities } = props;

    useEffect(() => {
        preLoginLoadUtilities();
    }, []);

    return (
        <HashRouter>
            <Switch>
                <Route path="/">
                    <Loading />
                    <Notify />
                    <NotificationContainer />
                    <SessionExpired/>
                    <AliveStatusMessage/>
                    <Switch>
                        <Route path="/login" component={Login} />
                        {AppConstants.DEBUG_VIEW && <Route path="/test" component={TestMasterPage} />}
                        <Route path="/standalone" component={Standalone} />
                        <PrivateRoute path="/" component={MasterPage} />
                        <Route component={NotFound} />
                    </Switch>
                </Route>
            </Switch>
        </HashRouter>
    )
}

const mapDispatchToProps = (dispatch) => ({
    preLoginLoadUtilities: () => dispatch(AppActions.preLoginLoadUtilities())
})

MasterPageBase = connect(null, mapDispatchToProps)(MasterPageBase);