// ── Telegram Web App init ───────────────────────────────────────
const tg = window.Telegram.WebApp;
tg.ready();
tg.expand();
const API = window.location.origin + "/api";
const userId = tg.initDataUnsafe?.user?.id;
if (!userId) {
document.getElementById("app").innerHTML =
'
Superset
';
} else {
groupsHtml += '
';
}
group.forEach((ex) => {
const machine = ex.machine_id ? `
(${ex.machine_id})` : "";
groupsHtml += `
${ex.name}${machine}
— ${ex.sets}x${ex.reps}x${ex.weight_kg}kg
`;
});
groupsHtml += "
";
});
card.innerHTML = `
${groupsHtml}
`;
container.appendChild(card);
});
historyOffset += data.workouts.length;
loadMore.style.display = historyOffset < data.total ? "block" : "none";
} catch (e) {
console.error("Failed to load history", e);
}
}
document.getElementById("btn-load-more").addEventListener("click", () => {
loadHistory(true);
});
// ── Stats View ──────────────────────────────────────────────────
async function loadStats() {
try {
const data = await api("GET", "/stats");
const container = document.getElementById("stats-content");
if (data.total_workouts === 0) {
container.innerHTML = '
';
return;
}
container.innerHTML = `
${data.total_workouts}
Workouts
${data.unique_exercises}
Exercises
${data.total_sets.toLocaleString()}
Total Sets
${Math.round(data.total_volume).toLocaleString()}
Volume (kg)
`;
} catch (e) {
console.error("Failed to load stats", e);
}
}
// ── Init ────────────────────────────────────────────────────────
async function init() {
if (!userId) return;
await loadSuggestions();
}
init();