"""Renderer for thinking/reasoning blocks."""

from __future__ import annotations

from rich.box import ROUNDED
from rich.console import RenderableType
from rich.padding import Padding
from rich.panel import Panel
from rich.text import Text

from clients.terminal.tui.themes import get_active_theme

from .base import ContentRenderer


class ThinkingRenderer(ContentRenderer):
    """Render a complete thinking block.

    Sub-agent thinking (``is_subagent=True``) is rendered with a dim border, a
    ``subagent thinking`` title, and a left indent so it reads as nested inside
    the parent spawn_agent card rather than as a top-level turn event.
    """

    def accepts(self, msg: dict) -> bool:
        return msg.get("type") == "thinking_block"

    def render(self, msg: dict) -> RenderableType:
        theme = get_active_theme()
        text = msg.get("content", "")
        is_subagent = bool(msg.get("is_subagent", False))
        if is_subagent:
            panel = Panel(
                Text(text, style=theme.text_dim.hex),
                title="subagent thinking",
                title_align="left",
                border_style=theme.text_dim.hex,
                box=ROUNDED,
            )
            return Padding(panel, (0, 0, 0, 2))
        return Panel(
            Text(text, style=theme.text_dim.hex),
            title="thinking",
            title_align="left",
            border_style=theme.thinking.hex,
            box=ROUNDED,
        )