//! Generated Unified {ComponentName} Page Component
//!
//! Auto-generated content list page implementation for blog/portfolio/recipe lists.

use leptos::prelude::*;
use shared::i18n::create_content_provider;

/// Unified {ComponentName} page component that delegates to appropriate implementation
#[component]
pub fn {ComponentName}Page(_language: String) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        // SSR context: use static implementation
        view! {
            <crate::{ModuleName}::ssr::{ComponentName}PageSSR language=_language.clone() />
        }
    }

    #[cfg(target_arch = "wasm32")]
    {
        // Client context: use reactive implementation
        view! {
            <crate::{ModuleName}::client::{ComponentName}PageClient language=_language.clone() />
        }
    }
}

/// Unified {ComponentName} Page component that works in both SSR and client contexts
#[component]
pub fn Unified{ComponentName}Page(
    #[prop(optional)] lang_content: Option<std::collections::HashMap<String, String>>,
    #[prop(optional)] content_type: Option<String>,
) -> impl IntoView {
    // Use DRY content accessor helper
    let content = create_content_provider(lang_content.clone());
    let content_type = content_type.unwrap_or_else(|| "{default_content_type}".to_string());

    view! {
        <div class="ds-bg-page min-h-screen">
            // Header Section
            <section class="ds-container py-ds-8">
                <div class="text-center mb-ds-12">
                    <h1 class="ds-heading-1 ds-text mb-ds-4">
                        {content.t_with_prefixes("page-title", &[&content_type, "{prefix}"], Some(&content.t("{prefix}-page-title")))}
                    </h1>

                    // Optional description
                    {move || {
                        let description = content.t_with_prefixes("page-description", &[&content_type, "{prefix}"], None);
                        if !description.is_empty() {
                            view! {
                                <p class="mt-ds-6 ds-body ds-text-secondary max-w-2xl mx-auto">
                                    {description}
                                </p>
                            }.into_view()
                        } else {
                            view! {}.into_view()
                        }
                    }}
                </div>

                // Content Grid Section
                <div class="space-y-ds-8">
                    // Featured content (optional)
                    {move || {
                        let featured_title = content.t_with_prefixes("featured-title", &[&content_type, "{prefix}"], None);
                        if !featured_title.is_empty() {
                            view! {
                                <section class="mb-ds-12">
                                    <h2 class="ds-heading-2 ds-text mb-ds-6 text-center">
                                        {featured_title}
                                    </h2>
                                    <components::ContentGrid
                                        content_type=content_type.clone()
                                        featured_only=true
                                        max_items={max_items}
                                        class="grid-cols-1 md:grid-cols-2 lg:grid-cols-3".to_string()
                                    />
                                </section>
                            }.into_view()
                        } else {
                            view! {}.into_view()
                        }
                    }}

                    // All content section
                    <section>
                        <components::ContentGrid
                            content_type=content_type.clone()
                            show_filters=true
                            show_search=true
                            items_per_page={max_items}
                            show_pagination={show_pagination}
                            enable_sorting=true
                            class="".to_string()
                        />

                        // No items message
                        {move || {
                            let no_items_msg = content.t_with_prefixes(
                                "no-items-found",
                                &[&content_type, "{prefix}"],
                                Some("No items found")
                            );
                            view! {
                                <div class="hidden empty:block text-center py-ds-12">
                                    <p class="ds-body ds-text-secondary">
                                        {no_items_msg}
                                    </p>
                                </div>
                            }
                        }}
                    </section>
                </div>
            </section>
        </div>
    }
}
