use leptos::prelude::*;

use super::unified::UnifiedHomePage;
use rustelo_content::rustelo_core_lib;

/// Client-side reactive page component (wrapper)
#[component]
pub fn HomeClient(
    #[prop(default = rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
) -> impl IntoView {
    // Use the existing use_page_i18n_dynamic function
    let page_content = rustelo_pages_leptos::common::use_page_i18n_dynamic(
        vec!["home-", "welcome-", "intro-"],
        Vec::new,
    );

    // Clone language for use in closure
    let language = _language.clone();

    move || {
        view! {
            <UnifiedHomePage
                _language=language.clone()
                lang_content=page_content.get()
            />
        }
    }
}

/// SSR static page component (wrapper)
#[component]
pub fn HomeSSR(
    #[prop(default = rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
) -> impl IntoView {
    // Create static translator for SSR
    let translator = rustelo_core_lib::i18n::page_translator::SsrTranslator::new(_language.clone());
    let patterns: Vec<&str> = vec!["home-", "welcome-", "intro-"];
    let lang_content =
        rustelo_core_lib::i18n::helpers::build_page_content_patterns(&translator, &patterns);

    view! {
        <UnifiedHomePage
            _language=_language.clone()
            lang_content=lang_content
        />
    }
}

/// Main page component with delegation
#[component]
pub fn HomePage(
    #[prop(default = rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        view! { <HomeSSR _language=_language.clone() /> }
    }

    #[cfg(target_arch = "wasm32")]
    {
        view! { <HomeClient _language=_language.clone() /> }
    }
}
