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

#[cfg(target_arch = "wasm32")]
use super::client::InputClient;
#[cfg(not(target_arch = "wasm32"))]
use super::ssr::InputSSR;

/// Glassmorphism text input component
#[component]
pub fn Input(
    /// Input type (text, email, password, etc.)
    #[prop(default = "text")]
    input_type: &'static str,
    /// Placeholder text
    #[prop(default = "")]
    placeholder: &'static str,
    /// Disable the input
    #[prop(default = false)]
    disabled: bool,
    /// Input change handler (CSR only)
    #[prop(optional)]
    #[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))]
    on_input: Option<Callback<ev::Event>>,
    /// Additional CSS classes
    #[prop(default = "")]
    class: &'static str,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    {
        view! {
            <InputSSR
                input_type=input_type
                placeholder=placeholder
                disabled=disabled
                class=class
            />
        }
    }

    #[cfg(target_arch = "wasm32")]
    {
        view! {
            <InputClient
                input_type=input_type
                placeholder=placeholder
                disabled=disabled
                on_input=on_input.unwrap_or(Callback::new(|_| {}))
                class=class
            />
        }
    }
}
