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

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>
          <link rel="icon" type="image/svg+xml" href="/icon.svg" />
          <link rel="icon" type="image/png" href="/favicon-48.png" sizes="48x48" />

          <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>
    }
}
