// Admin: status, Boost delivery, member lookup, ad status, the old-link map. The token stays in this tab only (sessionStorage).
(function () {
VAB.renderNav(''); VAB.renderFooter();
const $ = VAB.$, esc = VAB.esc;
let tok = ''; try { tok = sessionStorage.getItem('vab.admin') || ''; } catch (e) {}
const H = () => ({ 'x-admin-token': tok, 'Content-Type': 'application/json' });
const show = (el, o) => { el.textContent = JSON.stringify(o, null, 2); };
async function load() {
if (!tok) return;
const s = await VAB.getJSON('/api/admin/status', { headers: H() }); show($('statusOut'), s);
const b = await VAB.getJSON('/api/admin/boosts', { headers: H() });
$('boostRows').querySelector('tbody').innerHTML = (b.boosts || []).map(x => '
| ' + VAB.when(x.at) + ' | ad #' + esc(x.adId) + ' | ' + VAB.n(x.delivered) + ' / ' + VAB.n(x.views) + ' | ' + esc(x.status) + ' | ' + esc(VAB.short(x.buyer)) + ' |
').join('') || '| none |
';
}
$('tokForm').addEventListener('submit', e => { e.preventDefault(); tok = $('tok').value.trim(); try { sessionStorage.setItem('vab.admin', tok); } catch (x) {} load(); });
$('lookForm').addEventListener('submit', async e => { e.preventDefault(); show($('lookOut'), await VAB.getJSON('/api/admin/member-lookup?q=' + encodeURIComponent($('look').value.trim()), { headers: H() })); });
$('adForm').addEventListener('submit', async e => { e.preventDefault(); const r = await VAB.getJSON('/api/admin/ad', { method: 'POST', headers: H(), body: JSON.stringify({ id: Number($('adId').value), status: $('adStatus').value.trim(), note: $('adNoteIn').value }) }); VAB.status(r.error || 'Saved.', r.error ? 'err' : 'ok'); });
$('oldFile').addEventListener('change', async e => { const f = e.target.files[0]; if (!f) return; const r = await fetch('/api/admin/oldrefs', { method: 'POST', headers: H(), body: await f.text() }); show($('oldOut'), await r.json()); });
load();
})();