






#!/usr/bin/env python3
"""
Simple test to verify the TTS footer layout changes.
"""

import sys
from pathlib import Path

import pytest

# Add the project root to Python path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))


def test_layout_structure():
    """Test that the layout structure is correct."""
    try:
        from textual.containers import Horizontal
        from textual.widgets import Static

        # Test the compose method structure by inspecting the code
        # Since we can't easily create a full Textual app context in tests,
        # we'll verify the expected structure exists in the compose method
        # Import the app class
        from speakub.ui.app import EPUBReaderApp

        # Check that the compose method exists
        assert hasattr(EPUBReaderApp, "compose"), "compose method not found"

        # Check that the expected widget types are imported
        # This is a basic sanity check
        assert Horizontal is not None, "Horizontal container not available"
        assert Static is not None, "Static widget not available"

        # Since we can't run compose() without a full app context,
        # we'll just verify that the method exists and the imports work
        print(
            "✅ Layout structure verification: compose method exists and imports are correct"
        )

    except Exception as e:
        pytest.fail(f"Error during layout test: {e}")


def test_update_method():
    """Test that the _update_tts_progress method works correctly."""
    print("\n🔄 Testing _update_tts_progress Method")
    print("=" * 40)

    try:
        from speakub.cli import EPUBReaderApp

        # Create an instance
        app = EPUBReaderApp("dummy.epub")

        # Mock the viewport content
        from speakub.ui.widgets.content_widget import ViewportContent

        app.viewport_content = ViewportContent(["line 1", "line 2", "line 3"], 2)

        # Set some test values
        app.tts_status = "PLAYING"
        app.tts_volume = 80
        app.tts_rate = 10
        app.tts_pitch = "+5Hz"
        app.tts_smooth_mode = True

        # Call the update method
        import asyncio

        asyncio.run(app._update_tts_progress())

        print("✅ _update_tts_progress method executed without errors")
        print("   - Status should show: 'TTS: PLAYING (Smooth)'")
        print("   - Controls should show: 'Vol: 80% | Speed: +10% | Pitch: +5Hz'")
        print("   - Page should show: 'Page 1/2'")

    except Exception as e:
        print(f"❌ Error testing update method: {e}")
        import traceback

        traceback.print_exc()
        pytest.fail(f"Error during update method test: {e}")


if __name__ == "__main__":
    print("🎵 TTS Footer Layout Verification")
    print("This script verifies the layout changes made to the TTS footer.\n")

    # Test layout structure
    layout_ok = test_layout_structure()

    # Test update method
    update_ok = test_update_method()

    if layout_ok and update_ok:
        print("\n🎉 All verification tests passed!")
        print("\n📋 Summary of Changes:")
        print("✅ Modified compose() method to use Horizontal container")
        print("✅ Created three Static components: tts-status, tts-controls, tts-page")
        print("✅ Updated _update_tts_progress() to update each component separately")
        print("✅ Left: TTS status (TTS: PLAYING)")
        print("✅ Center: Vol/Speed/Pitch controls (centered)")
        print("✅ Right: Page information (right-aligned)")
    else:
        print("\n❌ Some tests failed!")
        sys.exit(1)
