import logo from './logo.svg';

import {
  BrowserRouter as Router,
  Switch, Route, Link
} from "react-router-dom";

import { Layout, Menu } from 'antd';

import Home from './pages/Home';
import Info from './pages/Info';
import Register from './pages/Register';
import Login from './pages/Login';
import Main from './pages/Main';
import Communities from './pages/Communities';
import Logout from './pages/Logout';

import _auth from '@netuno/auth-client';

import './App.less';

const { Header, Footer, Content } = Layout;

const { SubMenu } = Menu;

function App() {
  let menuItems = null;
  if (_auth.isLogged()) {
    menuItems = <>
      <Menu.Item>
        <Link to="/main">Principal</Link>
      </Menu.Item>
      <Menu.Item>
        <Link to="/communities">Comunidades</Link>
      </Menu.Item>
      <Menu.Item>
        <Link to="/logout">Sair</Link>
      </Menu.Item>
    </>;
  } else {
    menuItems = <>
      <Menu.Item>
        <Link to="/">Home</Link>
      </Menu.Item>
      <Menu.Item>
        <Link to="/info">Info</Link>
      </Menu.Item>
      <Menu.Item>
        <Link to="/register">Registo</Link>
      </Menu.Item>
      <Menu.Item>
        <Link to="/login">Login</Link>
      </Menu.Item>
    </>;
  }
  return (
    <Router>
      <Layout>
        <Header>
          <Menu mode="horizontal">
            {menuItems}
          </Menu>
        </Header>
        <Content>
          <Switch>
            <Route path="/login">
              <Login />
            </Route>
            <Route path="/register">
              <Register />
            </Route>
            <Route path="/info">
              <Info />
            </Route>
            <Route path="/main">
              <Main />
            </Route>
            <Route path="/communities">
              <Communities />
            </Route>
            <Route path="/logout">
              <Logout />
            </Route>
            <Route path="/">
              <Home />
            </Route>
          </Switch>
        </Content>
        <Footer>Footer</Footer>
      </Layout>
    </Router>
  );
}

export default App;
