import re

files_info = {
    'SOUTH LIVING.html': ('SOUTH LIVING', 'South Living {i}.webp', 'South Living'),
    'HAYAT.html': ('HAYAT', 'Hayat Residences {i}.webp', 'Hayat Residences'),
    'SOUTH BAY.html': ('SOUTH BAY', 'South Bay {i}.webp', 'South Bay'),
    'BEACHFRONT.html': ('BEACHFRONT', 'Beachfront Gates PD {i}.webp', 'Beachfront Gates')
}

for filename, (folder, img_pattern, title) in files_info.items():
    with open(filename, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # Generate carousel items
    items = []
    for i in range(1, 11):
        img_name = img_pattern.format(i=i)
        item = f'''
                            <div class="item">
                                <div class="picframe">
                                    <a class="image-popup-gallery" href="./DUBAI-SOUTH-IMAGES/{folder}/{img_name}">
                                        <span class="overlay">
                                            <span class="pf_title">
                                                <i class="icon_search"></i>
                                            </span>
                                            <span class="pf_caption">
                                                {title}
                                            </span>
                                        </span>
                                    </a>
                                    <img src="./DUBAI-SOUTH-IMAGES/{folder}/{img_name}" alt="">
                                </div>
                            </div>'''
        items.append(item)
    
    carousel_html = ''.join(items)
    
    # Replace the empty carousel with the new items
    content = content.replace('<div id="room-carousel" class="owl-2-cols-center owl-carousel owl-theme">\n\n                        </div>', f'<div id="room-carousel" class="owl-2-cols-center owl-carousel owl-theme">\n{carousel_html}\n                        </div>')
    
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print(f'Done {filename}')
