"""Renderer for error events."""

from __future__ import annotations

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

from clients.terminal.tui.themes import get_active_theme

from .base import ContentRenderer


class ErrorRenderer(ContentRenderer):
    """Render an error message panel."""

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

    def render(self, msg: dict) -> RenderableType:
        theme = get_active_theme()
        text = msg.get("message", "unknown error")
        return Panel(
            Text(text, style=f"bold {theme.error.hex}"),
            title="error",
            title_align="left",
            border_style=theme.error.hex,
            box=ROUNDED,
        )
