document.getElementById('db-check-btn').onclick = async function() {
    const btn = this;
    btn.disabled = true;
    const reportDiv = document.getElementById('db-check-report');
    reportDiv.innerHTML = '<em>Выполняется проверка...</em>';
    let resp, data;
    try {
        resp = await fetch('/api/admin/db_check', {method:'POST'});
        data = await resp.json();
    } catch (err) {
        reportDiv.innerHTML = 'Ошибка запроса: ' + err;
        btn.disabled = false;
        return;
    }
    btn.disabled = false;
    if (data.success && data.report) {
        let html = '<table class="table"><thead><tr><th>Таблица</th><th>Статус</th><th>Сообщение</th></tr></thead><tbody>';
        for (const row of data.report) {
            html += `<tr><td>${row.table}</td><td>${row.ok ? '✔️' : '❌'}</td><td>${row.msg}</td></tr>`;
        }
        html += '</tbody></table>';
        reportDiv.innerHTML = html;
    } else {
        reportDiv.innerHTML = '<div class="alert alert-danger">' + (data.message || 'Ошибка проверки') + '</div>';
    }
}
