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

const dir = path.join(__dirname, 'app/src/components/three');
const pagesDir = path.join(__dirname, 'app/src/pages');

// For components that return <SceneCanvas> inside them
const componentsToUpdate = [
  { file: 'app/src/components/three/Sign3D.tsx', id: 'muro_placa' },
  { file: 'app/src/components/three/IsolatedRoof3D.tsx', id: 'cobertura_isolada' },
  { file: 'app/src/components/three/Bridge3D.tsx', id: 'ponte' },
  { file: 'app/src/components/three/Vault3D.tsx', id: 'abobada' },
  { file: 'app/src/components/three/Dome3D.tsx', id: 'cupula' },
  { file: 'app/src/components/three/Cylinder3D.tsx', id: 'cilindro' },
  { file: 'app/src/components/three/Tower3D.tsx', id: 'torre' },
  { file: 'app/src/components/Warehouse3D.tsx', id: 'galpao' },
  { file: 'app/src/components/three/BarSelector3D.tsx', id: 'barras' }
];

for (const comp of componentsToUpdate) {
  const filePath = path.join(__dirname, comp.file);
  if (!fs.existsSync(filePath)) continue;
  
  let content = fs.readFileSync(filePath, 'utf8');
  content = content.replace(/<SceneCanvas/g, `<SceneCanvas moduleId="${comp.id}"`);
  fs.writeFileSync(filePath, content);
  console.log(`Updated ${comp.file} with moduleId="${comp.id}"`);
}
