const fs = require('fs');

function patchRender(filename, funcName) {
    let content = fs.readFileSync(filename, 'utf8');
    // We want to replace the specific view fetching logic with the user's generic active view logic
    // Usually it looks like: const activeView = document.getElementById('view-client-abstracts');
    
    // Using a regex to find the activeView logic
    const regex = /const activeView = document\.getElementById\('[^']+'\);/;
    const replacement = "const activeView = document.querySelector('.view.active, [id^=\"view-\"].active');";
    
    if (content.match(regex)) {
        content = content.replace(regex, replacement);
        fs.writeFileSync(filename, content, 'utf8');
        console.log(`Patched activeView in ${filename}`);
    } else {
        console.log(`Could not find activeView line in ${filename}`);
    }
}

patchRender('contractors_module.js', 'renderClientAbstracts');
patchRender('subcontracts.js', 'renderAbstracts');

