from pathlib import Path

from textual.widgets import ContentSwitcher, DataTable, Static

from absolutelyright.tui import AbsolutelyApp


async def test_dashboard_loads_and_renders(claude_dir: Path) -> None:
    app = AbsolutelyApp(claude_dir=claude_dir)
    async with app.run_test() as pilot:
        await pilot.pause()
        await app.workers.wait_for_complete()
        await pilot.pause()

        stats = app.query_one("#stats", Static)
        assert "absolutely right 1 times" in str(stats.content)

        prompts = app.query_one("#prompts", DataTable)
        assert prompts.row_count == 1  # "fix the bug in auth" x2


async def test_sidebar_switches_sections(claude_dir: Path) -> None:
    app = AbsolutelyApp(claude_dir=claude_dir)
    async with app.run_test() as pilot:
        await pilot.pause()
        switcher = app.query_one("#detail", ContentSwitcher)
        assert switcher.current == "overview"

        await pilot.press("down")
        assert switcher.current == "sessions"

        await pilot.press("down", "down", "down", "down", "down", "down")
        assert switcher.current == "hours"


async def test_window_binding_reloads(claude_dir: Path) -> None:
    app = AbsolutelyApp(claude_dir=claude_dir)
    async with app.run_test() as pilot:
        await pilot.pause()
        await app.workers.wait_for_complete()

        await pilot.press("7")
        await app.workers.wait_for_complete()
        await pilot.pause()

        assert app.days == 7
        stats = app.query_one("#stats", Static)
        assert "last 7d" in str(stats.content)
