const fs = require('fs');

const files = ['app_final.js'];

files.forEach(file => {
    if (fs.existsSync(file)) {
        let js = fs.readFileSync(file, 'utf8');
        
        js = js.replace(/const canApprove = currentUser\.permissions && currentUser\.permissions\.includes\('approve_settlements'\);/g,
            "const canApprove = currentUser.role === 'مدير عام' || (currentUser.permissions && currentUser.permissions.includes('approve_settlements'));");
            
        fs.writeFileSync(file, js, 'utf8');
        console.log(`Patched canApprove in ${file}`);
    }
});

// Cache buster
if (fs.existsSync('index.html')) {
    let html = fs.readFileSync('index.html', 'utf8');
    html = html.replace(/v=\d+/g, 'v=' + Date.now());
    fs.writeFileSync('index.html', html, 'utf8');
}
