/*
    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::{
    RenderInfo,
    format::{format_count, format_duration},
};
use chrono::DateTime;
use jellycommon::{
    jellyobject::{Object, TypedTag},
    *,
};
use jellyui_locale::tr;
use std::marker::PhantomData;

markup::define! {
    Props<'a>(ri: &'a RenderInfo<'a>, nku: Object<'a>, full: bool) {
        @let node = nku.get(NKU_NODE).unwrap_or_default();
        .props {
            @if let Some(dur) = node.get(NO_DURATION) {
                p { @format_duration(dur) }
            }
            // @if let Some(res) = node.get(NO_TRACK) {
            //     p { @m.resolution_name() }
            // }
            @if let Some(d) = node.get(NO_RELEASEDATE) {
                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.get(NO_VISIBILITY).unwrap_or(VISI_VISIBLE) {
                VISI_REDUCED => {p.visibility{@tr(ri.lang, "prop.vis.reduced")}}
                VISI_HIDDEN => {p.visibility{@tr(ri.lang, "prop.vis.hidden")}}
                VISI_VISIBLE | _ => {}
            }
            // TODO
            // @if !node.children.is_empty() {
            //     p { @format!("{} items", node.children.len()) }
            // }
            @for (kind, value) in node.get(NO_RATINGS).unwrap_or_default().entries::<f64>() {
                @match TypedTag(kind, PhantomData) {
                    RTYP_YOUTUBE_LIKES => {p.likes{ @format_count(value as usize) " Likes" }}
                    RTYP_YOUTUBE_VIEWS => {p{ @format_count(value as usize) " Views" }}
                    RTYP_YOUTUBE_SUBSCRIBERS => {p{ @format_count(value as usize) " Subscribers" }}
                    RTYP_ROTTEN_TOMATOES if *full => {p.rating{ "Rotten Tomatoes: " @value "%" }}
                    RTYP_METACRITIC if *full => {p.rating{ "Metacritic: " @value "/100" }}
                    RTYP_IMDB => {p.rating{ "IMDb " @value }}
                    RTYP_TMDB if *full => {p.rating{ "TMDB " @format!("{:.01}", value) }}
                    RTYP_TRAKT if *full => {p.rating{ "Trakt " @format!("{:.01}", value) }}
                    _ => {}
                }
            }
            // @match nodeu.udata.watched {
            //     WatchedState::None => {}
            //     WatchedState::Pending => { p.pending { @tr(ri.lang, "prop.watched.pending") } }
            //     WatchedState::Progress(x) => { p.progress { @tr(ri.lang, "prop.watched.progress").replace("{time}", &format_duration(x)) } }
            //     WatchedState::Watched => { p.watched { @tr(ri.lang, "prop.watched.watched") } }
            // }
        }
    }
}
