const fs = require('fs');
let content = fs.readFileSync('subcontracts.js', 'utf8');

// replace .value with ?.value where safe
content = content.replace(/row\.querySelector\('([^']+)'\)\.value/g, "row.querySelector('$1')?.value");

// also check getElementById
content = content.replace(/document\.getElementById\('([^']+)'\)\.value/g, "(document.getElementById('$1')?.value || '')");

// Same for .innerText
content = content.replace(/row\.querySelector\('([^']+)'\)\.innerText/g, "row.querySelector('$1')?.innerText");

fs.writeFileSync('subcontracts.js', content, 'utf8');
console.log('Patched subcontracts.js');
