All files / src/app/teacher-page/page/assignments/data-analytics/individual-answers IndividualAnswers.jsx

94.65% Statements 124/131
64.35% Branches 65/101
100% Functions 27/27
96.72% Lines 118/122

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624                                                                                                      1x 33x 32x             1x 162x             1x 162x 162x 196x 162x   162x 162x 162x 162x 162x 162x         162x     162x         162x 162x   162x 35x 35x 34x 34x 34x 33x 94x 31x 35x   1x   34x       35x     162x   68x                     162x 34x         33x 34x       34x     162x 27x 27x 27x 27x 27x 27x   27x   27x 27x 27x   1x 1x   27x           162x 162x     162x 162x   162x 20x 20x 10x 10x 10x   10x       162x 6x 6x 6x 6x     6x 5x 5x   1x 1x   6x       162x 4x 4x 4x           2x 2x 2x 2x   2x   2x 2x   4x       162x 8x 8x 4x 4x 4x   4x                 162x 4x 4x 4x 3x 3x   1x 1x   4x       162x 10x                     162x 5x 5x 5x               4x 4x   1x 1x   5x       162x               3x       257x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
/**
 * Modified by Allan Ninal — 2026-08-12
 *
 * Grade banner now goes through submissionGradeDisplay.js: it withholds on a
 * REJECTED late submission as well as a pending one, and refuses a non-numeric
 * grade so an ungraded submission can no longer render as "NaN%".
 */
 
import React, { useEffect, useMemo, useState } from "react";
import { useLocation, useParams } from "react-router-dom";
import { useSelector } from "react-redux";
import axios from "axios";
import {
    Alert,
    Autocomplete,
    Box,
    Card,
    CardContent,
    Chip,
    Divider,
    Grid,
    LinearProgress,
    Paper,
    Stack,
    TextField,
    Typography,
} from "@mui/material";
import PersonSearchIcon from "@mui/icons-material/PersonSearch";
import HourglassTopIcon from "@mui/icons-material/HourglassTop";
import BlockIcon from "@mui/icons-material/Block";
import GradeIcon from "@mui/icons-material/Grade";
import CommentIcon from "@mui/icons-material/Comment";
import AssignmentIcon from "@mui/icons-material/Assignment";
import TaskAltIcon from "@mui/icons-material/TaskAlt";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import ReplayIcon from "@mui/icons-material/Replay";
import TimerIcon from "@mui/icons-material/Timer";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import { enqueueSnackbar } from "notistack";
import { API_ENDPOINTS } from "@/api/endpoints";
import { TeacherAssignmentAPI } from "@/api/teacher/TeacherAssignmentAPI";
import SimpleLoading from "@/utils/components/SimpleLoading";
import { utcToLocalTime } from "@/utils/helpers/utcToLocalTime";
import SubmissionAnswersList from "@/utils/components/submission-review/SubmissionAnswersList";
import {
    canShowGrade,
    formatGradePercent,
    gradeProgressValue,
    gradeStatusLabel,
} from "@/utils/components/submission-review/submissionGradeDisplay";
 
const lowercaseQuestionTypes = (questions) =>
    questions?.map((entry) =>
        entry.questionType && typeof entry.questionType === "string"
            ? { ...entry, questionType: entry.questionType.toLowerCase() }
            : entry
    );
 
// Same palette rule as the student's own submission-details page — keeps a
// grade read identically whether the student or their teacher is looking at it.
const getRemarksColor = (remarks) => {
    Eif (!remarks) return "default";
    const lower = remarks.toLowerCase();
    if (lower === "passed" || lower === "pass" || lower === "excellent") return "success";
    if (lower === "failed" || lower === "fail") return "error";
    return "warning";
};
 
