"""Footer component showing item range indicator."""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/components/footer.ipynb.

# %% auto #0
__all__ = ['render_footer']

# %% ../../nbs/components/footer.ipynb #f78d4045
from fasthtml.common import Div, Span

from cjm_fasthtml_tailwind.utilities.spacing import p
from cjm_fasthtml_tailwind.utilities.typography import font_size
from cjm_fasthtml_tailwind.utilities.effects import opacity
from cjm_fasthtml_tailwind.core.base import combine_classes

from ..core.models import VirtualCollectionState
from ..core.html_ids import VirtualCollectionHtmlIds
from ..core.windowing import compute_window

# %% ../../nbs/components/footer.ipynb #cca999ea
def render_footer(state: VirtualCollectionState,     # Collection state
                  ids: VirtualCollectionHtmlIds,      # HTML IDs
                  oob: bool = False,                  # Whether to include hx-swap-oob
                 ) -> Div:  # Footer element
    """Render the footer with item range indicator."""
    render_start, render_end = compute_window(
        state.window_start, state.visible_rows, state.total_items
    )

    if state.total_items == 0:
        text = "No items"
    else:
        text = f"Showing {render_start + 1}-{render_end} of {state.total_items:,} items"

    footer = Div(
        Span(text),
        id=ids.footer,
        cls=combine_classes(font_size.sm, opacity(70), p.x(2), p.y(1)),
    )

    if oob:
        footer.attrs["hx-swap-oob"] = "outerHTML"

    return footer
