#!/usr/bin/env python3
"""
Fix mobile sidebar navigation translations
"""

from pathlib import Path
from bs4 import BeautifulSoup

def fix_mobile_sidebar(html_file):
    """Fix mobile sidebar navigation"""
    html_path = Path(html_file)
    if not html_path.exists():
        return False
    
    with open(html_path, 'r', encoding='utf-8', errors='ignore') as f:
        content = f.read()
    
    soup = BeautifulSoup(content, 'html.parser')
    changed = False
    
    # Find mobile sidebar
    mobile_sidebar = soup.find('div', class_='mobile-sidebar-nav')
    if mobile_sidebar:
        # Fix "About Us" main link
        about_main = mobile_sidebar.find('a', href=lambda x: x and 'about-ar.html' in str(x) and 'submenu' not in str(x.parent.get('class', [])))
        if about_main:
            parent_li = about_main.find_parent('li', class_='has-submenu')
            if parent_li:
                text = about_main.get_text(strip=True)
                if text == 'عن السيف':
                    about_main.string = 'من نحن'
                    changed = True
    
    if changed:
        with open(html_path, 'w', encoding='utf-8') as f:
            f.write(str(soup))
        print(f"✓ Fixed mobile sidebar in {html_file}")
        return True
    
    return False

if __name__ == "__main__":
    arabic_pages = [
        'home-ar.html',
        'about-ar.html',
        'ourService-ar.html',
        'project-ar.html',
        'contactUs-ar.html',
    ]
    
    fixed = 0
    for page in arabic_pages:
        if fix_mobile_sidebar(page):
            fixed += 1
    
    print(f"\nFixed {fixed} files")
