/*
    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,
    components::node_card::{NodeCard, NodeCardHightlight, NodeCardWide},
};
use jellycommon::{jellyobject::Object, *};
use jellyui_locale::tr;

markup::define! {
    NodeList<'a>(ri: &'a RenderInfo<'a>, nl: Object<'a>) {
        @let ds = nl.get(NODELIST_DISPLAYSTYLE).unwrap_or(NLSTYLE_GRID);
        @if let Some(title) = nl.get(NODELIST_TITLE) {
            h2 { @tr(ri.lang, title) }
        }
        @match ds {
            NLSTYLE_GRID => {
                ul.nl.grid { @for nku in nl.iter(NODELIST_ITEM) {
                    li { @NodeCard { ri, nku } }
                }}
            }
            NLSTYLE_INLINE => {
                ul.nl.inline { @for nku in nl.iter(NODELIST_ITEM) {
                    li { @NodeCard { ri, nku } }
                }}
            }
            NLSTYLE_LIST => {
                ol.nl.list { @for nku in nl.iter(NODELIST_ITEM) {
                    li { @NodeCardWide { ri, nku } }
                }}
            }
            NLSTYLE_HIGHLIGHT => {
                @if let Some(nku) = nl.get(NODELIST_ITEM) {
                    @NodeCardHightlight { ri, nku }
                }
            }
            _ => {}
        }
    }
}
