const fs = require('fs');
let js = fs.readFileSync('app_final.js', 'utf8');

js = js.replace("tr.querySelector('.sa-item-total-val').innerText = tVal.toLocaleString('ar-EG');", `tr.querySelector('.sa-item-total-val').innerText = tVal.toLocaleString('ar-EG');
        if (totalQty > 0 && tQty > totalQty) {
            tr.style.backgroundColor = 'rgba(255, 0, 0, 0.2)';
            let titleElement = tr.querySelector('td:nth-child(2)');
            if(titleElement && !titleElement.innerHTML.includes('تجاوز')) {
                titleElement.innerHTML += '<span style="color: #ff6b6b; font-size: 0.8em; margin-right: 5px; font-weight: bold;">(تجاوز!)</span>';
            }
        } else {
            tr.style.backgroundColor = '';
            let titleElement = tr.querySelector('td:nth-child(2)');
            if(titleElement && titleElement.innerHTML.includes('تجاوز')) {
                titleElement.innerHTML = titleElement.innerHTML.replace(/<span.*>\\(تجاوز!\\)<\\/span>/, '');
            }
        }
`);

fs.writeFileSync('app_final.js', js, 'utf8');
console.log('Added sa-item warning');
