use leptos::prelude::*;

#[component]
pub fn FormFieldSSR(
    label: String,
    error: Option<String>,
    required: bool,
    help_text: Option<String>,
    children: Children,
    class: &'static str,
) -> impl IntoView {
    view! {
        <div class={format!("flex flex-col gap-2 {}", class)}>
            <label class="text-sm font-medium text-white">
                {label}
                {required.then(|| view! { <span class="text-red-400 ml-1">"*"</span> })}
            </label>

            {children()}

            {error.map(|err| {
                view! {
                    <span class="text-sm text-red-400">
                        {err}
                    </span>
                }
            })}

            {help_text.map(|text| {
                view! {
                    <span class="text-sm text-white/60">
                        {text}
                    </span>
                }
            })}
        </div>
    }
}
