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

const replacements = [
    {
        find: "    try {\n        const res = await fetch(`${API_URL}/api/admin/settings`, {",
        replace: "    const resultConfirm = await Swal.fire({\n        title: 'هل أنت متأكد؟',\n        text: 'تغيير هذه الإعدادات سيؤثر على تسعير الطلبات الجديدة فوراً!',\n        icon: 'warning',\n        showCancelButton: true,\n        confirmButtonColor: '#e74c3c',\n        cancelButtonColor: '#6c757d',\n        confirmButtonText: 'نعم، قم بالحفظ',\n        cancelButtonText: 'إلغاء'\n    });\n\n    if (!resultConfirm.isConfirmed) return;\n\n    try {\n        const res = await fetch(`${API_URL}/api/admin/settings`, {"
    }
];

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.substring(0, 50));
    }
}

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