import React from "react"
import {BrowserRouter, Route, Routes} from "react-router-dom"
import {Suspense} from "react"
import Profile from "./Auth/Profile"
import Login from "./Auth/Login"
import Header from "../components/Header"
import Home from "./Home"
import useAuthUser from "../hooks/AuthUser"
import Register from "./Auth/Register"
import ToDoShow from "./ToDos/ToDoShow"
import TimeTrackersIndex from "./TimeTrackersIndex"

const Router = () => {

    console.log('router')
    const {loadingAuthUser} = useAuthUser()

    return <>
        {loadingAuthUser ? '...loading'
            : <BrowserRouter>
                <Suspense fallback={'... loading'}>
                    <Header />
                    <Routes>
                        <Route path="/" element={<Home />} />
                        <Route path="/profile" element={<Profile />} />
                        <Route path="/connexion" element={<Login />} />
                        <Route path="/inscription" element={<Register />} />
                        <Route path="/todos/:id" element={<ToDoShow />} />
                        <Route path="/times" element={<TimeTrackersIndex />} />
                    </Routes>
                </Suspense>
            </BrowserRouter>
        }
    </>
}

export default Router
