#!/usr/bin/env python3
"""
Test script to verify the beautiful no-reviews sections are working
"""

import requests
import re
from urllib.parse import urljoin

def test_no_reviews_styling():
    """Test that the no-reviews sections have the new beautiful styling"""
    base_url = "http://localhost:8001"
    
    print("Testing beautiful no-reviews sections...")
    print("=" * 60)
    
    # Test restaurant detail page
    try:
        restaurants_response = requests.get(f"{base_url}/api/restaurants", timeout=10)
        if restaurants_response.status_code == 200:
            data = restaurants_response.json()
            if data.get('success') and data.get('restaurants'):
                restaurant_id = data['restaurants'][0]['id']
                print(f"Testing restaurant detail page for ID: {restaurant_id}")
                
                detail_url = f"{base_url}/restaurant/{restaurant_id}"
                detail_response = requests.get(detail_url, timeout=10)
                
                if detail_response.status_code == 200:
                    html_content = detail_response.text
                    
                    # Check for beautiful no-reviews CSS
                    css_checks = [
                        ('no-reviews gradient background', 'background: linear-gradient(135deg, #667eea 0%, #764ba2 100%)'),
                        ('shimmer animation', '@keyframes shimmer'),
                        ('pulse animation', '@keyframes pulse'),
                        ('review stats styling', '.review-stats'),
                        ('beautiful button styling', '.no-reviews .btn')
                    ]
                    
                    for check_name, css_pattern in css_checks:
                        if css_pattern in html_content:
                            print(f"✓ Found {check_name}")
                        else:
                            print(f"✗ Missing {check_name}")
                    
                    # Check for SweetAlert integration
                    if 'SweetAlert2' in html_content or 'Swal.fire' in html_content:
                        print("✓ Found SweetAlert2 integration")
                    else:
                        print("✗ SweetAlert2 integration not found")
                    
                    print(f"✓ Restaurant detail page loaded successfully ({len(html_content)} bytes)")
                else:
                    print(f"✗ Restaurant detail page failed to load: {detail_response.status_code}")
                    
        # Test beach detail page
        beach_url = f"{base_url}/beaches-grid"
        beach_response = requests.get(beach_url, timeout=10)
        
        if beach_response.status_code == 200:
            print("✓ Beach pages are accessible")
            
            # Check if we can access any beach detail
            # For now just verify the beaches-grid loads
            html_content = beach_response.text
            if 'beach' in html_content.lower():
                print("✓ Beach content detected")
            else:
                print("✗ No beach content detected")
        else:
            print(f"✗ Beach pages failed to load: {beach_response.status_code}")
            
    except requests.exceptions.RequestException as e:
        print(f"✗ Network error: {e}")
        return False
    
    print("=" * 60)
    print("✓ Beautiful no-reviews sections testing completed!")
    return True

if __name__ == "__main__":
    test_no_reviews_styling()