//! Generic Content Index Page - works with ANY content type dynamically
//!
//! This component is fully configuration-driven and works with any content type
//! defined in content-kinds.toml without hardcoded logic.
//!
//! Uses safe, non-reactive patterns to avoid hydration issues and panics.

use leptos::prelude::*;
use rustelo_components::content::simple_grid::SimpleContentGrid;
use rustelo_components::filter::UnifiedCategoryFilter;
use rustelo_core_lib::i18n::content_helper::create_content_provider;

// Note: ContentIndexPage is now generated by the macro in mod.rs
// This function is kept for backward compatibility but delegates to the macro-generated component

// Using unified content types from shared crate

/// Generic Content Index Page - works with ANY content type
/// This is the ONLY content index component needed. It uses configuration
/// from content-kinds.toml to render any content type dynamically.
#[component]
pub fn UnifiedContentIndexPage(
    content_type: String,
    _language: String,
    #[prop(optional)] lang_content: Option<std::collections::HashMap<String, String>>,
    #[prop(optional)] filter: Option<String>,
) -> impl IntoView {
    let content = create_content_provider(lang_content.clone());
    view! {
        <div class="ds-container" data-content-type={content_type.clone()} data-language={_language.clone()}>
            <div class="container mx-auto px-4 py-8">
                // Page Header
                <header class="text-center mb-12">
                    <h1 class="text-balance text-4xl font-bold tracking-tight ds-text sm:text-6xl mb-ds-4">
                        {content.t_with_prefixes("page-title", &[&content_type, "content"], Some(&format!("{} Index", content_type)))}
                    </h1>
                    <p class="ds-text-secondary ds-body max-w-2xl mx-auto">
                        {content.t_with_prefixes("page-description", &[&content_type, "content"], Some(&format!("Browse all {} content", content_type)))}
                    </p>
                </header>

                // Category and Tag Filters (Unified Implementation - works in both SSR and SPA)
                <UnifiedCategoryFilter
                    content_type=content_type.clone()
                    language=_language.clone()
                    _all_emoji="🏷️".to_string()
                />

                <SimpleContentGrid
                    content_type=content_type.clone()
                    language=_language.clone()
                    lang_content=lang_content.unwrap_or_default()
                    category_filter=filter.unwrap_or_default()
                />
            </div>
        </div>
    }
}
