use leptos::prelude::*;

use crate::theme::{Size, Variant};

#[component]
pub fn ButtonSSR(
    children: Children,
    variant: Variant,
    size: Size,
    button_type: &'static str,
    loading: bool,
    disabled: bool,
    class: &'static str,
) -> impl IntoView {
    let base_classes = "ds-btn";
    let combined_classes = format!(
        "{} {} {} {}",
        base_classes,
        variant.classes(),
        size.classes(),
        class
    );

    let is_disabled = loading || disabled;

    view! {
        <button
            type=button_type
            class=combined_classes
            disabled=is_disabled
        >
            {if loading {
                view! {
                    <span class="flex items-center gap-2">
                        <span>"Loading..."</span>
                        {children()}
                    </span>
                }.into_any()
            } else {
                children().into_any()
            }}
        </button>
    }
}
