/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use crate::{
    format::{MediaInfoExt, format_count, format_duration},
    locale::{Language, tr, trs},
};
use jellycommon::{
    Node, RatingType, Visibility,
    chrono::DateTime,
    user::{NodeUserData, WatchedState},
};

markup::define! {
    Props<'a>(node: &'a Node, udata: &'a NodeUserData, full: bool, lang: &'a Language) {
        .props {
            @if let Some(m) = &node.media {
                p { @format_duration(m.duration) }
                p { @m.resolution_name() }
            }
            @if let Some(d) = &node.release_date {
                p { @if *full {
                    @DateTime::from_timestamp_millis(*d).unwrap().naive_utc().to_string()
                } else {
                    @DateTime::from_timestamp_millis(*d).unwrap().date_naive().to_string()
                }}
            }
            @match node.visibility {
                Visibility::Visible => {}
                Visibility::Reduced => {p.visibility{@trs(lang, "prop.vis.reduced")}}
                Visibility::Hidden => {p.visibility{@trs(lang, "prop.vis.hidden")}}
            }
            // TODO
            // @if !node.children.is_empty() {
            //     p { @format!("{} items", node.children.len()) }
            // }
            @for (kind, value) in &node.ratings {
                @match kind {
                    RatingType::YoutubeLikes => {p.likes{ @format_count(*value as usize) " Likes" }}
                    RatingType::YoutubeViews => {p{ @format_count(*value as usize) " Views" }}
                    RatingType::YoutubeFollowers => {p{ @format_count(*value as usize) " Subscribers" }}
                    RatingType::RottenTomatoes => {p.rating{ @value " Tomatoes" }}
                    RatingType::Metacritic if *full => {p{ "Metacritic Score: " @value }}
                    RatingType::Imdb => {p.rating{ "IMDb " @value }}
                    RatingType::Tmdb => {p.rating{ "TMDB " @format!("{:.01}", value) }}
                    RatingType::Trakt => {p.rating{ "Trakt " @format!("{:.01}", value) }}
                    _ => {}
                }
            }
            @if let Some(f) = &node.federated {
                p.federation { @f }
            }
            @match udata.watched {
                WatchedState::None => {}
                WatchedState::Pending => { p.pending { @trs(lang, "prop.watched.pending") } }
                WatchedState::Progress(x) => { p.progress { @tr(**lang, "prop.watched.progress").replace("{time}", &format_duration(x)) } }
                WatchedState::Watched => { p.watched { @trs(lang, "prop.watched.watched") } }
            }
        }
    }
}
