use leptos::prelude::*;
use leptos_meta::{MetaTags, Stylesheet, provide_meta_context};
use leptos_router::{
    StaticSegment,
    components::{Route, Router, Routes},
};

mod homepage;
mod mail;

use crate::components::Navbar;
use homepage::HomePage;
use mail::Mail;

pub fn shell(options: LeptosOptions) -> impl IntoView {
    view! {
      <!DOCTYPE html>
      <html lang="en" data-theme="dark">
        <head>
          <meta charset="utf-8" />
          <meta name="author" content="Tristan Daniël Maat" />
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <AutoReload options=options.clone() />
          <HydrationScripts options />
          <MetaTags />
        </head>
        <body>
          <App />
        </body>
      </html>
    }
}

#[component]
pub fn App() -> impl IntoView {
    provide_meta_context();

    view! {
      <Stylesheet href="/pkg/tlaternet-webserver.css" />

      <Navbar />

      // content for this welcome page
      <Router>
        <main>
          <Routes fallback=|| "Page not found.".into_view()>
            <Route path=StaticSegment("") view=HomePage />
            <Route path=StaticSegment("mail") view=Mail />
          </Routes>
        </main>
      </Router>
    }
}
