use leptos::*;

fn human_reading_time(reading_time: u64) -> String {
    match reading_time {
        0..=60 => format!("{reading_time}s"),
        _ => {
            let min = reading_time / 60;
            let secs = reading_time - min * 60;
            format!("{min}min {secs}s")
        }
    }
}

#[component]
pub fn ReadingTime(
    time: u64
) -> impl IntoView {
    view! {
        <span class="icon_container">
            <leptos_icons::Icon icon=icondata::BiTimeFiveRegular />
            { human_reading_time(time) }
        </span>
    }
}