"""Await-user block renderers: blocks that prompt for input (prompt handles all display)."""

from __future__ import annotations

from yera.console.prompts import prompt_buttons, prompt_date, prompt_slider, prompt_text
from yera.console.render_result import AwaitUserResult
from yera.events.models import ButtonsData, DatePickerData, InputRequestData, SliderData


def render_input_request(data: InputRequestData) -> AwaitUserResult:
    """Input request block: prompt for text."""
    message = data.message or "Input"
    return AwaitUserResult(collect_input=lambda c: prompt_text(c, message))


def render_buttons(data: ButtonsData) -> AwaitUserResult:
    """Buttons block: prompt for choice from options."""
    return AwaitUserResult(
        collect_input=lambda c: prompt_buttons(
            console=c, options=data.options, label=data.label
        ),
    )


def render_slider(data: SliderData) -> AwaitUserResult:
    """Slider block: prompt for value in range."""
    return AwaitUserResult(
        collect_input=lambda c: str(
            prompt_slider(
                c,
                data.label,
                data.min_value,
                data.max_value,
                data.initial_value,
            )
        ),
    )


def render_date(data: DatePickerData) -> AwaitUserResult:
    """Date block: prompt for date."""
    return AwaitUserResult(
        collect_input=lambda c: prompt_date(c, data.label, data.value),
    )
