#![allow(unused)]
#![warn(unused_must_use)]

use leptos::prelude::*;
use leptos_router::components::A;

pub mod plot_demo;

#[derive(Clone)]
pub struct PostMeta {
    pub slug: &'static str,
    pub title: &'static str,
    pub description: &'static str,
}

fn get_all_posts() -> Vec<PostMeta> {
    vec![
        // PostMeta {
        //     slug: "plot_demo",
        //     title: "Interactive Plot Demo",
        //     description: "A demonstration of the Plot component with interactive graphics rendering.",
        // },
    ]
}

#[component]
pub fn Posts() -> impl IntoView {
    let posts = get_all_posts();

    view! {
        <section>
            <header>
                <h1>"Posts"</h1>
            </header>
            "I haven't published anything yet. Try again later."
            <section class="posts-list">
                {posts
                    .into_iter()
                    .map(|post| {
                        view! {
                            <article class="post-preview">
                                <h2>
                                    <A href=format!("/posts/{}", post.slug)>{post.title}</A>
                                </h2>
                                <p class="post-description">{post.description}</p>
                            </article>
                        }
                    })
                    .collect::<Vec<_>>()}
            </section>
        </section>
    }
}
