//! Realm avatars list page component. use leptos::prelude::*; use leptos_router::hooks::use_params_map; use crate::components::{Card, EmptyState, PageHeader}; use crate::hooks::use_fetch_if; use crate::models::RealmAvatarSummary; use crate::utils::get_api_base; /// View mode for avatars listing. #[derive(Clone, Copy, PartialEq, Eq)] pub enum ViewMode { Table, Grid, } /// Realm avatars page component with table and grid views. #[component] pub fn RealmAvatarsPage() -> impl IntoView { let params = use_params_map(); let slug = move || params.get().get("slug").unwrap_or_default(); let initial_slug = params.get_untracked().get("slug").unwrap_or_default(); let (view_mode, set_view_mode) = signal(ViewMode::Table); let avatars = use_fetch_if::>( move || !slug().is_empty(), move || format!("{}/realms/{}/avatars", get_api_base(), slug()), ); let slug_for_new = initial_slug.clone(); let slug_for_back = initial_slug.clone(); view! { "Loading avatars..."

}> {move || { let slug = slug(); avatars.get().map(move |maybe_avatars: Option>| { match maybe_avatars { Some(avatar_list) if !avatar_list.is_empty() => { if view_mode.get() == ViewMode::Table { view! { }.into_any() } else { view! { }.into_any() } } _ => view! { }.into_any() } }) }}
} } /// Table view for realm avatars. #[component] fn RealmAvatarsTable(avatars: Vec, realm_slug: String) -> impl IntoView { view! {
{avatars.into_iter().map(|avatar| { let thumbnail_url = avatar.thumbnail_path.clone() .map(|p| format!("/assets/{}", p)); let detail_url = format!("/admin/realms/{}/avatars/{}", realm_slug, avatar.id); view! { } }).collect_view()}
"Thumbnail" "Name" "Slug" "Public" "Active" "Created"
{thumbnail_url.map(|url| view! { avatar.name.clone() })} {avatar.name} {avatar.slug} {if avatar.is_public { view! { "Public" }.into_any() } else { view! { "Private" }.into_any() }} {if avatar.is_active { view! { "Active" }.into_any() } else { view! { "Inactive" }.into_any() }} {avatar.created_at}
} } /// Grid view for realm avatars with thumbnails. #[component] fn RealmAvatarsGrid(avatars: Vec, realm_slug: String) -> impl IntoView { view! {
{avatars.into_iter().map(|avatar| { let thumbnail_url = avatar.thumbnail_path.clone() .map(|p| format!("/assets/{}", p)) .unwrap_or_else(|| "/static/placeholder-avatar.svg".to_string()); let avatar_url = format!("/admin/realms/{}/avatars/{}", realm_slug, avatar.id); let avatar_name_for_title = avatar.name.clone(); let avatar_name_for_alt = avatar.name.clone(); let avatar_name_for_label = avatar.name; let is_active = avatar.is_active; let is_public = avatar.is_public; view! { avatar_name_for_alt {avatar_name_for_label}
{if is_public { view! { "Public" }.into_any() } else { view! { "Private" }.into_any() }} {if !is_active { view! { "Inactive" }.into_any() } else { view! {}.into_any() }}
} }).collect_view()}
} }