// panes/api.js — interactive request explorer.
import { registerPane } from '../app.js';
import { jraw } from '../lib/api.js';
import { fmtJSON } from '../lib/ui.js';
const TPL = `
API Explorer
Hit any backend route.
`;
registerPane('api', {
label: 'API Explorer',
init(host) {
host.innerHTML = TPL;
host.querySelector('#ax-send').addEventListener('click', async () => {
const m = host.querySelector('#ax-method').value;
const p = host.querySelector('#ax-path').value;
const b = host.querySelector('#ax-body').value.trim();
const t0 = performance.now();
try {
const r = await jraw(m, p, m === 'GET' ? '' : b);
const dt = Math.round(performance.now() - t0);
host.querySelector('#ax-status').textContent = `${r.status} · ${dt}ms · ${r.raw.length}b`;
host.querySelector('#ax-out').textContent = typeof r.body === 'string' ? r.body : fmtJSON(r.body);
} catch (e) {
host.querySelector('#ax-status').textContent = 'error';
host.querySelector('#ax-out').textContent = e.message;
}
});
host.querySelector('#ax-clear').addEventListener('click', () => {
host.querySelector('#ax-out').textContent = '';
host.querySelector('#ax-status').textContent = '—';
});
},
});