//! Server-side navigation menu wrapper
//!
//! This is a thin wrapper that prepares SSR-specific data (static menu items)
//! and delegates to the unified implementation.

use ::rustelo_core_lib::{
    config::get_default_language,
    i18n::{build_page_content_patterns, SsrTranslator},
    load_reactive_menu_for_language,
};
use leptos::prelude::*;

use crate::navigation::navmenu::unified::UnifiedNavMenu;

/// Server-side navigation menu wrapper
#[component]
pub fn NavMenuSSR(
    #[prop(default = get_default_language().to_string())] language: String,
) -> impl IntoView {
    // Load menu items for the specified language
    let load_result = load_reactive_menu_for_language(&language);
    let menu_items = match &load_result {
        Ok(items) => {
            tracing::debug!(
                "NavMenuSSR: loaded {} menu items for language '{}'",
                items.len(),
                language
            );
            items.clone()
        }
        Err(e) => {
            tracing::error!(
                "❌ NavMenuSSR: Failed to load menu for '{}': {:?}",
                language,
                e
            );
            vec![]
        }
    };

    if menu_items.is_empty() {
        tracing::error!(
            "🚨 NavMenuSSR: RENDERING EMPTY MENU FOR '{}' - This will cause hydration mismatch!",
            language
        );
    }

    // Prepare i18n content from FTL files
    let ssr_i18n = SsrTranslator::new(language.clone());
    let nav_content = build_page_content_patterns(&ssr_i18n, &["nav-", "lang-"]);

    // Delegate to unified implementation
    view! {
        <UnifiedNavMenu
            language=language
            menu_items=menu_items
            content=nav_content
        />
    }
}

// Re-export as NavMenu for compatibility
pub use NavMenuSSR as NavMenu;
