import os
import re

html_files = [
    'd:\\iss\\Franciscan Society\\index.html',
    'd:\\iss\\Franciscan Society\\about.html',
    'd:\\iss\\Franciscan Society\\gallery.html'
]

# The old YouTube button block
yt_old = """<div onclick="window.open('https://youtube.com', '_blank')" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 999; transition: background 0.3s;">
                                <div style="width: 48px; height: 34px; background: #FF0000; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 4px 12px rgba(255,0,0,0.5); transition: transform 0.3s;">
                                    <svg viewBox="0 0 24 24" fill="currentColor" width="20" height="20" style="margin-left: 3px;">
                                        <path d="M8 5v14l11-7z"/>
                                    </svg>
                                </div>
                            </div>"""

# The new YouTube button, matching Facebook, Instagram, LinkedIn
yt_new = """<a href="https://youtube.com" target="_blank" aria-label="YouTube" style="width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); color: #ffffff; display: flex; align-items: center; justify-content: center; text-decoration: none; transition: all 0.3s ease;" onmouseover="this.style.background='#FF0000'; this.style.borderColor='#FF0000';" onmouseout="this.style.background='rgba(255,255,255,0.06)'; this.style.borderColor='rgba(255,255,255,0.12)';">
                                    <svg viewBox="0 0 24 24" fill="currentColor" width="16" height="16" style="margin-left: 2px;">
                                        <path d="M8 5v14l11-7z"/>
                                    </svg>
                                </a>"""

for file_path in html_files:
    if not os.path.exists(file_path):
        continue
        
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()

    # 1. Replace YouTube button
    content = content.replace(yt_old, yt_new)
    
    # 2. Fix the magnetic script: remove the innerSpan transform logic
    # Find the chunk and remove it
    script_to_remove = """                        const innerSpans = elem.querySelectorAll('span');
                        innerSpans.forEach(span => {
                            span.style.transition = 'transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)';
                            span.style.display = 'inline-block'; // required for transform
                            span.style.transform = `translate(${x * 0.15}px, ${y * 0.15}px)`;
                        });"""
    content = content.replace(script_to_remove, "")
    
    # Also remove the mouseleave innerSpans reset
    leave_to_remove = """                        const innerSpans = elem.querySelectorAll('span');
                        innerSpans.forEach(span => {
                            span.style.transform = `translate(0px, 0px)`;
                        });"""
    content = content.replace(leave_to_remove, "")

    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)
    print(f"Fixed YouTube icon and button text tilt in {file_path}")
