use askama::Template;
use axum::{response::IntoResponse, Extension};
use http::Request;

use crate::{HtmlTemplate, UserData};

#[derive(Template)]
#[template(path = "profile.html")]
struct ProfileTemplate {
    logged_in: bool,
    name: String,
}

pub async fn profile<T>(
    Extension(user_data): Extension<Option<UserData>>,
    _request: Request<T>,
) -> impl IntoResponse {
    let user_email = user_data.map(|s| s.user_email);
    let logged_in = user_email.is_some();
    let name = user_email.unwrap_or_default();

    let template = ProfileTemplate { logged_in, name};
    HtmlTemplate(template)
}