use leptos::prelude::*;

use super::unified::UnifiedContentIndexPage;

/// Client-side reactive page component (wrapper)
#[component]
pub fn ContentIndexClient(
    #[prop(default = rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
    content_type: String,
) -> impl IntoView {
    // Use the existing use_page_i18n_dynamic function
    let page_content = crate::common::use_page_i18n_dynamic(vec!["content-", "blog-"], || vec![]);

    let lang_content = page_content.get_untracked();

    view! {
        <UnifiedContentIndexPage
            _language=_language
            lang_content=lang_content
            content_type=content_type
        />
    }
}

/// SSR static page component (wrapper)
#[component]
pub fn ContentIndexSSR(
    #[prop(default = rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
    content_type: 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!["content-", "blog-"];
    let lang_content =
        rustelo_core_lib::i18n::helpers::build_page_content_patterns(&translator, &patterns);

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

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

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