const fs = require('fs');

if (fs.existsSync('app_final.js')) {
    let js = fs.readFileSync('app_final.js', 'utf8');
    
    // Add account statement button
    const searchString = "actions = `<button class=\"action-btn btn-edit\" onclick=\"openAccountModal(${acc.id})\">✏️ تعديل</button>";
    const replaceString = "actions = `<button class=\"action-btn\" style=\"background:#17a2b8; color:#fff;\" onclick=\"openAccountStatement(${acc.id})\">📄 كشف حساب</button>\n                   <button class=\"action-btn btn-edit\" onclick=\"openAccountModal(${acc.id})\">✏️ تعديل</button>";
    
    if (js.includes(searchString) && !js.includes('📄 كشف حساب')) {
        js = js.replace(searchString, replaceString);
        fs.writeFileSync('app_final.js', js, 'utf8');
        console.log('Added account statement button to app_final.js');
    }
}

// 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');
}
