
import * as React from "react";
import Main from "./Main";
import Login from "./Modules/Authentication/Login";
import Document from "./Document";
import { BrowserRouter, Switch, Route, Redirect } from "react-router-dom";
import {CachingService} from "../../Services";

const AdminApp = () => {
    
    let _cachingService = new CachingService();
    let notAuthenticated =  !_cachingService.read("Token") || _cachingService.read("Token")=='';
    return (
        <BrowserRouter>
          <div>
            {(notAuthenticated) && <Redirect to="/login"  key="from-root"></Redirect>}
                <Switch>
                    <Route path="/login" component={Login} exact></Route>
                    <Route path="/drive/:id" component={Document}></Route>
                    <Route path="/folder/:id" component={Document}></Route>
                    <Route path="/" component={Main}></Route>
                </Switch>
            </div>
        </BrowserRouter>
    )
}
export default AdminApp;
