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

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

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

/// Pagination component
///
/// Provides page navigation controls.
///
/// # Examples
///
/// ```rust
/// use leptos::prelude::*;
/// use vapora_leptos_ui::Pagination;
///
/// #[component]
/// fn DataList() -> impl IntoView {
///     let (page, set_page) = signal(1);
///
///     view! {
///         <Pagination
///             current_page=page.get()
///             total_pages=10
///             on_page_change=move |p| set_page(p)
///         />
///     }
/// }
/// ```
#[component]
pub fn Pagination(
    /// Current active page (1-indexed)
    current_page: usize,
    /// Total number of pages
    total_pages: usize,
    /// Callback when page changes
    #[prop(optional)]
    #[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))]
    on_page_change: Option<Callback<usize>>,
    /// Additional CSS classes
    #[prop(default = "")]
    class: &'static str,
) -> impl IntoView {
    #[cfg(not(target_arch = "wasm32"))]
    return view! {
        <PaginationSSR
            current_page=current_page
            total_pages=total_pages
            class=class
        />
    };

    #[cfg(target_arch = "wasm32")]
    return view! {
        <PaginationClient
            current_page=current_page
            total_pages=total_pages
            on_page_change=on_page_change.unwrap_or(Callback::new(|_| {}))
            class=class
        />
    };
}
