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"
import {env} from "../utilities/env"
import Reset from "./Auth/Reset"
import ForgotPassword from "./Auth/ForgotPassword"

const 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 />} />
                        {env.VITE_REGISTER_DISABLED === 'false' && <Route path="/sinscrire" element={<Register />} />}
                        <Route path="/todos/:id" element={<ToDoShow />} />
                        <Route path="/mot-de-passe-oubliee" element={<ForgotPassword />} />
                        <Route path="/reset/:token" element={<Reset />} />
                        <Route path="/times" element={<TimeTrackersIndex />} />
                    </Routes>
                </Suspense>
            </BrowserRouter>
        }
    </>
}

export default Router
