use leptos::prelude::*;

use super::unified::UnifiedUserPage;

/// Client-side reactive page component (wrapper)
#[component]
pub fn UserClient(
    #[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 = crate::common::use_page_i18n_dynamic(vec!["user-", "profile-"], || vec![]);

    let lang_content = page_content.get_untracked();

    view! {
        <UnifiedUserPage
            _language=language
            lang_content=lang_content
        />
    }
}

/// SSR static page component (wrapper)
#[component]
pub fn UserSSR(
    #[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!["user-", "profile-"];
    let lang_content =
        rustelo_core_lib::i18n::helpers::build_page_content_patterns(&translator, &patterns);

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

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

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