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

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

/// Glassmorphism modal component with backdrop
///
/// Renders content in a full-screen overlay with a backdrop.
/// Closes on backdrop click.
///
/// **Usage:** Conditionally render the modal:
///
/// ```rust
/// use leptos::prelude::*;
/// use vapora_leptos_ui::Modal;
///
/// let (show, set_show) = signal(false);
///
/// view! {
///     <button on:click=move |_| set_show(true)>"Open Modal"</button>
///
///     {move || if show.get() {
///         view! {
///             <Modal on_close=Callback::new(move |_| set_show(false))>
///                 <h2>"Modal Title"</h2>
///                 <p>"Modal content"</p>
///             </Modal>
///         }
///     } else {
///         view! {}
///     }}
/// }
/// ```
#[component]
pub fn Modal(
    /// Modal content
    children: Children,
    /// Close handler
    #[prop(optional)]
    on_close: Option<Callback<ev::MouseEvent>>,
    /// Additional CSS classes for modal content
    #[prop(default = "")]
    class: &'static str,
) -> impl IntoView {
    let _on_close = on_close.unwrap_or(Callback::new(|_| {}));

    #[cfg(not(target_arch = "wasm32"))]
    return view! {
        <ModalSSR class=class>
            {children()}
        </ModalSSR>
    };

    #[cfg(target_arch = "wasm32")]
    return view! {
        <ModalClient on_close=_on_close class=class>
            {children()}
        </ModalClient>
    };
}
