import glob
import re

html_files = glob.glob("*.html")

lang_switcher_new = """    <!-- Language Flags -->
    <div class="lang-switcher top-right">
        <a href="#" class="lang-btn active" data-lang="vi" title="Tiếng Việt"><img src="https://flagcdn.com/w40/vn.png" alt="VI"></a>
        <a href="#" class="lang-btn" data-lang="en" title="English"><img src="https://flagcdn.com/w40/gb.png" alt="EN"></a>
        <a href="#" class="lang-btn" data-lang="ja" title="日本語"><img src="https://flagcdn.com/w40/jp.png" alt="JP"></a>
        <a href="#" class="lang-btn" data-lang="ko" title="한국어"><img src="https://flagcdn.com/w40/kr.png" alt="KR"></a>
    </div>"""

new_footer_contact = """<div class="footer-contact">
                <h4>LIÊN HỆ & HỖ TRỢ</h4>
                <p><i class="fa-solid fa-phone" style="width:20px; color:var(--gold);"></i> Hotline: 0938 332 308</p>
                <p><i class="fa-solid fa-comment-dots" style="width:20px; color:var(--gold);"></i> Zalo: <a href="https://zalo.me/0938332308" style="color:var(--text-white); text-decoration:none;">0938 332 308</a></p>
                <p><i class="fa-solid fa-envelope" style="width:20px; color:var(--gold);"></i> info@aodaithaonguyen.vn</p>
                <p><i class="fa-solid fa-map-location-dot" style="width:20px; color:var(--gold);"></i> <a href="https://www.google.com/maps/search/Ho+Chi+Minh+City" target="_blank" style="color:var(--gold); text-decoration:underline;">Chỉ đường Google Maps</a></p>
            </div>"""

for f in html_files:
    with open(f, 'r') as file:
        content = file.read()
    
    # 1. Remove old lang-switcher div from inside the nav container
    content = re.sub(r'\s*<div class="lang-switcher">[\s\S]*?</div>', '', content)
    
    # 2. Inject new lang-switcher at the beginning of the header
    content = content.replace('<header class="navbar-mockup" style="position:relative;">', '<header class="navbar-mockup" style="position:relative;">\n' + lang_switcher_new)
    # Or in case it wasn't position relative yet
    content = content.replace('<header class="navbar-mockup">', '<header class="navbar-mockup" style="position:relative;">\n' + lang_switcher_new)

    # 3. Replace all variations of the footer-contact div
    footer_pattern = r'<div class="footer-contact">[\s\S]*?</div>(\s*</div>\s*<div class="copyright text-center">)'
    content = re.sub(footer_pattern, new_footer_contact + r'\1', content)
    
    with open(f, 'w') as file:
        file.write(content)

print(f"Updated flags, Zalo, Maps, and phone numbers in {len(html_files)} files.")
