//! Unified page transition component interface using shared delegation patterns
//!
//! This module provides a unified interface that automatically selects between
//! client-side reactive and server-side static implementations based on
//! context.

use leptos::prelude::*;

#[cfg(target_arch = "wasm32")]
use crate::ui::page_transition::client::{
    PageTransition as PageTransitionClient,
    SimplePageTransition as SimplePageTransitionClient,
    // TransitionStyle will be imported from unified by client module
};
#[cfg(not(target_arch = "wasm32"))]
use crate::ui::page_transition::ssr::{
    PageTransition as PageTransitionSSR, SimplePageTransition as SimplePageTransitionSSR,
};

// Define TransitionStyle once in unified module
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TransitionStyle {
    Fade,
    Slide,
    Scale,
}

/// Unified page transition component that delegates to appropriate
/// implementation
#[component]
pub fn PageTransition(
    /// Signal that triggers the transition (usually the route path)
    trigger: ReadSignal<String>,
    /// Children to render with transitions
    children: Children,
    /// Transition style to use
    #[prop(default = TransitionStyle::Fade)]
    style: TransitionStyle,
    /// Duration of the transition in milliseconds
    #[prop(default = 300)]
    duration_ms: u64,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        // SSR context: use static implementation
        view! {
            <PageTransitionSSR
                _trigger=trigger
                _style=style
                _duration_ms=duration_ms
            >
                {children()}
            </PageTransitionSSR>
        }
    }

    #[cfg(target_arch = "wasm32")]
    {
        // Client context: use reactive implementation
        view! {
            <PageTransitionClient
                trigger=trigger
                style=style
                duration_ms=duration_ms
            >
                {children()}
            </PageTransitionClient>
        }
    }
}

/// Unified simple page transition component that delegates to appropriate
/// implementation
#[component]
pub fn SimplePageTransition(
    /// Children to render with transitions
    children: Children,
    /// Additional CSS classes
    #[prop(default = String::new())]
    class: String,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        // SSR context: use static implementation
        view! {
            <SimplePageTransitionSSR class=class>
                {children()}
            </SimplePageTransitionSSR>
        }
    }

    #[cfg(target_arch = "wasm32")]
    {
        // Client context: use reactive implementation
        view! {
            <SimplePageTransitionClient class=class>
                {children()}
            </SimplePageTransitionClient>
        }
    }
}
