use super::pagination::{render_paginated, PaginatableTemplate, PaginationInfo};
use super::posts::{HtmlContent, Post};
use super::util::templates::{filters, TemplateCommon};
use askama::Template;

pub fn generate(posts: &[&Post<HtmlContent>]) -> Result<(), std::io::Error> {
    render_paginated(
        &HomeTemplate {
            posts: &[],
            pagination_info: Default::default(),
        },
        posts,
        "/",
    )
}

#[derive(Template)]
#[template(path = "index.html")]
struct HomeTemplate<'a> {
    posts: &'a [&'a Post<HtmlContent>],
    pagination_info: PaginationInfo,
}

impl<'a> TemplateCommon for HomeTemplate<'a> {}

impl<'a> PaginatableTemplate<'a> for HomeTemplate<'a> {
    fn with_posts(
        &'a self,
        posts: &'a [&'a Post<HtmlContent>],
        pagination_info: PaginationInfo,
    ) -> Self {
        Self {
            posts,
            pagination_info,
        }
    }
}

impl<'a> HomeTemplate<'a> {
    fn permalink(&self) -> &'static str {
        "/"
    }
}
