use askama_axum::{Response, Template};
use axum::{
    http::StatusCode, response::{Html, IntoResponse}
};

struct HtmlTemplate<T>(T);

impl<T> IntoResponse for HtmlTemplate<T>
where
    T: Template,
{
    fn into_response(self) -> Response {
        match self.0.render() {
            Ok(html) => Html(html).into_response(),
            Err(err) => (
                StatusCode::INTERNAL_SERVER_ERROR,
                format!("Failed to render template. Error: {}", err),
            )
                .into_response(),
        }
    }
}

#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {
}

pub async fn index(
) -> impl IntoResponse {
        let template = IndexTemplate {};
        HtmlTemplate(template).into_response()
}

#[derive(Template)]
#[template(path = "fontsample.html")]
struct FontSampleTemplate {
}

pub async fn fontsample(
) -> impl IntoResponse {
        let template = FontSampleTemplate {};
        HtmlTemplate(template).into_response()
}

#[derive(Template)]
#[template(path = "about.html")]
struct AboutTemplate {
}

pub async fn about() -> impl IntoResponse {
    let template = AboutTemplate {};
    HtmlTemplate(template)
}

#[derive(Template)]
#[template(path = "contactus.html")]
struct ContactTemplate {
}

pub async fn contact() -> impl IntoResponse {
    let template = ContactTemplate {};
    HtmlTemplate(template)
}
