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

// 1. Fix literal \n
js = js.replace(/\\nwindow\.renderClientAbstracts/g, '\nwindow.renderClientAbstracts');
js = js.replace(/\\nwindow\.openClientAbstractModal/g, '\nwindow.openClientAbstractModal');

// 2. Fix escaped backticks
js = js.replace(/let actions = \\`/g, 'let actions = `');
js = js.replace(/\\` : ''}/g, '` : \'\'}');

// There might be another one around tr.innerHTML = \`
js = js.replace(/tr\.innerHTML = \\`/g, 'tr.innerHTML = `');
js = js.replace(/\\`;\s*tbody\.appendChild\(tr\);/g, '`;\n    tbody.appendChild(tr);');

fs.writeFileSync('app_final.js', js, 'utf8');
console.log('Fixed syntax errors in app_final.js!');