const IndividualAnswers = () => {
    const location = useLocation();
    const { classCode } = useParams();
    const { specificClassData } = useSelector((state) => state.TeacherSpecificClass);
    const assignmentId = location.state?.assignmentId;
 
    const [roster, setRoster] = useState([]);
    const [rosterLoading, setRosterLoading] = useState(false);
    const [selectedStudent, setSelectedStudent] = useState(null);
    const [submission, setSubmission] = useState(null);
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(null);
    // Per-question teacher comments, keyed by questionId. Loaded from
    // submission.teacherComments on fetch; saves/deletes hit the real
    // student-submission comment endpoint and only update local state once
    // the request confirms, so the UI reflects what's actually persisted.
    const [comments, setComments] = useState({});
    // Per-question in-flight comment action, keyed by questionId: "saving" | "deleting".
    // Drives the loading state shown in CommentBox.
    const [commentActionState, setCommentActionState] = useState({});
    // Per-question in-flight points-edit action, keyed by questionId: "saving".
    // Points edits only ever touch this assignment's own point override
    // (assignments_collection) — the teacher_questionbank question record is
    // never modified.
    const [pointsActionState, setPointsActionState] = useState({});
    const [markActionState, setMarkActionState] = useState({});
 
    useEffect(() => {
        const fetchRoster = async () => {
            if (!specificClassData?._id) return;
            setRosterLoading(true);
            try {
                const response = await axios.get(API_ENDPOINTS.teacher.class.roster.fetch(specificClassData._id));
                const students = (response.data?.class_roster || [])
                    .filter((student) => student.status === "Enrolled")
                    .sort((a, b) => a.last_name.localeCompare(b.last_name));
                setRoster(students);
            } catch (err) {
                console.error("Error:", err.response?.data || err.message);
            } finally {
                setRosterLoading(false);
            }
        };
 
        fetchRoster();
    }, [specificClassData?._id]);
 
    const studentOptions = useMemo(
        () =>
            roster.map((student) => ({
                _id: student._id,
                label: `${student.last_name}, ${student.first_name}`,
            })),
        [roster]
    );
 
    // Shared fetch/parse for a student's submission — used both on student
    // selection and to refresh after a points edit (which can recount
    // total_score/grade/pass-fail on already-graded submissions, so a partial
    // local patch isn't enough to keep the summary card accurate).
    const fetchAndSetSubmission = async (studentId) => {
        const response = await TeacherAssignmentAPI.prototype.fetchStudentSubmission(
            classCode,
            assignmentId,
            studentId
        );
        const data = response.data?.data ?? response.data;
        setSubmission({
            ...data,
            details: lowercaseQuestionTypes(data?.details ?? []),
        });
        setComments(data?.teacherComments || {});
    };
 
    const handleStudentChange = async (_, option) => {
        setSelectedStudent(option);
        setSubmission(null);
        setError(null);
        setComments({});
        setCommentActionState({});
        setPointsActionState({});
 
        Iif (!option || !assignmentId) return;
 
        setLoading(true);
        try {
            await fetchAndSetSubmission(option._id);
        } catch (err) {
            console.error("Error:", err.response?.data || err.message);
            setError("Failed to load this student's submission.");
        } finally {
            setLoading(false);
        }
    };
 
    // studentAnswers comes from last_student_answers stored at submit time —
    // same "did they actually submit" gate the student's own view uses.
    const hasSubmission = submission?.isSubmitted && (submission?.studentAnswers?.length ?? 0) > 0;
    const gradePercentage = gradeProgressValue(submission);
    // Withholds on pending AND rejected, and refuses a non-numeric grade, so an
    // ungraded submission can never render as "NaN%" (EI-1195 / EI-1210).
    const showGrade = canShowGrade(submission);
    const totalPossiblePoints = Number(submission?.totalScore) || 0;
 
    const setCommentBusy = (questionId, action) => {
        setCommentActionState((prev) => {
            if (action === null) {
                const next = { ...prev };
                delete next[questionId];
                return next;
            }
            return { ...prev, [questionId]: action };
        });
    };
 
    const handleCommentSave = async (questionId, text) => {
        const isUpdate = Boolean(comments[questionId]);
        setCommentBusy(questionId, "saving");
        try {
            const save = isUpdate
                ? TeacherAssignmentAPI.prototype.updateStudentAnswerComment
                : TeacherAssignmentAPI.prototype.addStudentAnswerComment;
            await save(classCode, assignmentId, selectedStudent._id, questionId, text);
            setComments((prev) => ({ ...prev, [questionId]: text }));
            enqueueSnackbar(isUpdate ? "Comment updated." : "Comment added.", { variant: "success" });
        } catch (err) {
            console.error("Error:", err.response?.data || err.message);
            enqueueSnackbar("Failed to save comment.", { variant: "error" });
        } finally {
            setCommentBusy(questionId, null);
        }
    };
 
    const handleCommentDelete = async (questionId) => {
        setCommentBusy(questionId, "deleting");
        try {
            await TeacherAssignmentAPI.prototype.deleteStudentAnswerComment(
                classCode,
                assignmentId,
                selectedStudent._id,
                questionId
            );
            setComments((prev) => {
                const next = { ...prev };
                delete next[questionId];
                return next;
            });
            enqueueSnackbar("Comment deleted.", { variant: "success" });
        } catch (err) {
            console.error("Error:", err.response?.data || err.message);
            enqueueSnackbar("Failed to delete comment.", { variant: "error" });
        } finally {
            setCommentBusy(questionId, null);
        }
    };
 
    const setPointsBusy = (questionId, busy) => {
        setPointsActionState((prev) => {
            if (!busy) {
                const next = { ...prev };
                delete next[questionId];
                return next;
            }
            return { ...prev, [questionId]: "saving" };
        });
    };
 
    // Edits assignments_collection.question_points_overrides only — the
    // underlying question in teacher_questionbank is never touched. The
    // backend also recounts total_score/grade/pass-fail for this student's
    // already-graded submission, so re-fetch rather than patch locally —
    // a partial patch can't reproduce that recount client-side.
    const handlePointsSave = async (questionId, points) => {
        setPointsBusy(questionId, true);
        try {
            await TeacherAssignmentAPI.prototype.updateQuestionPoints(assignmentId, questionId, points);
            await fetchAndSetSubmission(selectedStudent._id);
            enqueueSnackbar("Points updated.", { variant: "success" });
        } catch (err) {
            console.error("Error:", err.response?.data || err.message);
            enqueueSnackbar("Failed to update points.", { variant: "error" });
        } finally {
            setPointsBusy(questionId, false);
        }
    };
 
    const setMarkBusy = (questionId, busy) => {
        setMarkActionState((prev) => ({ ...prev, [questionId]: busy ? "saving" : undefined }));
    };
 
    // Marking ONE student's written answer. Unlike handlePointsSave above — which
    // changes what a question is worth for the whole class — this awards what this
    // student earned for what they wrote.
    //
    // Re-fetch rather than patch locally, for the same reason: the backend recomputes
    // the grade over the questions that have actually been marked, and a held question
    // leaves both the score and the total it is divided by. That is not reproducible
    // client-side from the response alone.
    const handleMarkSave = async (questionId, points, feedback) => {
        setMarkBusy(questionId, true);
        try {
            await TeacherAssignmentAPI.prototype.markStudentAnswer(
                classCode,
                assignmentId,
                selectedStudent._id,
                questionId,
                points,
                feedback
            );
            await fetchAndSetSubmission(selectedStudent._id);
            enqueueSnackbar("Answer marked.", { variant: "success" });
        } catch (err) {
            console.error("Error:", err.response?.data || err.message);
            enqueueSnackbar(err.response?.data?.detail || "Failed to mark this answer.", { variant: "error" });
        } finally {
            setMarkBusy(questionId, false);
        }
    };
 
    return (
        <Box>
            <Stack direction="row" spacing={2} alignItems="center" sx={{ mb: 3 }}>
                <Autocomplete
                    id="teacher-analytics-individual-answers-student-select"
                    options={studentOptions}
                    loading={rosterLoading}
                    value={selectedStudent}
                    isOptionEqualToValue={(option, value) => option._id === value._id}
                    onChange={handleStudentChange}
                    sx={{ width: 320 }}
                    renderInput={(params) => (
                        <TextField {...params} label="Select a student" placeholder="Search by name" size="small" />
                    )}
                />
            </Stack>
 
            {!assignmentId && (
                <Alert severity="warning">
                    We couldn't determine which assignment to load. Please navigate here from the assignments list.
                </Alert>
            )}
 
            {assignmentId && !selectedStudent && (
                <Box sx={{ textAlign: "center", py: 8 }}>
                    <PersonSearchIcon sx={{ fontSize: 48, color: "text.disabled", mb: 1 }} />
                    <Typography variant="body1" color="text.secondary">
                        Select a student above to view their individual answers.
                    </Typography>
                </Box>
            )}
 
            <SimpleLoading showLoading={loading} />
 
            {error && (
                <Alert severity="error" sx={{ mb: 3 }}>
                    {error}
                </Alert>
            )}
 
            {!loading && selectedStudent && submission && (
                <Box sx={{ maxWidth: 1400, mx: "auto" }}>
                    {/* Assignment context — same fields shown on the student's own submission-details
                        page (SubmissionDetails.jsx): title, description, open/close dates. */}
                    {submission.assignmentDetails && (
                        <Paper
                            elevation={0}
                            sx={{ p: 3, mb: 3, borderRadius: 2, border: "1px solid", borderColor: "divider" }}
                        >
                            <Box sx={{ display: "flex", alignItems: "flex-start", gap: 2, mb: 2 }}>
                                <AssignmentIcon color="primary" sx={{ fontSize: 32, mt: 0.5 }} />
                                <Box sx={{ flex: 1 }}>
                                    <Typography variant="h5" fontWeight={600} gutterBottom>
                                        {submission.assignmentDetails.title}
                                    </Typography>
                                    <Typography variant="body1" color="text.secondary">
                                        {submission.assignmentDetails.description}
                                    </Typography>
                                </Box>
                            </Box>
                            <Divider sx={{ my: 2 }} />
                            <Box sx={{ display: "flex", gap: 3, flexWrap: "wrap" }}>
                                <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
                                    <CalendarTodayIcon fontSize="small" color="action" />
                                    <Typography variant="body2" color="text.secondary">
                                        Opened:{" "}
                                        <strong>{utcToLocalTime(submission.assignmentDetails.date_open)}</strong>
                                    </Typography>
                                </Box>
                                <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
                                    <CalendarTodayIcon fontSize="small" color="action" />
                                    <Typography variant="body2" color="text.secondary">
                                        Closed:{" "}
                                        <strong>{utcToLocalTime(submission.assignmentDetails.date_close)}</strong>
                                    </Typography>
                                </Box>
                            </Box>
                        </Paper>
                    )}
 
                    {/* Late-submission review-status banners — same wording/iconography as the
                        student's own submission-details page (SubmissionDetails.jsx). */}
                    {submission.reviewStatus === "pending" && (
                        <Alert severity="warning" icon={<HourglassTopIcon />} sx={{ mb: 3 }}>
                            <Typography fontWeight={600}>Awaiting Your Approval</Typography>
                            <Typography variant="body2" sx={{ mt: 0.5 }}>
                                This late submission is pending review. The grade is hidden from the student until you
                                approve or reject it.
                            </Typography>
                        </Alert>
                    )}
 
                    {submission.reviewStatus === "rejected" && (
                        <Alert severity="error" icon={<BlockIcon />} sx={{ mb: 3 }}>
                            <Typography fontWeight={600}>Late Submission Rejected</Typography>
                            <Typography variant="body2" sx={{ mt: 0.5 }}>
                                You did not accept this late submission.
                            </Typography>
                        </Alert>
                    )}
 
                    {hasSubmission ? (
                        <>
                            <Typography
                                variant="h6"
                                fontWeight={600}
                                sx={{ mb: 2, display: "flex", alignItems: "center", gap: 1 }}
                            >
                                <GradeIcon color="primary" />
                                Submission Summary
                            </Typography>
 
                            {/* Grade and remarks banner — only when graded and not pending review. */}
                            {(showGrade || submission.remarks) && (
                                <Paper elevation={0} sx={{ p: 2.5, mb: 3, borderRadius: 2 }}>
                                    <Box
                                        sx={{
                                            display: "flex",
                                            alignItems: "center",
                                            justifyContent: "space-between",
                                            flexWrap: "wrap",
                                            gap: 2,
                                        }}
                                    >
                                        <Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
                                            <GradeIcon
                                                sx={{
                                                    fontSize: 40,
                                                    color: `${getRemarksColor(submission.remarks)}.dark`,
                                                }}
                                            />
                                            <Box>
                                                <Typography variant="body2" color="text.secondary">
                                                    Grade
                                                </Typography>
                                                <Typography
                                                    variant="h3"
                                                    fontWeight={700}
                                                    color={`${getRemarksColor(submission.remarks)}.dark`}
                                                >
                                                    {showGrade
                                                        ? `${formatGradePercent(submission)}%`
                                                        : gradeStatusLabel(submission.gradeStatus)}
                                                </Typography>
                                            </Box>
                                        </Box>
                                        {submission.remarks && (
                                            <Chip
                                                icon={<CommentIcon />}
                                                label={
                                                    submission.remarks.charAt(0).toUpperCase() +
                                                    submission.remarks.slice(1)
                                                }
                                                color={getRemarksColor(submission.remarks)}
                                                size="medium"
                                                sx={{ fontWeight: 600, fontSize: "0.9rem", py: 2.5 }}
                                            />
                                        )}
                                    </Box>
                                    {showGrade && (
                                        <Box sx={{ mt: 2 }}>
                                            <LinearProgress
                                                variant="determinate"
                                                value={gradePercentage}
                                                color={getRemarksColor(submission.remarks)}
                                                sx={{ height: 8, borderRadius: 4 }}
                                            />
                                        </Box>
                                    )}
                                </Paper>
                            )}
 
                            <Grid container spacing={2} sx={{ mb: 4 }}>
                                {submission.studentScore !== undefined && (
                                    <Grid size={{ xs: 6, sm: 4, md: 2 }}>
                                        <Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
                                            <CardContent sx={{ textAlign: "center" }}>
                                                <TaskAltIcon color="primary" sx={{ fontSize: 28, mb: 1 }} />
                                                <Typography
                                                    variant="overline"
                                                    color="text.secondary"
                                                    sx={{ display: "block" }}
                                                >
                                                    Score
                                                </Typography>
                                                <Typography variant="h5" fontWeight={700}>
                                                    {submission.studentScore}
                                                    {totalPossiblePoints > 0 && (
                                                        <Typography
                                                            component="span"
                                                            variant="body2"
                                                            color="text.secondary"
                                                        >
                                                            {" "}
                                                            / {totalPossiblePoints}
                                                        </Typography>
                                                    )}
                                                </Typography>
                                            </CardContent>
                                        </Card>
                                    </Grid>
                                )}
                                {submission.totalCorrectAnswers !== undefined && (
                                    <Grid size={{ xs: 6, sm: 4, md: 2 }}>
                                        <Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
                                            <CardContent sx={{ textAlign: "center" }}>
                                                <CheckCircleIcon color="success" sx={{ fontSize: 28, mb: 1 }} />
                                                <Typography
                                                    variant="overline"
                                                    color="text.secondary"
                                                    sx={{ display: "block" }}
                                                >
                                                    Correct
                                                </Typography>
                                                <Typography variant="h5" fontWeight={700}>
                                                    {submission.totalCorrectAnswers}
                                                    {submission.totalQuestions !== undefined && (
                                                        <Typography
                                                            component="span"
                                                            variant="body2"
                                                            color="text.secondary"
                                                        >
                                                            {" "}
                                                            / {submission.totalQuestions}
                                                        </Typography>
                                                    )}
                                                </Typography>
                                            </CardContent>
                                        </Card>
                                    </Grid>
                                )}
                                <Grid size={{ xs: 6, sm: 4, md: 2 }}>
                                    <Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
                                        <CardContent sx={{ textAlign: "center" }}>
                                            <AssignmentIcon color="secondary" sx={{ fontSize: 28, mb: 1 }} />
                                            <Typography
                                                variant="overline"
                                                color="text.secondary"
                                                sx={{ display: "block" }}
                                            >
                                                Submitted
                                            </Typography>
                                            <Typography variant="h5" fontWeight={700}>
                                                {submission.totalAnswersSubmitted}
                                                {submission.totalQuestions !== undefined && (
                                                    <Typography component="span" variant="body2" color="text.secondary">
                                                        {" "}
                                                        / {submission.totalQuestions}
                                                    </Typography>
                                                )}
                                            </Typography>
                                        </CardContent>
                                    </Card>
                                </Grid>
                                <Grid size={{ xs: 6, sm: 4, md: 2 }}>
                                    <Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
                                        <CardContent sx={{ textAlign: "center" }}>
                                            <ReplayIcon color="warning" sx={{ fontSize: 28, mb: 1 }} />
                                            <Typography
                                                variant="overline"
                                                color="text.secondary"
                                                sx={{ display: "block" }}
                                            >
                                                Attempts
                                            </Typography>
                                            <Typography variant="h5" fontWeight={700}>
                                                {submission.totalAttemptsUsed}
                                                {submission.totalAttemptsAllowed !== undefined && (
                                                    <Typography component="span" variant="body2" color="text.secondary">
                                                        {" "}
                                                        / {submission.totalAttemptsAllowed}
                                                    </Typography>
                                                )}
                                            </Typography>
                                        </CardContent>
                                    </Card>
                                </Grid>
                                {submission.remainingTime && (
                                    <Grid size={{ xs: 6, sm: 4, md: 2 }}>
                                        <Card variant="outlined" sx={{ height: "100%", borderRadius: 2 }}>
                                            <CardContent sx={{ textAlign: "center" }}>
                                                <TimerIcon color="action" sx={{ fontSize: 28, mb: 1 }} />
                                                <Typography
                                                    variant="overline"
                                                    color="text.secondary"
                                                    sx={{ display: "block" }}
                                                >
                                                    Time Left
                                                </Typography>
                                                <Typography variant="h6" fontWeight={700}>
                                                    {submission.remainingTime}
                                                </Typography>
                                            </CardContent>
                                        </Card>
                                    </Grid>
                                )}
                            </Grid>
 
                            <Box sx={{ mb: 3 }}>
                                <Typography
                                    variant="h6"
                                    fontWeight={600}
                                    sx={{ mb: 2, display: "flex", alignItems: "center", gap: 1 }}
                                >
                                    <AssignmentIcon color="primary" />
                                    Student's Answers
                                </Typography>
                            </Box>
                            <SubmissionAnswersList
                                questions={submission.details}
                                answers={submission.studentAnswers}
                                comments={comments}
                                commentActionState={commentActionState}
                                onCommentSave={handleCommentSave}
                                onCommentDelete={handleCommentDelete}
                                editablePoints
                                pointsActionState={pointsActionState}
                                onPointsSave={handlePointsSave}
                                canMark
                                markActionState={markActionState}
                                onMarkSave={handleMarkSave}
                            />
                        </>
                    ) : (
                        <Alert severity="info">
                            {selectedStudent.label.split(", ").reverse().join(" ")} has not submitted answers for this
                            assignment.
                        </Alert>
                    )}
                </Box>
            )}
        </Box>
    );
};
 
export default IndividualAnswers;