const fs = require('fs');

let spJs = fs.readFileSync('d:/برنامج مخازن/sales_purchases_module.js', 'utf8');

// Replace the condition to be more permissive
spJs = spJs.replace(
    /if\(currentUser && currentUser\.role === 'مدير عام'\) \{/g,
    `if(currentUser && (currentUser.role === 'مدير عام' || currentUser.role.includes('مدير') || currentUser.username === 'admin')) {`
);

fs.writeFileSync('d:/برنامج مخازن/sales_purchases_module.js', spJs, 'utf8');

// Bust cache
let html = fs.readFileSync('d:/برنامج مخازن/index.html', 'utf8');
const version = Date.now().toString();
html = html.replace(/v=\d+/g, 'v=' + version);
fs.writeFileSync('d:/برنامج مخازن/index.html', html, 'utf8');

console.log('Delete button condition updated.');
