"""Python language detection - based on editor state."""

from ..models import Context
from .state import DetectionState


def get_python_hint(mode: str = "reference") -> str | None:
    """Get activation hint for python detector."""
    if mode == "code":
        return "Opening a Python file in an editor"
    return None


def detect_python(state: DetectionState) -> Context | None:
    """Detect Python context from editor state.

    Only detects Python if an editor (like micro) has identified it.

    Args:
        state: Detection state with environment

    Returns:
        Python context if detected by editor
    """
    editor_lang = state.get("editor_language")
    if editor_lang == "python":
        return Context(
            name="python",
            type="language",
            priority=20,
            sheet="python",
            metadata={"mode": "editing", "editor": state.get("editor")},
        )

    return None
