"""Reference picker overlay widget."""

from __future__ import annotations

import importlib
from typing import Any


def _load_static_base() -> type[Any]:
    try:
        return importlib.import_module("textual.widgets").Static
    except Exception:  # pragma: no cover

        class _FallbackStatic:
            def __init__(self, *args: object, **kwargs: object) -> None:
                self._text = ""

            def update(self, text: str) -> None:
                self._text = text

        return _FallbackStatic


_StaticBase = _load_static_base()


class ReferencePickerOverlay(_StaticBase):
    """Simple overlay displaying reference suggestions."""

    def set_suggestions(self, query: str, suggestions: list[str]) -> None:
        if not suggestions:
            self.update(f"@{query}\n(no matches)")
            return
        lines = [f"@{query}"]
        for item in suggestions[:10]:
            lines.append(f"  {item}")
        self.update("\n".join(lines))
