import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom"

import loadable from "@loadable/component"
import { Header } from "./pages/template/Header.tsx"
import "./style/app.css"

const HomePage = loadable(() => import("./pages/HomePage.tsx"))
const LoginPage = loadable(() => import("./pages/LoginPage.tsx"))
const RegisterPage = loadable(() => import("./pages/RegisterPage.tsx"))
const NotFoundPage = loadable(() => import("./pages/404.tsx"))
const CreateTeamPage = loadable(() => import("./pages/CreateTeamPage.tsx"))
const TeamPanelPage = loadable(() => import("./pages/TeamPanel.tsx"))
const NewTacticPage = loadable(() => import("./pages/NewTacticPage.tsx"))
const Editor = loadable(() => import("./pages/Editor.tsx"))

export default function App() {
    return (
        <div id="app">
            <BrowserRouter>
                <Outlet />

                <Routes>
                    <Route path={"/login"} element={<LoginPage />} />
                    <Route path={"/register"} element={<RegisterPage />} />

                    <Route path={"/"} element={<AppLayout />}>
                        <Route path={"/"} element={<HomePage />} />
                        <Route path={"/home"} element={<HomePage />} />

                        <Route
                            path={"/team/new"}
                            element={<CreateTeamPage />}
                        />
                        <Route
                            path={"/team/:teamId"}
                            element={<TeamPanelPage />}
                        />
                        <Route
                            path={"/tactic/new"}
                            element={<NewTacticPage />}
                        />
                        <Route
                            path={"/tactic/:tacticId/edit"}
                            element={<Editor guestMode={false} />}
                        />
                        <Route
                            path={"/tactic/edit-guest"}
                            element={<Editor guestMode={true} />}
                        />

                        <Route path={"*"} element={<NotFoundPage />} />
                    </Route>
                </Routes>
            </BrowserRouter>
        </div>
    )
}

function AppLayout() {
    return (
        <>
            <Header />
            <Outlet />
        </>
    )
}
