use leptos::prelude::*;

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

#[cfg(target_arch = "wasm32")]
use super::client::FormFieldClient;

/// Form field wrapper with label and error display
///
/// # Examples
///
/// ```rust
/// use leptos::prelude::*;
/// use vapora_leptos_ui::{FormField, Input};
///
/// #[component]
/// fn LoginForm() -> impl IntoView {
///     let (username, set_username) = signal(String::new());
///     let (error, set_error) = signal(None::<String>);
///
///     view! {
///         <FormField
///             label="Username"
///             error=error.get()
///             required=true
///         >
///             <Input
///                 value=username.get()
///                 on_input=move |val| set_username(val)
///                 placeholder="Enter username"
///             />
///         </FormField>
///     }
/// }
/// ```
#[component]
pub fn FormField(
    /// Field label text
    label: String,
    /// Optional error message to display
    #[prop(optional)]
    error: Option<String>,
    /// Whether field is required (shows asterisk)
    #[prop(default = false)]
    required: bool,
    /// Optional help text
    #[prop(optional)]
    help_text: Option<String>,
    /// Child input component
    children: Children,
    /// Additional CSS classes
    #[prop(default = "")]
    class: &'static str,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    return view! {
        <FormFieldSSR
            label=label
            error=error
            required=required
            help_text=help_text
            class=class
        >
            {children()}
        </FormFieldSSR>
    };

    #[cfg(target_arch = "wasm32")]
    return view! {
        <FormFieldClient
            label=label
            error=error
            required=required
            help_text=help_text
            class=class
        >
            {children()}
        </FormFieldClient>
    };
}
