// The student's grades: each lesson's best quiz grade, and each real test's exercise tests and simulation (best grade, tries, last date).
// Assignments will add their rows later.
import { swr } from "./api.js";
import { esc, fmt } from "./math.js";
import { forSubject, shortDate, tabs } from "./ui.js";
const day = iso => iso ? new Date(iso).toLocaleDateString("he-IL", { day: "numeric", month: "numeric" }) : "";
const tries = n => `${n} ${n === 1 ? "ניסיון" : "ניסיונות"}`;
function row({ attrs, href, title, best, attempts, last }) {
return `
${title}
${best}
${tries(attempts)}${last ? ` · האחרון ב־${day(last)}` : ""}`;
}
const testTitle = (t, suffix) => `מבחן ב־${shortDate(t.date)}: ${suffix}${t.removed ? " (הוסר)" : ""}`;
export const show = view => swr(forSubject("/api/grades"), data => draw(view, data));
function draw(view, { quizzes, exercise_tests: exercises = [], simulations = [], assignments = [] }) {
const none = !quizzes.length && !exercises.length && !simulations.length && !assignments.length;
view(`${tabs("grades")}הציונים שלי
${none ? `עוד אין ציונים. הבוחן של כל שיעור מחכה בסוף השיעור במסלול.
` : ""}
${quizzes.length ? `בחנים
${quizzes.map(g => row({ attrs: `data-lesson="${esc(g.lesson.id)}"`, href: `#/quiz/${esc(g.lesson.id)}`,
title: fmt(g.lesson.name), best: g.best, attempts: g.attempts, last: g.last })).join("")}
` : ""}
${exercises.length ? `מבחני תרגול
${exercises.map(g => row({ attrs: `data-test="${g.test.id}" data-number="${g.number}"`,
href: `#/test/${g.test.id}`, title: testTitle(g.test, g.title || `מבחן תרגול ${g.number}`), best: g.best, attempts: g.attempts, last: g.last })).join("")}
` : ""}
${assignments.length ? `משימות
` : ""}
${simulations.length ? `מבחני סימולציה
${simulations.map(g => row({ attrs: `data-test="${g.test.id}"`,
href: `#/test/${g.test.id}`, title: testTitle(g.test, "מבחן סימולציה"), best: g.best, attempts: g.attempts, last: g.last })).join("")}
` : ""}`);
}