import os
import re

# List of ALL pages that might have Mercedes images
all_pages = [
    # Admin pages
    'admin-drivers.html', 'admin-messages.html', 'admin-new-booking.html',
    'admin-pricing.html', 'admin-quotes.html', 'admin.html', 'admin-login.html',
    # Other pages
    'acceptable-use.html', 'gdpr.html', 'promotional-terms.html',
    'sign-in.html', 'sign-up.html', 'success.html', 'test-menu.html',
    'terms_temp.html', 'terms_old_backup.html', 'reset-password.html'
]

for page in all_pages:
    file_path = page
    if not os.path.exists(file_path):
        print(f"⚠️  {page} - File not found")
        continue
    
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    original_content = content
    
    # Replace ALL old Mercedes image references with new one
    # Pattern 1: mercedes-eclass-2025.jpg
    content = re.sub(
        r'src="/mercedes-eclass-2025\.jpg"',
        r'src="/mercedes-logo-final.png"',
        content
    )
    
    # Pattern 2: mercedes-final.png
    content = re.sub(
        r'src="/mercedes-final\.png"',
        r'src="/mercedes-logo-final.png"',
        content
    )
    
    # Pattern 3: mercedes-transparent.png  
    content = re.sub(
        r'src="/mercedes-transparent\.png"',
        r'src="/mercedes-logo-final.png"',
        content
    )
    
    # Pattern 4: mercedes-black-2025.jpg
    content = re.sub(
        r'src="/mercedes-black-2025\.jpg"',
        r'src="/mercedes-logo-final.png"',
        content
    )
    
    # Pattern 5: mercedes-circular-logo.png
    content = re.sub(
        r'src="/mercedes-circular-logo\.png"',
        r'src="/mercedes-logo-final.png"',
        content
    )
    
    # Add proper styling if missing (50px for admin, white background)
    # Find img tags with mercedes-logo-final that don't have proper styling
    def add_styling(match):
        img_tag = match.group(0)
        if 'style=' not in img_tag or 'height:' not in img_tag:
            # Add styling before the closing >
            return img_tag.replace('/>', 'style="height: 50px; margin-left: 25px; background-color: white; padding: 4px; border-radius: 6px;" />')
        return img_tag
    
    content = re.sub(
        r'<img[^>]*src="/mercedes-logo-final\.png"[^>]*/?>',
        add_styling,
        content
    )
    
    if content != original_content:
        with open(file_path, 'w', encoding='utf-8') as f:
            f.write(content)
        print(f"✅ Updated {page}")
    else:
        print(f"ℹ️  {page} - Already using mercedes-logo-final.png")

print("\n✅ All admin and other pages now use mercedes-logo-final.png with proper styling!")
