// One assignment: its material (pages or the bank's written quiz), the student's answer as pictures (from the board, the camera, a file or
// the phone) and handing it in; afterwards its state, and the grade and note or the request to correct.
import { api } from "./api.js";
import { stateWord } from "./ai_sheet.js";
import { loadBoard } from "./exercise.js";
import { figures } from "./figures.js";
import { assignmentState } from "./home.js";
import { withBusy } from "./busy.js";
import { esc, fmt } from "./math.js";
import { isTouch, pictureUrl, prepare, sendPicture } from "./media.js";
import * as phone from "./phone.js";
import { shortDate, tabs } from "./ui.js";
let draw = null, current = null, draft = [], message = "";
const draftKey = id => `assignment-draft:${id}`;
const saveDraft = () => { try { sessionStorage.setItem(draftKey(current.id), JSON.stringify(draft)); } catch { /* private window */ } };
const loadDraft = id => { try { return JSON.parse(sessionStorage.getItem(draftKey(id)) || "null"); } catch { return null; } };
const q = selector => document.querySelector(selector);
const editable = a => ["not_handed", "handed_in", "returned"].includes(a.state);
/** Fill an with a private picture (fetched with the sign-in). */
async function fill(img, id) {
try { img.src = await pictureUrl(id); img.hidden = false; } catch (error) { img.replaceWith(Object.assign(document.createElement("span"), { className: "muted", textContent: error.message })); }
}
function material(a) {
if (a.kind === "exercise_test") return `
${fmt(x.question)}
${figures(x)}${x.points} נק׳הערת המורה: ${fmt(a.teacher_note)}
` : ""; const head = `${s.word}
`; if (a.state === "returned") return `${head}תקנו והגישו שוב.
הציון: ${a.grade}
${note}`; return head; } /** What the student can do about a handed-in answer: ask for an AI check (it waits for the teacher), see its result as a suggestion, or ask * the teacher to look again. */ function aiBox(a) { const ai = a.ai; if (!ai || (!ai.can_check && !ai.can_look_again && !ai.asked_again && !ai.checks.length)) return ""; const checks = ai.checks.map(c => { const r = c.result; const body = c.state === "done" ? (r.score === null || r.score === undefined ? `ה־AI לא הצליח לקרוא את התשובה. המורה יבדוק/תבדוק.
` : `הציון המוצע: ${r.score} (המורה קובע/ת את הציון)
`) + `${fmt(r.feedback || "")}
${r.next_step ? `${fmt(r.next_step)}
` : ""}` : c.state === "declined" ? `${c.teacher_note ? fmt(c.teacher_note) : "המורה לא שלח/ה את הבקשה."}
` : c.state === "failed" ? `${esc(c.failure?.message || "לא הצלחנו כרגע. נסו שוב מאוחר יותר.")}
` : ""; return `${esc(stateWord(c.state))}
${body}המורה יראה/תראה את הבקשה קודם.
` : ""} ${ai.can_look_again ? `` : ""} ${ai.asked_again ? `ביקשתם מהמורה לבדוק שוב.
` : ""}${checks}התמונות נמחקו
` : `${isTouch() ? `` : ""} ${!isTouch() ? `` : ""}
${esc(message)}
${esc(current.class.name)} · עד ${shortDate(current.due_date)}${current.overdue ? " · באיחור" : ""}
${current.note ? `${fmt(current.note)}
` : ""}${stateBox(current)}