"""Shared syntax-highlighting helper for code rendered in the TUI.

The single point of assignment for the code colour scheme is
``Theme.code_theme`` (see ``clients/terminal/tui/themes.py``). Every renderer
that shows code — markdown fenced blocks (via ``_theme_aware_code_theme``),
code artifacts, and the filesystem ``read`` tool output — builds its
``rich.syntax.Syntax`` through :func:`highlight_code` so the whole UI shares
one Pygments style per theme.
"""

from __future__ import annotations

from rich.syntax import Syntax

from clients.terminal.tui.themes import Theme


def highlight_code(
    code: str,
    language: str,
    *,
    theme: Theme,
    line_numbers: bool = False,
    start_line: int = 1,
    word_wrap: bool = True,
) -> Syntax:
    """Return a ``rich.syntax.Syntax`` renderable styled by ``theme.code_theme``.

    ``language`` is a Pygments lexer name (or ``"text"`` for plain output).
    The background is the theme's ``surface`` colour so a code block reads as
    a distinct surface panel, matching the code-artifact renderer.
    """
    return Syntax(
        code,
        language,
        theme=theme.code_theme,
        background_color=theme.surface.hex,
        line_numbers=line_numbers,
        start_line=start_line,
        word_wrap=word_wrap,
    )