use maud::{Markup, Render, html};

/// Shorthand for an `<a>` link that opens a new tab
/// Values are (url, text)
pub struct FarLink<'a, T: Render>(pub &'a str, pub T);

impl<T: Render> Render for FarLink<'_, T> {
	fn render(&self) -> Markup {
		html!(
			a
			target="_blank"
			rel="noopener noreferrer"
			href=(self.0)
			{ (self.1) }
		)
	}
}

pub struct Backlinks<'a>(pub &'a [(&'a str, &'a str)], pub &'a str);

impl Render for Backlinks<'_> {
	fn render(&self) -> Markup {
		html! {
			div {
				@for (url, text) in self.0 {
					a href=(url) style="padding-left:5pt;padding-right:5pt;" { (text) }
					"/"
				}

				span style="color:var(--metaColor);padding-left:5pt;padding-right:5pt;" { (self.1) }
			}
		}
	}
}
