import os
import re

html_files = [
    'index.html',
    'construction-company-in-krishnagiri.html',
    'home-builder-in-krishnagiri.html',
    'architecture-firm-in-krishnagiri.html',
    'interior-designers-in-krishnagiri.html',
    'about-us.html',
    'faq.html',
    'contact-us.html'
]

dir_path = r'd:\xampp\htdocs\mkconstruction'

# The exact old nav links string to match
old_nav_services = """                        <li><a href="construction-company-in-krishnagiri.html">Construction</a></li>
                        <li><a href="#services">Home Builder</a></li>
                        <li><a href="#services">Architecture</a></li>
                        <li><a href="#services">Interior Design</a></li>
                        <li><a href="#services">Other Services</a></li>"""

new_nav_services = """                        <li><a href="construction-company-in-krishnagiri.html">Construction</a></li>
                        <li><a href="home-builder-in-krishnagiri.html">Home Builder</a></li>
                        <li><a href="architecture-firm-in-krishnagiri.html">Architecture</a></li>
                        <li><a href="interior-designers-in-krishnagiri.html">Interior Design</a></li>
                        <li><a href="index.html#services">Other Services</a></li>"""

old_nav_more = """                        <li><a href="#about">About Us</a></li>
                        <li><a href="#contact">Contact Us</a></li>
                        <li><a href="#">FAQ</a></li>
                        <li><a href="#">Blogs</a></li>"""

new_nav_more = """                        <li><a href="about-us.html">About Us</a></li>
                        <li><a href="contact-us.html">Contact Us</a></li>
                        <li><a href="faq.html">FAQ</a></li>
                        <li><a href="blog.php">Blogs</a></li>"""

old_footer_quick = """                    <li><a href="#hero">Home</a></li>
                    <li><a href="#about">About Us</a></li>
                    <li><a href="#services">Services</a></li>
                    <li><a href="#contact">Contact</a></li>"""

new_footer_quick = """                    <li><a href="index.html">Home</a></li>
                    <li><a href="about-us.html">About Us</a></li>
                    <li><a href="index.html#services">Services</a></li>
                    <li><a href="contact-us.html">Contact</a></li>"""

old_footer_services = """                    <li><a href="#services">Vasthu Planning</a></li>
                    <li><a href="#services">Blueprint Design</a></li>
                    <li><a href="#services">Building Approvals</a></li>
                    <li><a href="#services">Home & Land Loans</a></li>"""

new_footer_services = """                    <li><a href="architecture-firm-in-krishnagiri.html">Vasthu Planning</a></li>
                    <li><a href="architecture-firm-in-krishnagiri.html">Blueprint Design</a></li>
                    <li><a href="construction-company-in-krishnagiri.html">Building Approvals</a></li>
                    <li><a href="index.html#services">Home & Land Loans</a></li>"""

for filename in html_files:
    filepath = os.path.join(dir_path, filename)
    
    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()

    content = content.replace(old_nav_services, new_nav_services)
    content = content.replace(old_nav_more, new_nav_more)
    content = content.replace(old_footer_quick, new_footer_quick)
    content = content.replace(old_footer_services, new_footer_services)
    
    # Also fix some ad-hoc links that might be global
    content = content.replace('href="#contact"', 'href="contact-us.html"')
    content = content.replace('href="#about"', 'href="about-us.html"')
    content = content.replace('href="#portfolio"', 'href="portfolio.php"')
    
    with open(filepath, 'w', encoding='utf-8') as f:
        f.write(content)

print("Linked all pages successfully.")
