"""Platform dispatcher — exports get_selected_text() for the current OS."""

from __future__ import annotations

import sys


def get_selected_text(stealth: bool = False) -> str:
    """Return currently selected text in the active application.

    Args:
        stealth: When True on Windows, attempt to capture text via
                 Win32 Edit messages (no keyboard events) before falling
                 back to the standard Ctrl+C clipboard method.
    """
    if sys.platform == "win32":
        if stealth:
            from .selection_win_uia import get_selected_text_stealth

            text = get_selected_text_stealth()
            if text:
                return text
            # Fallback: standard clipboard method
        from .selection_win import get_selected_text as _fn

        return _fn()
    elif sys.platform == "darwin":
        from .selection_mac import get_selected_text as _fn

        return _fn()
    else:
        raise RuntimeError(f"Unsupported platform: {sys.platform}")
