import React, { useEffect, useState} from 'react';

import _service from '@netuno/service-client';

import { Layout, Menu } from 'antd';

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

import Home from './pages/Home';
import Login from './pages/Login';
import Register from './pages/Register';

import logo from './logo.svg';
import './App.less';

const { Header, Footer, Content } = Layout;

const { SubMenu } = Menu;

function App() {
  const [ data, setData ] = useState([]);
  useEffect(() => {
    _service({
        url: "pessoas",
        success: (response) => {
            if (response.json) {
              setData(response.json);
            }
        },
        fail: (e) => {
            console.log("Service Error", e);
        }
    });
  }, []);

  return (
    <Router>
      <Layout>
        <Header>
          <Menu mode="horizontal">
            <Menu.Item>
              <Link to="/">Home</Link>
            </Menu.Item>
            <Menu.Item>
              <Link to="/login">Login</Link>
            </Menu.Item>
            <Menu.Item>
              <Link to="/register">Registrar</Link>
            </Menu.Item>
          </Menu>
        </Header>
        <Content>
          <Switch>
            <Route path="/login">
              <Login />
            </Route>
            <Route path="/register">
              <Register />
            </Route>
            <Route path="/">
              <Home />
            </Route>
          </Switch>
        </Content>
        <Footer>Footer</Footer>
      </Layout>
    </Router>
  );
}

export default App;
