use crate::defaults::SECTION_ALT;
use crate::utils::defaults::{
DEFAULT_CONTACT_ITEM, DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS, PARAMS_TYPE, SECTION_CONTACT,
};
use crate::utils::types::{SharedAppState, TextMap, URLParams, URLPath};
use crate::utils::DEFAULT_TEXTMAP;
use crate::{rumtk_web_get_config, rumtk_web_get_config_string, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, DEFAULT_TEXT};
use rumtk_core::strings::RUMString;
#[derive(RUMWebTemplate, Debug)]
#[template(
source = "
{% if custom_css_enabled %}
<link href='/static/components/contact_card.css' rel='stylesheet'>
{% endif %}
<div class='centered'>
<div class='f18 contact-card-{{ css_class }}-container'>
{% for (details_typ, details_data) in contact_lines %}
{% if details_typ == &\"phrase\" && !details_data.is_empty() %}
<p class='f14 italics' >
'{{ details_data }}'
</p>
{% else if details_typ == &\"email\" && !details_data.is_empty() %}
<p>
<a href='mailto:{{ details_data }}'>{{ details_data }}</a>
</p>
{% else if details_typ == &\"phone\" && !details_data.is_empty() %}
<p>
<a href='tel:{{ details_data }}'>{{ details_data }}</a>
</p>
{% else if details_typ == &\"portrait\" && !details_data.is_empty() %}
<img src='{{ details_data }}' alt='{{ alt }}' class='contact-card-{{ css_class }}-portrait' fetchpriority='low' loading='lazy'/>
{% else if !details_data.is_empty() %}
<p><strong>
{{ details_data }}
</strong></p>
{% endif %}
{% endfor %}
</div>
</div>
",
ext = "html"
)]
pub struct ContactCard {
alt: RUMString,
contact_lines: TextMap,
css_class: RUMString,
custom_css_enabled: bool,
}
pub fn contact_card<'a>(
_path_components: URLPath<'a, 'a>,
params: URLParams<'a>,
state: SharedAppState,
) -> ComponentResult<ContactCard> {
let typ = rumtk_web_get_text_item!(params, PARAMS_TYPE, DEFAULT_CONTACT_ITEM);
let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
let text_conf = rumtk_web_get_config_string!(state, SECTION_CONTACT);
let contact_lines = rumtk_web_get_text_item!(&text_conf, typ, &DEFAULT_TEXTMAP).clone();
let alt_text = rumtk_web_get_text_item!(&contact_lines, SECTION_ALT, &*DEFAULT_TEXT).to_string();
Ok(ContactCard {
alt: alt_text,
contact_lines,
css_class,
custom_css_enabled
})
}