"""Tests for Rich display components."""

from agent_scout_cli.display.components import (
    action_panel,
    comparison_table,
    cost_display,
    error_panel,
    finish_panel,
    observation_panel,
    price_trend_display,
    sparkline,
    task_progress,
    thought_panel,
)


def test_thought_panel():
    panel = thought_panel("I should search for flights", 1)
    assert panel.title is not None
    assert "1" in str(panel.title)


def test_action_panel():
    panel = action_panel("web_search", {"query": "flights"})
    assert panel.title is not None


def test_action_panel_no_input():
    panel = action_panel("web_search")
    assert panel.title is not None


def test_observation_panel():
    panel = observation_panel("Found 3 results")
    assert panel.title is not None


def test_observation_panel_truncation():
    long_text = "x" * 1000
    panel = observation_panel(long_text, max_length=100)
    # Panel should exist without error
    assert panel is not None


def test_finish_panel():
    panel = finish_panel("The best flight is $450")
    assert panel.title is not None


def test_error_panel():
    panel = error_panel("Something went wrong")
    assert panel.title is not None


def test_cost_display():
    panel = cost_display(1000, 500, 0.05)
    assert panel.title is not None


def test_cost_display_with_budget():
    panel = cost_display(1000, 500, 0.05, budget_remaining=0.95)
    assert panel is not None


def test_comparison_table():
    table = comparison_table(
        "Flights",
        ["Airline", "Price", "Duration"],
        [["BA", "$450", "7h"], ["AA", "$500", "8h"]],
    )
    assert table.title == "Flights"
    assert table.row_count == 2


def test_task_progress():
    panel = task_progress(3, 10, "Searching...")
    assert panel is not None


def test_sparkline():
    result = sparkline([1, 2, 3, 4, 5])
    assert len(result) == 5
    # First char should be lowest, last should be highest
    assert result[0] != result[-1]


def test_sparkline_empty():
    assert sparkline([]) == ""


def test_sparkline_single_value():
    result = sparkline([5])
    assert len(result) == 1


def test_sparkline_wide():
    result = sparkline(list(range(100)), width=20)
    assert len(result) == 20


def test_price_trend_display():
    panel = price_trend_display("Flight NYC-LON", [450, 430, 420, 440, 410])
    assert panel is not None


def test_price_trend_display_empty():
    panel = price_trend_display("Flight", [])
    assert panel is not None
