import os
import re

# List of ALL pages with navigation
all_pages = [
    'index.html', 'quotation.html', 'fleet.html', 'contact.html',
    'locations.html', 'sitemap-towns.html', 'q-and-a.html', 
    'privacy.html', 'terms.html',
    'admin-drivers.html', 'admin-messages.html', 'admin-new-booking.html',
    'admin-pricing.html', 'admin-quotes.html', 'admin.html',
]

# Icon mappings for menu items
icon_mappings = {
    'Home': 'fa-home',
    'Get Quote': 'fa-calculator',
    'Our Fleet': 'fa-car',
    'Fleet': 'fa-car',
    'Contact': 'fa-envelope',
    'Admin': 'fa-shield-alt',
    'Live Quote': 'fa-calculator',
    'Dashboard': 'fa-tachometer-alt',
    'Bookings': 'fa-calendar-check',
    'Quotes': 'fa-file-invoice-dollar',
    'Drivers': 'fa-users',
    'Pricing': 'fa-dollar-sign',
    'Messages': 'fa-comments',
    'Settings': 'fa-cog',
    'Logout': 'fa-sign-out-alt',
}

for page in all_pages:
    if not os.path.exists(page):
        print(f"⚠️  {page} - File not found")
        continue
    
    with open(page, 'r', encoding='utf-8') as f:
        content = f.read()
    
    original_content = content
    changes_made = False
    
    # Add icons to navigation links
    for text, icon in icon_mappings.items():
        # Pattern 1: <a href="...">Text</a> - add icon before text
        pattern1 = r'(<a href="[^"]*">)(' + re.escape(text) + r'</a>)'
        if re.search(pattern1, content) and f'<i class="fas {icon}">' not in content:
            replacement = r'\1<i class="fas ' + icon + r'"></i> \2'
            content = re.sub(pattern1, replacement, content)
            changes_made = True
        
        # Pattern 2: <a ...>Text</a> - for links with classes
        pattern2 = r'(<a [^>]*>)(' + re.escape(text) + r'</a>)'
        if re.search(pattern2, content):
            # Check if icon doesn't already exist
            matches = list(re.finditer(pattern2, content))
            for match in matches:
                full_match = match.group(0)
                if f'<i class="fas {icon}">' not in full_match and '<i class="fas' not in full_match:
                    # Add icon
                    content = content.replace(
                        match.group(0),
                        match.group(1) + f'<i class="fas {icon}"></i> ' + match.group(2)
                    )
                    changes_made = True
    
    if changes_made or content != original_content:
        with open(page, 'w', encoding='utf-8') as f:
            f.write(content)
        print(f"✅ Added navigation icons to {page}")
    else:
        print(f"ℹ️  {page} - Icons already present or no nav found")

print("\n" + "="*60)
print("✅ Navigation icons added to all pages!")
print("="*60)
