<?php
$lines = file('app.js'); 

$replacement = <<<EOT
}

function deleteProduct(id) {
    if (!STATE.currentUser || STATE.currentUser.role !== 'admin') {
        showToast('เฉพาะแอดมินเท่านั้นที่สามารถลบสินค้าได้', 'error');
        return;
    }
    if (confirm('คุณต้องการลบสินค้านี้ออกจากคลังใช่หรือไม่?')) {
        STATE.products = STATE.products.filter(p => p.id !== id);
        localStorage.setItem('goodboyshop_products', JSON.stringify(STATE.products));
        renderProducts();
        const content = document.getElementById('admin-tab-content');
        if (content) _renderAdminProductsTab(content);
        showToast('ลบสินค้าออกจากคลังสำเร็จ', 'info');
    }
}
EOT;

$replacement_lines = explode("\n", $replacement);
foreach ($replacement_lines as &$line) {
    $line .= "\n";
}

// Lines 1302 to 1313 correspond to indices 1301 to 1312
array_splice($lines, 1301, 12, $replacement_lines);
file_put_contents('app.js', implode("", $lines));
echo "Fixed deleteProduct syntax error\n";
