use dioxus::prelude::*;

use crate::pages::{Blog, Post, Root};
use crate::settings::{BardSettings, StylesheetBehavior};



const BLOG_CSS: Asset = asset!("/assets/css/blog.css");



#[component]
fn BlogLayout() -> Element
{
   // Retrieve the provided settings from context.
   let settings = use_context::<BardSettings>();

   rsx!
   {
      match settings.stylesheet
      {
         StylesheetBehavior::Override(asset) =>
         {
            rsx!
            {
                document::Stylesheet { href: asset }
            }
         }

         StylesheetBehavior::Extend(asset) =>
         {
            rsx!
            {
                document::Stylesheet { href: BLOG_CSS }
                document::Stylesheet { href: asset }
            }
         }

         StylesheetBehavior::None =>
         {
            rsx!
            {
                document::Stylesheet { href: BLOG_CSS }
            }
         }
      }

      // Setup the system to use Highlight.js for code blocks.
      document::Stylesheet { href: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/vs2015.css" }
      document::Script { src: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js" }

      Outlet::<Page> {}
   }
}



//#[derive(Debug, Clone, Routable, PartialEq, Eq, Hash, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
pub enum Page
{
   #[layout(BlogLayout)]
   #[route("/")]
   Root { },

   #[route("/:tag")]
   Blog { tag: String },

   #[route("/post/:slug")]
   Post { slug: String},
}
