const fs = require('fs');
const file = 'c:/Users/kde/Desktop/wassili_V2/public_html/admin-debt-history.html';
let content = fs.readFileSync(file, 'utf8');

const replacements = [
    {
        find: "const captainName  = e.captain?.name  || 'محذوف';",
        replace: "const captainName  = window.escapeHtml ? window.escapeHtml(e.captain?.name || 'محذوف') : e.captain?.name || 'محذوف';"
    },
    {
        find: "const adminName    = e.admin?.name    || '—';",
        replace: "const adminName    = window.escapeHtml ? window.escapeHtml(e.admin?.name || '—') : e.admin?.name || '—';"
    },
    {
        find: "title=\"${e.note || ''}\">${e.note || '—'}",
        replace: "title=\"${window.escapeHtml ? window.escapeHtml(e.note || '') : e.note || ''}\">${window.escapeHtml ? window.escapeHtml(e.note || '—') : e.note || '—'}"
    }
];

let replacedCount = 0;
for (const r of replacements) {
    if (content.includes(r.find)) {
        content = content.replace(r.find, r.replace);
        replacedCount++;
    } else {
        console.log("NOT FOUND:", r.find);
    }
}

fs.writeFileSync(file, content);
console.log(`Fixed admin-debt-history.html successfully. (${replacedCount} replacements)`);
