"""Tests for the turn-duration metadata renderer."""

from __future__ import annotations

from rich.console import Console

from clients.terminal.tui.renderers.turn_meta import TurnMetaRenderer
from clients.terminal.tui.themes import set_active_theme


def _render_text(renderable) -> str:
    console = Console(record=True, width=80, force_terminal=True, color_system=None)
    console.print(renderable)
    return console.export_text()


def test_turn_meta_renders_elapsed() -> None:
    set_active_theme("gnexus-dark")
    out = _render_text(TurnMetaRenderer().render({"type": "turn_meta", "elapsed_seconds": 136}))
    assert "⏱ 2m 16s" in out


def test_turn_meta_renders_dash_when_backend_omitted_elapsed() -> None:
    set_active_theme("gnexus-dark")
    out = _render_text(TurnMetaRenderer().render({"type": "turn_meta", "elapsed_seconds": None}))
    assert "⏱ —" in out


def test_turn_meta_accepts_only_turn_meta() -> None:
    r = TurnMetaRenderer()
    assert r.accepts({"type": "turn_meta"}) is True
    assert r.accepts({"type": "status"}) is False