use dioxus::prelude::*;
use crate::button::{Button, ButtonSize, ButtonVariant};
use crate::icon::{Icon, IconKind, RenderSvgIcon, SvgIcon};
#[component]
pub fn AttachmentCard(
title: String,
#[props(default)] subtitle: Option<String>,
#[props(default)] avatar: Option<Element>,
#[props(default)] avatar_src: Option<String>,
#[props(default)] avatar_icon: Option<SvgIcon>,
#[props(default)] image: Option<String>,
#[props(default)] image_alt: Option<String>,
#[props(default)] progress: Option<f32>,
#[props(default)] description: Option<String>,
#[props(default)] on_download: Option<EventHandler<MouseEvent>>,
#[props(default)] on_share: Option<EventHandler<MouseEvent>>,
#[props(default)] buttons: Option<Element>,
#[props(default)] actions: Option<Element>,
#[props(default)] on_click: Option<EventHandler<MouseEvent>>,
#[props(default)] class: String,
#[props(default)] children: Element,
) -> Element {
let resolved_avatar = if let Some(custom_av) = avatar {
Some(custom_av)
} else if let Some(src) = avatar_src {
Some(rsx! {
div {
class: "w-10 h-10 rounded-full overflow-hidden border border-white/10 shrink-0",
img {
src: "{src}",
alt: "{title}",
class: "w-full h-full object-cover",
}
}
})
} else if let Some(ic) = avatar_icon {
Some(rsx! {
div {
class: "w-10 h-10 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-purple-300 shrink-0",
RenderSvgIcon { icon: ic, size: 18 }
}
})
} else {
Some(rsx! {
div {
class: "w-10 h-10 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-purple-300 shrink-0",
Icon { kind: IconKind::Paperclip, size: 18 }
}
})
};
let has_buttons = on_download.is_some() || on_share.is_some() || buttons.is_some() || actions.is_some();
let buttons_element = if has_buttons {
Some(rsx! {
if let Some(dl) = on_download {
Button {
size: ButtonSize::Sm,
variant: ButtonVariant::Outline,
left_icon: Some(rsx! { Icon { kind: IconKind::Download, size: 14 } }),
onclick: move |evt| dl.call(evt),
"Scarica"
}
}
if let Some(sh) = on_share {
Button {
size: ButtonSize::Sm,
variant: ButtonVariant::Ghost,
left_icon: Some(rsx! { Icon { kind: IconKind::Share2, size: 14 } }),
onclick: move |evt| sh.call(evt),
"Condividi"
}
}
if let Some(custom_btns) = buttons {
{custom_btns}
}
if let Some(legacy_actions) = actions {
{legacy_actions}
}
})
} else {
None
};
rsx! {
crate::card::Card {
class: "sd-attachment-card-unified {class}",
avatar: resolved_avatar,
title: Some(title),
subtitle: subtitle,
progress: progress,
buttons: buttons_element,
image: image,
image_alt: image_alt,
on_click: on_click,
if let Some(desc) = description {
p { class: "text-xs text-zinc-300 leading-relaxed mb-1", "{desc}" }
}
{children}
}
}
}