import os
import re

# Navigation HTML with icons
nav_templates = {
    'index.html': '''      <nav class="nav">
        <a href="/index.html" class="active"><i class="fas fa-home"></i> Home</a>
        <a href="/quotation.html"><i class="fas fa-calculator"></i> Get Quote</a>
        <a href="/fleet.html"><i class="fas fa-car"></i> Our Fleet</a>
        <a href="/contact.html"><i class="fas fa-envelope"></i> Contact</a>
        <a href="/admin-login.html"><i class="fas fa-shield-alt"></i> Admin</a>
        <a href="/quotation.html" class="btn-quote"><i class="fas fa-calculator"></i> Live Quote</a>
      </nav>''',
    
    'quotation.html': '''      <nav class="nav">
        <a href="/index.html"><i class="fas fa-home"></i> Home</a>
        <a href="/quotation.html" class="active"><i class="fas fa-calculator"></i> Get Quote</a>
        <a href="/fleet.html"><i class="fas fa-car"></i> Our Fleet</a>
        <a href="/contact.html"><i class="fas fa-envelope"></i> Contact</a>
        <a href="/admin-login.html"><i class="fas fa-shield-alt"></i> Admin</a>
        <a href="/quotation.html" class="btn-quote"><i class="fas fa-calculator"></i> Live Quote</a>
      </nav>''',
    
    'fleet.html': '''      <nav class="nav">
        <a href="/index.html"><i class="fas fa-home"></i> Home</a>
        <a href="/quotation.html"><i class="fas fa-calculator"></i> Get Quote</a>
        <a href="/fleet.html" class="active"><i class="fas fa-car"></i> Our Fleet</a>
        <a href="/contact.html"><i class="fas fa-envelope"></i> Contact</a>
        <a href="/admin-login.html"><i class="fas fa-shield-alt"></i> Admin</a>
        <a href="/quotation.html" class="btn-quote"><i class="fas fa-calculator"></i> Live Quote</a>
      </nav>''',
    
    'contact.html': '''      <nav class="nav">
        <a href="/index.html"><i class="fas fa-home"></i> Home</a>
        <a href="/quotation.html"><i class="fas fa-calculator"></i> Get Quote</a>
        <a href="/fleet.html"><i class="fas fa-car"></i> Our Fleet</a>
        <a href="/contact.html" class="active"><i class="fas fa-envelope"></i> Contact</a>
        <a href="/admin-login.html"><i class="fas fa-shield-alt"></i> Admin</a>
        <a href="/quotation.html" class="btn-quote"><i class="fas fa-calculator"></i> Live Quote</a>
      </nav>''',
}

# Default nav for other pages
default_nav = '''      <nav class="nav">
        <a href="/index.html"><i class="fas fa-home"></i> Home</a>
        <a href="/quotation.html"><i class="fas fa-calculator"></i> Get Quote</a>
        <a href="/fleet.html"><i class="fas fa-car"></i> Our Fleet</a>
        <a href="/contact.html"><i class="fas fa-envelope"></i> Contact</a>
        <a href="/admin-login.html"><i class="fas fa-shield-alt"></i> Admin</a>
        <a href="/quotation.html" class="btn-quote"><i class="fas fa-calculator"></i> Live Quote</a>
      </nav>'''

main_pages = ['index.html', 'quotation.html', 'fleet.html', 'contact.html', 
              'locations.html', 'sitemap-towns.html', 'q-and-a.html', 
              'privacy.html', 'terms.html']

for page in main_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()
    
    # Get appropriate nav template
    nav_html = nav_templates.get(page, default_nav)
    
    # Check if nav with icons already exists
    if '<nav class="nav">' in content and '<i class="fas fa-home"></i>' in content:
        print(f"ℹ️  {page} - Already has nav with icons")
        continue
    
    # Remove old nav if exists
    content = re.sub(
        r'<nav class="nav">.*?</nav>',
        '',
        content,
        flags=re.DOTALL
    )
    
    # Add new nav after menu toggle button and before </div> closing header-content
    # Find the menu toggle button first
    if '<button class="menu-toggle"' in content:
        # Add after menu toggle closing </button>
        content = re.sub(
            r'(</button>)\s*(</div>\s*</header>)',
            r'\1\n\n' + nav_html + r'\n    \2',
            content,
            count=1
        )
        print(f"✅ Added nav with icons to {page}")
    else:
        print(f"⚠️  {page} - No menu toggle found")

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