from contextlib import contextmanager

from nicegui import ui


@contextmanager
def section_header_row(*, classes: str = ""):
    """Render a standardized section header row container."""
    base_classes = "w-full items-center justify-between pb-2 ui-header-divider"
    with ui.row().classes(f"{base_classes} {classes}".strip()) as row:
        yield row


def render_empty_state(message: str, *, italic: bool = False, extra_classes: str = "") -> None:
    """Render standardized empty-state helper text."""
    classes = "text-xs ui-text-muted"
    if italic:
        classes = f"{classes} italic"
    ui.label(message).classes(f"{classes} {extra_classes}".strip())


def destructive_button(
    label: str,
    *,
    on_click,
    icon: str,
    variant: str = "outlined",
    extra_classes: str = "",
):
    """Render a standardized destructive action button."""
    button = ui.button(label, on_click=on_click, icon=icon)
    if variant == "solid":
        button.props("unelevated color=negative")
    else:
        button.props("outlined color=negative")
    if extra_classes:
        button.classes(extra_classes)
    return button
