use leptos::ev;
use leptos::prelude::*;

#[cfg(target_arch = "wasm32")]
use super::client::ButtonClient;
#[cfg(not(target_arch = "wasm32"))]
use super::ssr::ButtonSSR;
use crate::theme::{Size, Variant};

/// Glassmorphism button component
///
/// # Example
///
/// ```rust
/// use leptos::prelude::*;
/// use vapora_leptos_ui::{Button, Variant, Size};
///
/// #[component]
/// fn App() -> impl IntoView {
///     view! {
///         <Button variant=Variant::Primary size=Size::Medium on:click=|_| {}>"Click Me"</Button>
///     }
/// }
/// ```
#[component]
pub fn Button(
    /// Button content
    children: Children,
    /// Visual variant (Primary, Secondary, Danger, Ghost)
    #[prop(default = Variant::Primary)]
    variant: Variant,
    /// Size variant (Small, Medium, Large)
    #[prop(default = Size::Medium)]
    size: Size,
    /// HTML button type attribute
    #[prop(default = "button")]
    button_type: &'static str,
    /// Show loading spinner
    #[prop(default = false)]
    loading: bool,
    /// Disable the button
    #[prop(default = false)]
    disabled: bool,
    /// Click handler (CSR only)
    #[prop(optional)]
    #[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))]
    on_click: Option<Callback<ev::MouseEvent>>,
    /// Additional CSS classes
    #[prop(default = "")]
    class: &'static str,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        view! {
            <ButtonSSR
                variant=variant
                size=size
                button_type=button_type
                loading=loading
                disabled=disabled
                class=class
            >
                {children()}
            </ButtonSSR>
        }
    }

    #[cfg(target_arch = "wasm32")]
    {
        view! {
            <ButtonClient
                variant=variant
                size=size
                button_type=button_type
                loading=loading
                disabled=disabled
                on_click=on_click.unwrap_or(Callback::new(|_| {}))
                class=class
            >
                {children()}
            </ButtonClient>
        }
    }
}
