use leptos::prelude::*;

#[cfg(target_arch = "wasm32")]
use super::client::SpaLinkClient;
#[cfg(not(target_arch = "wasm32"))]
use super::ssr::SpaLinkSSR;

/// SPA-aware link component with client-side navigation
///
/// Automatically detects external links and opens them in a new tab.
/// Internal links use `pushState` for seamless navigation without page reload.
///
/// # Example
///
/// ```rust
/// use leptos::prelude::*;
/// use vapora_leptos_ui::SpaLink;
///
/// view! {
///     // Internal link (SPA navigation)
///     <SpaLink href="/about">"About Us"</SpaLink>
///
///     // External link (opens in new tab)
///     <SpaLink href="https://example.com">"External Site"</SpaLink>
///
///     // Force external behavior
///     <SpaLink href="/download" external=true>"Download"</SpaLink>
/// }
/// ```
#[component]
pub fn SpaLink(
    /// Link destination
    href: String,
    /// Link content
    children: Children,
    /// Additional CSS classes
    #[prop(optional)]
    class: Option<String>,
    /// Force external link behavior (new tab)
    #[prop(default = false)]
    external: bool,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    return view! {
        <SpaLinkSSR href=href class=class external=external>
            {children()}
        </SpaLinkSSR>
    };

    #[cfg(target_arch = "wasm32")]
    return view! {
        <SpaLinkClient href=href class=class external=external>
            {children()}
        </SpaLinkClient>
    };
}
