import { PartyClient, joinText, qrSvg } from "/_tvpipe/lib/client.js";
const $ = (id) => document.getElementById(id);
const client = PartyClient.fromLocation();
client.on("view", (view) => {
const s = view.screen ?? {};
$("qr").innerHTML = qrSvg(view.join?.qr);
$("code").textContent = joinText(view.join) ?? "";
$("status").textContent = !s.round ? "Scan to join, then the host starts a round" : `Round ${s.round}: buzz!`;
$("buzzed").replaceChildren(...(s.buzzed ?? []).map((name) => item(name)));
$("scores").replaceChildren(...(s.scores ?? []).map((p) => item(`${p.name}: ${p.points}`)));
});
client.on("status", (st) => {
if (st !== "open") $("status").textContent = st;
});
function item(text) {
const li = document.createElement("li");
li.textContent = text; return li;
}
await client.connect();