const fs = require('fs');
const path = require('path');

const slidesDir = path.join(__dirname, 'slides');
const files = fs.readdirSync(slidesDir).filter(f => f.endsWith('.html') && f !== 'slide1_title.html');

const flagCSSFix = `/* Italian flag diagonal - simple rectangles positioned diagonally */
.flag-green {
  position: absolute;
  top: 15pt;
  left: 15pt;
  width: 45pt;
  height: 12pt;
  background: #2D5016;
  opacity: 0.85;
}

.flag-white {
  position: absolute;
  top: 27pt;
  left: 27pt;
  width: 45pt;
  height: 12pt;
  background: #F5F5DC;
  opacity: 0.85;
}

.flag-red {
  position: absolute;
  top: 39pt;
  left: 39pt;
  width: 45pt;
  height: 12pt;
  background: #8B1A1A;
  opacity: 0.85;
}`;

files.forEach(file => {
  const filePath = path.join(slidesDir, file);
  let content = fs.readFileSync(filePath, 'utf8');

  // Replace the old flag CSS with the new one
  content = content.replace(
    /\/\* Italian flag diagonal \*\/[\s\S]*?\.flag-red \{[\s\S]*?\}/,
    flagCSSFix
  );

  // Remove the flag-diagonal wrapper div in HTML
  content = content.replace(
    /<div class="flag-diagonal">\s*<div class="flag-green"><\/div>\s*<div class="flag-white"><\/div>\s*<div class="flag-red"><\/div>\s*<\/div>/,
    '<div class="flag-green"></div>\n  <div class="flag-white"></div>\n  <div class="flag-red"></div>'
  );

  fs.writeFileSync(filePath, content, 'utf8');
  console.log(`✓ Fixed ${file}`);
});

console.log(`\n✅ Fixed ${files.length} slides`);
