#!/usr/bin/env python3
"""
Test script to visualize library pagination.
"""

from pathlib import Path
from dreader import LibraryManager

def test_pagination():
    """Test pagination with actual library"""
    library_path = Path(__file__).parent / 'tests' / 'data' / 'library-epub'

    # Create library manager (default books_per_page=6)
    library = LibraryManager(
        library_path=str(library_path),
        page_size=(800, 1200)
    )

    # Scan library
    books = library.scan_library()
    print(f"\nFound {len(books)} books")
    print(f"Books per page: {library.books_per_page}")
    print(f"Total pages: {library.get_total_pages()}")

    # Render all pages
    for page_num in range(library.get_total_pages()):
        library.set_page(page_num)
        print(f"\n=== Rendering Page {page_num + 1}/{library.get_total_pages()} ===")

        library.create_library_table()
        img = library.render_library()

        output_path = f'/tmp/library_pagination_page{page_num + 1}.png'
        img.save(output_path)
        print(f"Saved to {output_path}")

        # Show which books are on this page
        start_idx = page_num * library.books_per_page
        end_idx = min(start_idx + library.books_per_page, len(books))
        page_books = books[start_idx:end_idx]
        print(f"Books on this page ({len(page_books)}):")
        for book in page_books:
            print(f"  - {book['title']} by {book['author']}")

    # Cleanup
    library.cleanup()
    print("\nPagination test complete!")

if __name__ == '__main__':
    test_pagination()
