//! Server-side language selector component
//!
//! Static implementation of the language selector optimized for SSR rendering.

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

/// Server-side static language selector component
#[component]
pub fn LanguageSelectorSSR(
    #[prop(optional)] class: Option<String>,
    #[prop(optional)] current_language: Option<String>,
    #[prop(optional)] current_path: Option<String>,
) -> impl IntoView {
    let lang = current_language
        .unwrap_or_else(|| rustelo_core_lib::config::get_default_language().to_string());
    let _path = current_path.clone().unwrap_or_else(|| "/".to_string());

    // Use pattern-based key discovery - same as client for perfect hydration sync
    let ssr_i18n = SsrTranslator::new(lang.clone());
    let lang_content = build_page_content_patterns(&ssr_i18n, &["lang-"]);

    view! {
        <crate::navigation::language_selector::unified::LanguageSelector
            class=class.unwrap_or_default()
            current_language=Some(lang)
            _current_path=current_path.unwrap_or_default()
            content=lang_content
            navigation_signals=None
        />
    }
}

/// Server-side static language toggle component
#[component]
pub fn LanguageToggleSSR(
    #[prop(optional)] class: Option<String>,
    #[prop(optional)] current_language: Option<String>,
    #[prop(optional)] current_path: Option<String>,
) -> impl IntoView {
    let lang = current_language
        .unwrap_or_else(|| rustelo_core_lib::config::get_default_language().to_string());
    let _path = current_path.clone().unwrap_or_else(|| "/".to_string());

    // Use pattern-based key discovery - same as client for perfect hydration sync
    let ssr_i18n = SsrTranslator::new(lang.clone());
    let lang_content = build_page_content_patterns(&ssr_i18n, &["lang-"]);

    view! {
        <crate::navigation::language_selector::unified::LanguageSelector
            class=class.unwrap_or_default()
            current_language=Some(lang)
            _current_path=current_path.unwrap_or_default()
            content=lang_content
            navigation_signals=None
        />
    }
}
