use leptos::prelude::*;

#[component]
pub fn SpaLinkSSR(
    href: String,
    children: Children,
    class: Option<String>,
    external: bool,
) -> impl IntoView {
    // Detect if link is external
    let is_external = external
        || href.starts_with("http://")
        || href.starts_with("https://")
        || href.starts_with("mailto:")
        || href.starts_with("tel:");

    if is_external {
        // External link - open in new tab
        view! {
            <a
                href=href
                class=class.unwrap_or_default()
                target="_blank"
                rel="noopener noreferrer"
            >
                {children()}
            </a>
        }
        .into_any()
    } else {
        // Internal link - standard anchor (SSR doesn't need JS)
        view! {
            <a href=href class=class.unwrap_or_default()>
                {children()}
            </a>
        }
        .into_any()
    }
}
