"""HTMX utilities for detecting and handling HTMX requests."""

from quart import request


def is_htmx_request() -> bool:
    """
    Check if the current request is an HTMX request.

    Returns:
        bool: True if HX-Request header is present and true
    """
    return request.headers.get("HX-Request", "").lower() == "true"


def get_htmx_target() -> str | None:
    """
    Get the target element ID from HTMX request headers.

    Returns:
        str | None: Target element ID or None
    """
    return request.headers.get("HX-Target")


def get_htmx_trigger() -> str | None:
    """
    Get the trigger element ID from HTMX request headers.

    Returns:
        str | None: Trigger element ID or None
    """
    return request.headers.get("HX-Trigger")


def should_return_fragment() -> bool:
    """
    Determine if we should return a fragment vs full page.

    For HTMX requests, return fragment.
    For normal requests, return full page.

    Returns:
        bool: True if fragment should be returned
    """
    return is_htmx_request()
