/* Classifiche — logica pagina */ "use strict"; const $ = (id) => document.getElementById(id); const S = { type: "total", status: "all", q: "", from: 0, to: 0 }; const STATUS_LABEL = { "": "Attivo", i: "Inattivo", I: "Inattivo lungo", v: "In vacanza", vi: "Vacanza + inatt.", vI: "Vacanza + inatt.", a: "Admin" }; const stClass = (s) => "st-" + (s || ""); async function initHead() { try { const b = await api("/api/bootstrap"); $("rk-universe").textContent = `${b.server.name} — Classifiche`; $("rk-sub").textContent = `[s${b.server.number}-${b.server.community}] · aggiornamento: ${b.fetched.highscore_total ? b.fetched.highscore_total : "—"} UTC`; } catch (e) { /* header non bloccante */ } } function fmtScore(v) { if (v === null || v === undefined) return "—"; return Number(v).toLocaleString("it-IT"); } function posClass(rank) { if (!rank) return "pos na"; return "pos p" + rank; } async function load() { const msg = $("f-msg"); msg.textContent = "Caricamento…"; const p = new URLSearchParams({ type: S.type, status: S.status, q: S.q }); if (S.from > 0) p.set("start", S.from); if (S.to > 0) p.set("end", S.to); try { const d = await api("/api/rankings?" + p.toString()); render(d); msg.textContent = ""; } catch (e) { msg.textContent = e.message; } } function render(d) { const isFleet = d.type === "fleet"; const kindLabel = { total: "classifica generale", military: "classifica armamenti", fleet: "top flotte — navi dai rapporti", }[d.type] || d.type; $("rk-count").innerHTML = `Giocatori: ${d.count} — ` + `${kindLabel}`; const rows = d.rows.map((r) => { const st = r.status || ""; const stLab = STATUS_LABEL[st] || st; const jump = r.avatar ? `onclick="goGalaxy('${r.avatar}')"` : ""; const mine = r.mine ? ' ●' : ""; const empty = r.avatar ? `${artSVG(r.avatar, 26)}` : `${artSVG(r.name + r.id, 26)}`; const rep = r.reports || 0; const repCoords = r.report_coords || r.avatar; const repCell = rep ? `` + `${icon("badge_spy", 12)} ${rep}` : `—`; return `