import re
import sys

# Read the copied shared-hosting.html
with open(r'd:\DN\final_page_project\shared-hosting.html', 'r', encoding='utf-8') as f:
    html = f.read()

# 1. Replace Title
html = html.replace('<title>CloudMate - One Stop for All Your Business Needs</title>', '<title>Shared Hosting - CloudMate</title>')

# 2. Replace Hero content
html = html.replace('<h1>Cloud Hosting <br />Built for Your Success</h1>', '<h1>Building your own<br>website just got easier.</h1>')
html = html.replace(
    '<p>\n                        Fast, secure, and reliable cloud hosting services powered by\n                        enterprise-grade infrastructure. Perfect for businesses of all\n                        sizes.\n                    </p>',
    '<p>CloudMate Shared Hosting services delivers a Low-cost affordable hosting to get you started, perfect for your blogs/business websites.</p>'
)

# 3. Replace Hero image with Lottie animation
lottie_html = '''<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
                    <lottie-player src="https://assets8.lottiefiles.com/packages/lf20_tnoqsv4p.json" background="transparent" speed="1" style="width: 100%; height: auto; max-width: 650px; margin: auto;" loop autoplay></lottie-player>'''
html = html.replace('<img src="assets/banner-image.png" alt="Cloud Hosting Illustration" />', lottie_html)

# 4. Replace Pricing Section Title
html = html.replace('<h4 class="se-title-2">Get More Power With Our Managed Business Plans</h4>', '<h4 class="se-title-2">Shared server hosting plans and pricing</h4>')

# 5. Extract Shared Hosting Plans from content.md and inject
with open(r'C:\Users\Nikita Rajput\.gemini\antigravity-ide\brain\28413561-d1e4-432f-92a9-82b86e63153c\.system_generated\steps\42\content.md', 'r', encoding='utf-8') as f:
    shared_md = f.read()

# find the plans block in content.md
match = re.search(r'<div class="row">\s*<!-- col -->\s*<div class="col-xl-3(.*?)</div>\s*</div>\s*</div>\s*<!-- se-footer -->', shared_md, re.DOTALL)
if match:
    plans_html = '<div class="row mx-xl-0">\n          <!-- col -->\n          <div class="col-xl-3' + match.group(1) + '</div>\n          </div>'
    # fix images
    plans_html = plans_html.replace('data-src="', 'src="')
    plans_html = plans_html.replace('src="/assets/', 'src="assets/')
    
    # inject plans_html into our html
    html = re.sub(r'<div class="row mx-xl-0">.*?</div>\s*</div>\s*<!-- se-footer -->', plans_html + '\n        </div>\n        <!-- se-footer -->', html, flags=re.DOTALL)
else:
    print("Could not extract plans from content.md")
    sys.exit(1)
    
with open(r'd:\DN\final_page_project\shared-hosting.html', 'w', encoding='utf-8') as f:
    f.write(html)
    
print("Successfully generated shared-hosting.html")
