use yew::{classes, function_component, html, AttrValue, Classes, Html, Properties};
use zu_util::prop::ToAttr;
use crate::styles::color::Color;
use crate::typography::{Typography, Variant};
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
pub action: Option<Html>,
#[prop_or_default]
pub avatar: Option<Html>,
#[prop_or_default]
pub classes: Classes,
#[prop_or_default]
pub component: AttrValue,
#[prop_or(false)]
pub disable_typography: bool,
#[prop_or_default]
pub subheader: Option<Html>,
#[prop_or_default]
pub style: AttrValue,
#[prop_or_default]
pub title: Option<Html>,
}
#[function_component(CardHeader)]
pub fn card_header(props: &Props) -> Html {
let component = if props.component.is_empty() {
"div"
} else {
props.component.as_str()
};
let root_cls = classes!("ZuCardHeader-root", props.classes.clone());
html! {
<@{component.to_owned()}
class={root_cls}
style={props.style.to_attr()}>
if let Some(avatar) = &props.avatar {
<div class="ZuCardHeader-avatar">
{avatar.clone()}
</div>
}
<div class="ZuCardHeader-content">
<Typography classes="ZuCardHeader-title"
variant={if props.avatar.is_some() {Variant::Body2 } else { Variant::H5 }}
component="span">
{props.title.clone().unwrap_or_default()}
</Typography>
<Typography classes="ZuCardHeader-subheader"
variant={if props.avatar.is_some() { Variant::Body2 } else { Variant::Body1 }}
color={Color::Secondary}
component="span">
{props.subheader.clone().unwrap_or_default()}
</Typography>
</div>
if let Some(action) = &props.action {
<div class="ZuCardHeader-action">
{action.clone()}
</div>
}
</@>
}
}