All files / src/app/teacher-page/page/assignments/new-assignment/student-preview/components AnswerTracker.jsx

59.81% Statements 128/214
59.58% Branches 143/240
61.11% Functions 33/54
63.06% Lines 111/176

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 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647                                                                                3x 53x                               3x 54x 54x 54x   107x 107x   54x   54x 54x 54x   54x         54x 53x               54x 54x 53x                           54x   54x 48x   22x 41x 41x   22x 22x 22x   22x                 9x   9x   9x 9x   9x 5x   5x 2x 4x 2x         5x 3x 5x 3x         5x 2x 4x 2x         5x 1x 1x 1x 1x 1x             5x     2x     2x           1x     5x 10x 5x       3x 2x   8x 4x   4x         1x   3x 2x                                                                                                                           2x 2x   4x 2x     2x 2x         1x                       54x 148x 146x 146x 102x 98x               98x                 98x 20x 20x 10x     78x     54x   54x 54x 74x     54x 3x 3x 1x                 54x 54x 54x 54x   54x                                                                                                                                                                                           1x                 54x                                           74x 74x 74x   74x     3x                     74x   74x         74x                                     74x         74x                                                                                                                                                                                                                                                            
import {
    Box,
    Button,
    Card,
    CardContent,
    Chip,
    CircularProgress,
    Collapse,
    IconButton,
    LinearProgress,
    Stack,
    Tooltip,
    Typography,
} from "@mui/material";
import React, { useEffect, useMemo, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import YesNoOption from "@/utils/components/dialogs/YesNoOption";
import { useLocation, useNavigate } from "react-router-dom";
import { _generateAnswersModel } from "@/store/slices/student/StudentQuestionPage";
import { scroller } from "react-scroll";
import { enqueueSnackbar } from "notistack";
 
// Icons
import FlagIcon from "@mui/icons-material/Flag";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
import SendIcon from "@mui/icons-material/Send";
import AssignmentIcon from "@mui/icons-material/Assignment";
import AccessTimeIcon from "@mui/icons-material/AccessTime";
import { alpha } from "@mui/material/styles";
import { isEmptyGraphAnswer } from "@/utils/components/question-bank/question-display/graph/graphAnswerUtils";
import {
    countActiveInteractiveDotsInAnswer,
    isInteractiveDotsAnswerComplete,
    parseInteractiveDotLimitsFromQuestion,
} from "@/utils/components/question-bank/question-display/interactive-dots/interactiveDotsUtils";
 
// Mirrors the student take-assignment tracker's countdown formatting exactly —
// this preview's whole purpose is to show a teacher what the student sees.
const formatDuration = (totalSeconds) => {
    Eif (totalSeconds <= 0) return null;
 
    const days = Math.floor(totalSeconds / 86400);
    const hours = Math.floor((totalSeconds % 86400) / 3600);
    const minutes = Math.floor((totalSeconds % 3600) / 60);
    const seconds = totalSeconds % 60;
 
    const parts = [];
    if (days > 0) parts.push(`${days}d`);
    if (hours > 0) parts.push(`${hours}h`);
    if (minutes > 0) parts.push(`${minutes}m`);
    parts.push(`${seconds}s`);
 
    return parts.join(" ");
};
 
const AnswerTracker = ({ page, setPage }) => {
    const navigate = useNavigate();
    const location = useLocation();
    const dispatch = useDispatch();
 
    const { myAnswers, settings } = useSelector((state) => state.StudentQuestionPage);
    const { assignmentData } = useSelector((state) => state.TeacherCreateAssignment);
 
    const selectedQuestions = assignmentData?.step2?.selectedQuestions ?? [];
 
    const [showYesNoOption, setShowYesNoOption] = useState(false);
    const [showAnswers, setShowAnswers] = useState(true);
    const [secondsUntilClose, setSecondsUntilClose] = useState(null);
 
    const clickYes = () => {
        setShowYesNoOption(false);
        enqueueSnackbar("Assignment successfully submitted", { variant: "success" });
    };
 
    useEffect(() => {
        Iif ((myAnswers?.data?.length ?? 0) === 0 && selectedQuestions.length > 0) {
            dispatch(_generateAnswersModel(selectedQuestions));
        }
    }, [dispatch, myAnswers?.data?.length, selectedQuestions]);
 
    // Preview-only display, no auto-submit: unlike the real take-assignment
    // tracker there is no live submission to auto-submit when time runs out,
    // so this just mirrors the countdown/closed banners for visual parity.
    const dateClose = assignmentData?.step3?.dateAssigned?.dateClose;
    useEffect(() => {
        Eif (!dateClose) return;
 
        const updateCountdown = () => {
            const now = Date.now();
            const closeTime = new Date(dateClose).getTime();
            const diff = Math.floor((closeTime - now) / 1000);
            setSecondsUntilClose(diff);
        };
 
        updateCountdown();
        const intervalId = setInterval(updateCountdown, 1000);
        return () => clearInterval(intervalId);
    }, [dateClose]);
 
    const closingLabel = useMemo(() => formatDuration(secondsUntilClose), [secondsUntilClose]);
 
    const displayAnswer = (entry) => {
        if (!entry || !entry.questionType) return "";
 
        const stripHtml = (text) => {
            Iif (!text || typeof text !== "string") return "";
            return text.replace(/<[^>]+>/g, "").trim();
        };
        const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        const questionMeta = selectedQuestions.find((q) => q._id === entry.questionId);
        const questionType = entry.questionType.toLowerCase();
 
        switch (questionType) {
            case "graph-multiple-select":
            case "graph-multiple-choice": {
                if (!entry.answer) return "";
                const active = countActiveInteractiveDotsInAnswer(entry.answer);
                return active > 0 ? `${active} selected` : "";
            }
 
            case "graph": {
                Iif (!entry.answer) return "";
 
                const points = [];
 
                try {
                    const graphData = typeof entry.answer === "string" ? JSON.parse(entry.answer) : entry.answer;
 
                    if (graphData.format === "Graph2D" && graphData.data) {
                        const data = graphData.data;
 
                        if (Array.isArray(data.pointValueDots)) {
                            for (const point of data.pointValueDots) {
                                if (typeof point.x === "number" && typeof point.y === "number") {
                                    points.push(`(x: ${point.x}, y: ${point.y})`);
                                }
                            }
                        }
 
                        if (Array.isArray(data.dots)) {
                            for (const point of data.dots) {
                                if (typeof point.x === "number" && typeof point.y === "number") {
                                    points.push(`(x: ${point.x}, y: ${point.y})`);
                                }
                            }
                        }
 
                        if (Array.isArray(data.labeldots)) {
                            for (const point of data.labeldots) {
                                if (typeof point.x === "number" && typeof point.y === "number") {
                                    points.push(`(x: ${point.x}, y: ${point.y})`);
                                }
                            }
                        }
 
                        if (Array.isArray(data.tplines)) {
                            for (const line of data.tplines) {
                                Eif (Array.isArray(line.dotData)) {
                                    for (const point of line.dotData) {
                                        Eif (typeof point.x === "number" && typeof point.y === "number") {
                                            points.push(`(x: ${point.x}, y: ${point.y})`);
                                        }
                                    }
                                }
                            }
                        }
 
                        return points.length ? points.join(", ") : "";
                    }
                } catch (e) {
                    return "";
                }
 
                return "";
            }
 
            case "free-response":
                // entry.answer is TinyMCE HTML (see FreeResponse.jsx) — this preview
                // is a single truncated line, so it's stripped to plain text here.
                return stripHtml(entry.answer) || "";
 
            case "multiple-choice": {
                Iif (!questionMeta?.choices || typeof entry.answer !== "string") return "";
                const index = questionMeta.choices.findIndex((c) => stripHtml(c.text) === stripHtml(entry.answer));
                return index >= 0 && index < alphabet.length ? alphabet[index] : "";
            }
 
            case "checkbox": {
                if (!Array.isArray(entry.answer) || !questionMeta?.choices) return "";
                return entry.answer
                    .map((ans) => {
                        const index = questionMeta.choices.findIndex((c) => stripHtml(c.text) === stripHtml(ans));
                        return index >= 0 && index < alphabet.length ? alphabet[index] : null;
                    })
                    .filter((letter) => letter !== null)
                    .join(", ");
            }
 
            case "drag-and-drop":
                return Array.isArray(entry.answer)
                    ? entry.answer
                          .filter((item) => item?.answer?.trim?.() !== "")
                          .map((item) => stripHtml(item.answer))
                          .join(", ")
                    : "";
 
            case "embedded-multiple-choice": {
                // entry.answer is the selected choice's id (not its text — the same
                // phrase can be marked more than once in the passage), so resolve it
                // against the question's choices to show the picked word/phrase.
                if (!questionMeta?.choices || typeof entry.answer !== "string" || !entry.answer) return "";
                const selected = questionMeta.choices.find((c) => c.id === entry.answer);
                return selected ? stripHtml(selected.text) : "";
            }
 
            case "grid-question": {
                // Mirrors the take-assignment tracker's copy exactly — see that
                // file for the full rationale.
                if (!Array.isArray(entry.answer)) return "";
                return entry.answer
                    .filter((item) => item?.answer?.trim?.())
                    .map((item) => {
                        const row = questionMeta?.rows?.find((r) => r.id === item.id);
                        const rowLabel = row ? stripHtml(row.text) : "";
                        return rowLabel ? `${rowLabel}: ${item.answer}` : item.answer;
                    })
                    .join("; ");
            }
 
            case "single-stimulus":
            case "multi-part-question": {
                // Mirrors the take-assignment tracker's copy exactly — see that
                // file for the full rationale.
                if (!questionMeta?.groups || typeof entry.answer !== "object" || entry.answer === null) return "";
                return questionMeta.groups
                    .map((group, groupIdx) => {
                        const groupAnswer = entry.answer[group.group_id];
                        if (group.type === "drop-down" || group.type === "drag-and-drop") {
                            if (!Array.isArray(groupAnswer)) return null;
                            const filled = groupAnswer
                                .filter((item) => {
                                    if (typeof item === "string") return item.trim() !== "";
                                    return item?.answer?.trim?.() !== "";
                                })
                                .map((item) => stripHtml(typeof item === "string" ? item : item.answer));
                            return filled.length ? `Group ${groupIdx + 1}: ${filled.join(", ")}` : null;
                        }
                        const values = Array.isArray(groupAnswer) ? groupAnswer : groupAnswer ? [groupAnswer] : [];
                        if (values.length === 0) return null;
                        const groupLetters = values
                            .map((value) => {
                                const index = (group.choices || []).findIndex(
                                    (c) => stripHtml(c.text) === stripHtml(value)
                                );
                                return index >= 0 && index < alphabet.length ? alphabet[index] : null;
                            })
                            .filter((letter) => letter !== null);
                        return groupLetters.length ? `Group ${groupIdx + 1}: ${groupLetters.join(", ")}` : null;
                    })
                    .filter(Boolean)
                    .join(" · ");
            }
 
            case "drop-down-menu":
                Iif (!Array.isArray(entry.answer)) return "";
                return entry.answer
                    .filter((item) => {
                        if (typeof item === "string") return item.trim() !== "";
                        return item?.answer?.trim?.() !== "";
                    })
                    .map((item) => {
                        const text = typeof item === "string" ? item : item.answer;
                        return stripHtml(text);
                    })
                    .join(", ");
 
            default:
                return "";
        }
    };
 
    // Modified by Allan Ninal — graph answers cannot be judged by emptiness of the
    // string. An UNTOUCHED canvas does not serialize to ""; it comes back fully
    // populated with empty collections (`lines#o#{}&dots#o#{}&…`), so the `return
    // true` below counted it as answered. A single click on the graph is enough for
    // the autosave to store that, and the student is then told everything is done and
    // submits a blank graph. `isEmptyGraphAnswer` is the helper written for this — its
    // docstring says a `trim() !== ""` test can never detect an empty canvas — and
    // nothing was calling it here.
    const isAnswered = (entry) => {
        if (!entry) return false;
        const { answer } = entry;
        if (answer === "" || answer === null || answer === undefined) return false;
        if (entry.questionType === "graph") return !isEmptyGraphAnswer(answer);
        Iif (
            entry.questionType === "graph-multiple-select" ||
            entry.questionType === "graph-multiple-choice"
        ) {
            const questionMeta = selectedQuestions.find((q) => q._id === entry.questionId);
            const limits = parseInteractiveDotLimitsFromQuestion(questionMeta);
            return isInteractiveDotsAnswerComplete(answer, limits);
        }
        Iif (entry.questionType === "single-stimulus" || entry.questionType === "multi-part-question") {
            const questionMeta = selectedQuestions.find((q) => q._id === entry.questionId);
            const groups = questionMeta?.groups || [];
            if (groups.length === 0 || typeof answer !== "object") return false;
            return groups.every((g) => {
                const value = answer[g.group_id];
                return Array.isArray(value) ? value.length > 0 : Boolean(value);
            });
        }
        if (Array.isArray(answer)) {
            return !answer.every((item) => {
                if (typeof item !== "object" || item === null) return false;
                return "answer" in item && item.answer === "";
            });
        }
        return true;
    };
 
    const totalAnswers = (entries = []) => entries.filter(isAnswered).length;
 
    const totalFlaggedQuestions = (questionsList) => {
        Iif (!Array.isArray(questionsList)) return 0;
        return questionsList.reduce((count, q) => (q?.isFlagged ? count + 1 : count), 0);
    };
 
    const handleViewQuestion = (questionIndex) => {
        setPage(questionIndex + 1);
        if (settings.layout === "1") {
            scroller.scrollTo(`question-${questionIndex}`, {
                duration: 800,
                delay: 0,
                smooth: "easeInOutQuart",
                offset: -150,
            });
        }
    };
 
    const answeredCount = totalAnswers(Object.values(myAnswers?.data ?? {}));
    const totalQuestions = selectedQuestions.length;
    const flaggedCount = totalFlaggedQuestions(myAnswers.data);
    const progressPercent = totalQuestions > 0 ? (answeredCount / totalQuestions) * 100 : 0;
 
    return (
        <Box>
            {selectedQuestions && (
                <>
                    <YesNoOption
                        title="Confirm Submission"
                        message={
                            answeredCount === totalQuestions
                                ? "Do you want to submit all your answers?"
                                : `You have ${totalQuestions - answeredCount} unanswered question${totalQuestions - answeredCount !== 1 ? "s" : ""} and ${flaggedCount} flagged question${flaggedCount !== 1 ? "s" : ""}. Do you want to submit all your answers? Warning: unanswered questions will be marked as wrong.`
                        }
                        showDialog={showYesNoOption}
                        clickNo={() => setShowYesNoOption(false)}
                        clickYes={clickYes}
                    />
 
                    <Card
                        sx={{
                            borderRadius: 3,
                            boxShadow: "0 4px 20px rgba(0, 0, 0, 0.08)",
                            overflow: "hidden",
                        }}
                    >
                        {/* Header */}
                        <Box
                            sx={{
                                p: 2,
                                background: "linear-gradient(135deg, #1976d2 0%, #1565c0 100%)",
                                color: "white",
                            }}
                        >
                            <Box sx={{ display: "flex", alignItems: "center", gap: 1, mb: 1 }}>
                                <AssignmentIcon fontSize="small" />
                                <Typography variant="subtitle1" fontWeight={600}>
                                    Answer Tracker
                                </Typography>
                            </Box>
 
                            {/* Progress Section */}
                            <Box sx={{ mt: 1.5 }}>
                                <Box sx={{ display: "flex", justifyContent: "space-between", mb: 0.5 }}>
                                    <Typography variant="caption" sx={{ opacity: 0.9 }}>
                                        Progress
                                    </Typography>
                                    <Typography variant="caption" fontWeight={600}>
                                        {answeredCount} / {totalQuestions}
                                    </Typography>
                                </Box>
                                <LinearProgress
                                    variant="determinate"
                                    value={progressPercent}
                                    sx={{
                                        height: 8,
                                        borderRadius: 4,
                                        backgroundColor: "action.disabledBackground",
                                        "& .MuiLinearProgress-bar": {
                                            backgroundColor: "success.main",
                                            borderRadius: 4,
                                        },
                                    }}
                                />
                            </Box>
 
                            {/* Stats Chips */}
                            <Stack direction="row" spacing={1} sx={{ mt: 1.5 }}>
                                <Chip
                                    size="small"
                                    icon={<CheckCircleIcon sx={{ fontSize: 16, color: "#4caf50 !important" }} />}
                                    label={`${answeredCount} Answered`}
                                    sx={{
                                        bgcolor: "rgba(255,255,255,0.15)",
                                        color: "white",
                                        fontSize: 11,
                                        height: 24,
                                    }}
                                />
                                {flaggedCount > 0 && (
                                    <Chip
                                        size="small"
                                        icon={<FlagIcon sx={{ fontSize: 14, color: "#ffb74d !important" }} />}
                                        label={`${flaggedCount} Flagged`}
                                        sx={{
                                            bgcolor: "rgba(255,255,255,0.15)",
                                            color: "white",
                                            fontSize: 11,
                                            height: 24,
                                        }}
                                    />
                                )}
                            </Stack>
                        </Box>
 
                        {/* Toggle Button */}
                        <Box
                            onClick={() => setShowAnswers(!showAnswers)}
                            sx={{
                                display: "flex",
                                alignItems: "center",
                                justifyContent: "space-between",
                                px: 2,
                                py: 1,
                                cursor: "pointer",
                                bgcolor: "action.hover",
                                borderBottom: (t) => `1px solid ${t.palette.divider}`,
                                "&:hover": { bgcolor: "action.selected" },
                            }}
                        >
                            <Typography variant="body2" color="text.secondary" fontWeight={500}>
                                {showAnswers ? "Hide Answers" : "Show Answers"}
                            </Typography>
                            <IconButton size="small">
                                {showAnswers ? <ExpandLessIcon /> : <ExpandMoreIcon />}
                            </IconButton>
                        </Box>
 
                        {/* Answer List */}
                        <Collapse in={showAnswers}>
                            <Box
                                sx={{
                                    maxHeight: "45vh",
                                    overflowY: "auto",
                                    p: 1,
                                }}
                            >
                                {myAnswers.data?.map((entry, answerIndex) => {
                                    const answered = isAnswered(entry);
                                    const isCurrent = page - 1 === answerIndex;
                                    const isFlagged = entry?.isFlagged;
 
                                    return (
                                        <Box
                                            key={answerIndex}
                                            onClick={() => handleViewQuestion(answerIndex)}
                                            sx={{
                                                display: "flex",
                                                alignItems: "center",
                                                gap: 1.5,
                                                p: 1.5,
                                                mb: 0.5,
                                                borderRadius: 2,
                                                cursor: "pointer",
                                                transition: "all 0.2s ease",
                                                bgcolor: (t) =>
                                                    isCurrent ? alpha(t.palette.primary.main, 0.1) : "transparent",
                                                border: (t) =>
                                                    isCurrent
                                                        ? `1px solid ${alpha(t.palette.primary.main, 0.4)}`
                                                        : "1px solid transparent",
                                                "&:hover": {
                                                    bgcolor: (t) =>
                                                        isCurrent
                                                            ? alpha(t.palette.primary.main, 0.1)
                                                            : t.palette.action.selected,
                                                },
                                            }}
                                        >
                                            {/* Question Number Badge */}
                                            <Box
                                                sx={{
                                                    width: 28,
                                                    height: 28,
                                                    borderRadius: "50%",
                                                    display: "flex",
                                                    alignItems: "center",
                                                    justifyContent: "center",
                                                    fontSize: 12,
                                                    fontWeight: 600,
                                                    flexShrink: 0,
                                                    bgcolor: (t) =>
                                                        answered
                                                            ? alpha(t.palette.success.main, 0.12)
                                                            : t.palette.action.hover,
                                                    color: answered ? "success.main" : "text.disabled",
                                                    border: (t) =>
                                                        answered
                                                            ? `2px solid ${t.palette.success.main}`
                                                            : `2px solid ${t.palette.divider}`,
                                                }}
                                            >
                                                {answerIndex + 1}
                                            </Box>
 
                                            {/* Answer Content */}
                                            <Box sx={{ flex: 1, minWidth: 0 }}>
                                                <Typography
                                                    variant="body2"
                                                    sx={{
                                                        color: answered ? "text.primary" : "text.disabled",
                                                        fontWeight: answered ? 500 : 400,
                                                        whiteSpace: "nowrap",
                                                        overflow: "hidden",
                                                        textOverflow: "ellipsis",
                                                    }}
                                                >
                                                    {answered ? displayAnswer(entry) : "Not answered"}
                                                </Typography>
                                            </Box>
 
                                            {/* Status Icons */}
                                            {isFlagged && (
                                                <Tooltip title="Flagged for review">
                                                    <FlagIcon
                                                        sx={{
                                                            fontSize: 18,
                                                            color: "warning.main",
                                                        }}
                                                    />
                                                </Tooltip>
                                            )}
                                        </Box>
                                    );
                                })}
                            </Box>
                        </Collapse>
 
                        {/* Assignment close countdown */}
                        {closingLabel && (
                            <Box
                                sx={{
                                    display: "flex",
                                    alignItems: "center",
                                    justifyContent: "center",
                                    gap: 1,
                                    px: 2,
                                    py: 1.25,
                                    bgcolor: (t) =>
                                        secondsUntilClose < 300
                                            ? alpha(t.palette.warning.main, 0.1)
                                            : alpha(t.palette.info.main, 0.1),
                                    borderBottom: "1px solid",
                                    borderColor: (t) =>
                                        secondsUntilClose < 300
                                            ? alpha(t.palette.warning.main, 0.3)
                                            : alpha(t.palette.info.main, 0.3),
                                }}
                            >
                                <AccessTimeIcon
                                    sx={{
                                        fontSize: 18,
                                        color: secondsUntilClose < 300 ? "warning.dark" : "info.dark",
                                    }}
                                />
                                <Typography
                                    variant="body2"
                                    fontWeight={600}
                                    sx={{
                                        color: secondsUntilClose < 300 ? "warning.dark" : "info.dark",
                                    }}
                                >
                                    Assignment closes in {closingLabel}
                                </Typography>
                            </Box>
                        )}
                        {secondsUntilClose !== null && secondsUntilClose <= 0 && (
                            <Box
                                sx={{
                                    display: "flex",
                                    alignItems: "center",
                                    justifyContent: "center",
                                    gap: 1,
                                    px: 2,
                                    py: 1.25,
                                    bgcolor: (t) => alpha(t.palette.error.main, 0.1),
                                    borderBottom: (t) => `1px solid ${alpha(t.palette.error.main, 0.3)}`,
                                }}
                            >
                                <AccessTimeIcon sx={{ fontSize: 18, color: "error.dark" }} />
                                <Typography variant="body2" fontWeight={600} sx={{ color: "error.dark" }}>
                                    Assignment is closed
                                </Typography>
                            </Box>
                        )}
 
                        {/* Submit Button */}
                        <CardContent sx={{ p: 2, pt: 1.5, pb: "16px !important" }}>
                            <Button
                                variant="contained"
                                color="primary"
                                disabled={true}
                                fullWidth
                                startIcon={<SendIcon />}
                                sx={{
                                    py: 1.25,
                                    borderRadius: 2,
                                    textTransform: "none",
                                    fontWeight: 600,
                                    fontSize: 15,
                                }}
                            >
                                Submit Answers
                            </Button>
                        </CardContent>
                    </Card>
                </>
            )}
        </Box>
    );
};
 
export default AnswerTracker;