import re

# Update index.html
with open('/var/www/html/undangan_digital/index.html', 'r') as f:
    html = f.read()

# Make couple-cards animate from left and right
html = html.replace('<div class="couple-wrap reveal">', '<div class="couple-wrap">')
html = html.replace('<div class="couple-card">', '<div class="couple-card reveal-left">', 1)
html = html.replace('<div class="couple-card">', '<div class="couple-card reveal-right">', 1) # second one

# Make acara-cards animate from left and right
html = html.replace('<div class="acara-grid reveal">', '<div class="acara-grid">')
html = html.replace('<div class="acara-card">', '<div class="acara-card reveal-left">', 1)
html = html.replace('<div class="acara-card">', '<div class="acara-card reveal-right">', 1)

# Make gallery scale up
html = html.replace('<div class="gallery-grid reveal">', '<div class="gallery-grid reveal-scale">')

# Make bank cards scale up
html = html.replace('<div class="qris-card reveal">', '<div class="qris-card reveal-scale">')

with open('/var/www/html/undangan_digital/index.html', 'w') as f:
    f.write(html)

# Update style.css
with open('/var/www/html/undangan_digital/style.css', 'r') as f:
    css = f.read()

old_reveal = """.reveal { opacity:0; transform:translateY(40px); transition:opacity .8s ease, transform .8s ease; }
.reveal.visible { opacity:1; transform:translateY(0); }"""

new_reveal = """/* ── REVEAL ANIMATIONS ── */
.reveal, .reveal-up, .reveal-left, .reveal-right, .reveal-scale, .reveal-fade {
  opacity: 0;
  transition: opacity 1.2s cubic-bezier(0.165, 0.84, 0.44, 1), transform 1.2s cubic-bezier(0.165, 0.84, 0.44, 1);
  will-change: opacity, transform;
}
.reveal, .reveal-up { transform: translateY(60px); }
.reveal-left { transform: translateX(-60px); }
.reveal-right { transform: translateX(60px); }
.reveal-scale { transform: scale(0.85); }
.reveal-fade { transform: translateY(0); }

.reveal.visible, .reveal-up.visible, .reveal-left.visible, .reveal-right.visible, .reveal-scale.visible, .reveal-fade.visible {
  opacity: 1;
  transform: translate(0) scale(1);
}"""

if old_reveal in css:
    css = css.replace(old_reveal, new_reveal)
else:
    # Just append if not found exactly
    css += "\n" + new_reveal

with open('/var/www/html/undangan_digital/style.css', 'w') as f:
    f.write(css)

# Update script.js
with open('/var/www/html/undangan_digital/script.js', 'r') as f:
    script = f.read()

script = script.replace("document.querySelectorAll('.reveal').forEach", "document.querySelectorAll('.reveal, .reveal-up, .reveal-left, .reveal-right, .reveal-scale, .reveal-fade').forEach")

with open('/var/www/html/undangan_digital/script.js', 'w') as f:
    f.write(script)

print("Animations upgraded.")
