import re

GALLERY_IMAGES = [
    'gallery_1_1785739465440.png',
    'gallery_2_1785739478020.png',
    'gallery_3_1785739488033.png',
    'gallery_4_1785739507745.png',
    'gallery_5_1785739518760.png',
    'gallery_6_1785739530049.png'
]

GRID_HTML = '''
<!-- Gallery Grid Section -->
<section id="gallery-grid" style="padding: 5rem 2rem 5rem 2rem; background-color: #F1F1F1; box-sizing: border-box;">
    <div style="max-width: 1200px; margin: 0 auto;">
        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 2.5rem;">
'''
for img in GALLERY_IMAGES:
    GRID_HTML += f'''            <div style="overflow: hidden; border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); transition: transform 0.4s ease;">
                <img src="assets/images/{img}" alt="Church Gallery Image" style="width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4/3; display: block; transition: transform 0.6s ease;" onmouseover="this.style.transform='scale(1.05)'" onmouseout="this.style.transform='scale(1)'">
            </div>
'''
GRID_HTML += '''        </div>
    </div>
</section>
'''

HERO_HTML = '''
    <!-- Gallery Hero Section -->
    <section style="position: relative; padding-top: 180px; padding-bottom: 120px; background: url('assets/images/church-bg.jpg') center/cover no-repeat;">
        <div style="position: absolute; inset: 0; background: rgba(20, 33, 58, 0.75);"></div>
        <div style="position: relative; z-index: 10; max-width: 1200px; margin: 0 auto; padding: 0 2rem; text-align: center;">
            <h1 style="font-family: 'Phudu', sans-serif !important; font-size: clamp(3rem, 5vw, 4.5rem); font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: -0.02em; margin-bottom: 1rem;">OUR GALLERY</h1>
            <div style="font-family: 'Instrument Sans', sans-serif; font-size: 1.05rem; font-weight: 600; color: #e7e2d6;">
                Home / Image Gallery
            </div>
        </div>
    </section>
'''

with open('index.html', 'r', encoding='utf-8') as f:
    content = f.read()

header = content[:content.find('<main')]
header = re.sub(r'<!-- Unclippable Flying Bible.*?</div>', '', header, flags=re.DOTALL)
footer = content[content.find('</main>'):]
footer = re.sub(r'<div id="welcome-scroll-bible-container".*?</div>', '', footer, flags=re.DOTALL)

new_content = header + '<main id="main-content" style="padding-top: 0; background-color: #FFFFFF;">\n' + HERO_HTML + GRID_HTML + '\n' + footer

new_content = re.sub(r'<title>.*?</title>', '<title>Image Gallery | The Franciscan Society</title>', new_content)

with open('gallery.html', 'w', encoding='utf-8') as f:
    f.write(new_content)
print('Done fixing gallery.html')
