use crate::pages;
use leptos::prelude::*;
use leptos_router::components::*;
use leptos_router::path;

pub fn shell(options: LeptosOptions) -> impl IntoView {
    use leptos_meta::MetaTags;

    view! {
        <!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width, initial-scale=1" />
                <AutoReload options=options.clone() />
                <HydrationScripts options />
                <MetaTags />
            </head>
            <body class="bg-slate-950 text-white">
                <App />
            </body>
        </html>
    }
}

#[component]
pub fn App() -> impl leptos::IntoView {
    use leptos_meta::Stylesheet;
    use leptos_meta::Title;

    tracing::debug!("Rendering root component");

    // Provides context that manages stylesheets, titles, meta tags, etc.
    leptos_meta::provide_meta_context();

    leptos::view! {
        <Stylesheet id="leptos" href="/pkg/ascend.css" />

        <Title text="Ascend" />

        <Router>
            <main>
                <Routes fallback=|| "Not found">
                    <Route path=path!("/") view=pages::wall::Wall />
                    <Route path=path!("/wall/edit") view=pages::edit_wall::EditWall />
                    <Route path=path!("/wall/routes") view=pages::routes::Routes />
                </Routes>
            </main>
        </Router>
    }
}
