//! Server-side SPA link component
//!
//! Static implementation of links for SSR rendering (always renders as regular
//! <a> tags).

use leptos::prelude::*;

/// Server-side static link component (renders as regular <a> tag)
#[component]
pub fn SpaLinkSSR(
    /// The target URL
    href: String,
    /// Link content/children
    children: Children,
    /// CSS class
    #[prop(optional)]
    class: Option<String>,
    /// Whether this is an external link
    #[prop(default = false)]
    external: bool,
    /// Target attribute for external links
    #[prop(optional)]
    target: Option<String>,
    /// Rel attribute for external links
    #[prop(optional)]
    rel: Option<String>,
    /// ARIA label
    #[prop(optional)]
    aria_label: Option<String>,
    /// Title attribute
    #[prop(optional)]
    title: Option<String>,
) -> impl IntoView {
    let class_attr = class.unwrap_or_default();

    let (target_attr, rel_attr) = if external
        || href.starts_with("http")
        || href.starts_with("mailto:")
        || href.starts_with("tel:")
    {
        // External link attributes
        let target = target.unwrap_or_else(|| "_blank".to_string());
        let rel = rel.unwrap_or_else(|| "noopener noreferrer".to_string());
        (Some(target), Some(rel))
    } else {
        // Internal link - no special attributes needed for SSR
        (target, rel)
    };

    view! {
        <a
            href=href
            class=class_attr
            target=target_attr
            rel=rel_attr
            aria-label=aria_label
            title=title
        >
            {children()}
        </a>
    }
}
