const PREVIEW_STORAGE_PREFIX = "teacher-task-review-preview:"; function currentLocation() { return typeof window === "undefined" ? null : window.location; } function previewKeyFromLocation() { const location = currentLocation(); if (!location) return ""; const directKey = new URLSearchParams(location.search).get("reviewPreviewKey"); if (directKey) return directKey; const hashQueryIndex = location.hash.indexOf("?"); if (hashQueryIndex < 0) return ""; return new URLSearchParams(location.hash.slice(hashQueryIndex + 1)).get("reviewPreviewKey") || ""; } export function getTrainingReviewPreviewKey() { return previewKeyFromLocation(); } export function writeTrainingReviewPreview(previewKey, value) { if (!previewKey || typeof sessionStorage === "undefined") return; sessionStorage.setItem(`${PREVIEW_STORAGE_PREFIX}${previewKey}`, JSON.stringify(value)); } export function readTrainingReviewPreview(previewKey) { if (!previewKey || typeof sessionStorage === "undefined") return null; try { return JSON.parse(sessionStorage.getItem(`${PREVIEW_STORAGE_PREFIX}${previewKey}`) || "null"); } catch (_) { return null; } } export function clearTrainingReviewPreview(previewKey) { if (previewKey && typeof sessionStorage !== "undefined") { sessionStorage.removeItem(`${PREVIEW_STORAGE_PREFIX}${previewKey}`); } } export function getTrainingReviewPreviewContext() { return readTrainingReviewPreview(getTrainingReviewPreviewKey()); } export function isTrainingReviewPreviewRequest(config = {}) { const method = String(config.method || "get").toLowerCase(); const url = String(config.url || "").split("?")[0]; return Boolean(getTrainingReviewPreviewKey()) && ["post", "put", "patch", "delete"].includes(method) && (url.startsWith("/api/student-training-answers/") || url.startsWith("/api/student/project-study-time/") || url === "/common/upload"); }