All files / src/utils/components/question-bank/question-content/embedded-multiple-choice EmbeddedMultipleChoiceEditor.jsx

73.56% Statements 64/87
78.94% Branches 75/95
64.28% Functions 18/28
71.25% Lines 57/80

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 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711                                                                                                                        1x                                                                                           116x   116x 116x 116x     116x 116x 116x     116x 116x           116x 19x 19x 19x       116x 232x 232x 232x 232x 232x 232x     116x 3x           116x                     116x                     116x 5x 1x       1x   4x 2x 2x   2x 2x       116x 5x   2x   4x     2x 1x 1x         116x 116x 22x               94x                 94x                 94x     116x     116x 8x         116x                                                                                                                                                                                                                                                                                                                 180x             2x                                                                                                                                                                                                                                                           143x 143x                                         3x                                                                             60x                                                                                                                                                                                                                                                  
import React, { useEffect, useState } from "react";
import "./EmbeddedMultipleChoiceEditor.scss";
import {
    Alert,
    Box,
    Button,
    Card,
    CardContent,
    Chip,
    Collapse,
    IconButton,
    LinearProgress,
    Paper,
    Stack,
    Tooltip,
    Typography,
} from "@mui/material";
import { useTheme } from "@mui/material/styles";
import ReadOnlyMathEditor from "@/utils/components/TinyMCETextEditorReadOnly";
import UnsavedChangesDialog from "@/utils/components/UnsavedChangesDialog";
import tinyMCEUtility from "@/utils/helpers/tinyMCEUtility";
import { sanitizeRichText } from "@/utils/helpers/sanitizeHtml";
import EmbeddedChoicePassage from "@/utils/components/question-bank/question-display/embedded-multiple-choice/EmbeddedChoicePassage";
import { questionCardSurfaceBg } from "@/utils/components/question-bank/question-display/utils/questionCardStyles";
 
// Icons
import AddIcon from "@mui/icons-material/Add";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import EditIcon from "@mui/icons-material/Edit";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
import SaveIcon from "@mui/icons-material/Save";
import CloseIcon from "@mui/icons-material/Close";
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
import FormatUnderlinedIcon from "@mui/icons-material/FormatUnderlined";
import SettingsIcon from "@mui/icons-material/Settings";
import ListAltIcon from "@mui/icons-material/ListAlt";
import NoteAddIcon from "@mui/icons-material/NoteAdd";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
 
import {
    letters,
    useQuestionForm,
    TextEditorDialog,
    QuestionSettings,
    QuickTipsCard,
    getClassificationProgress,
    editorContainerSx,
    editorHeaderSx,
    cardHeaderHoverSx,
    editorCardSx,
    contentPreviewSx,
    emptyStateSx,
    choiceBadgeSx,
    correctAnswerBadgeSx,
    tipsCardSx,
} from "../utils";
 
const EmbeddedMultipleChoiceEditor = ({ role = "teacher" }) => {
    const {
        displayError,
        setDisplayError,
        editQuestion,
        isEditMode,
        questionText,
        setQuestionText,
        questionTextEditor,
        setQuestionTextEditor,
        showQuestionTextEditor,
        questionDetailsText,
        setQuestionDetailsText,
        questionDetailsTextEditor,
        setQuestionDetailsTextEditor,
        showQuestionDetailsTextEditor,
        answerDetailsText,
        setAnswerDetailsText,
        answerDetailsTextEditor,
        setAnswerDetailsTextEditor,
        showAnswerDetailsTextEditor,
        values,
        touched,
        errors,
        handleChange,
        handleBlur,
        setFieldValue,
        setFieldTouched,
        handleCancel,
        clickQuestionButton,
        saveQuestion,
        cancelQuestion,
        clickQuestionDetailsButton,
        saveQuestionDetails,
        cancelQuestionDetails,
        clickEditAnswerDetails,
        saveAnswerDetails,
        cancelEditAnswerDetails,
        deleteAnswerDetails,
        submitQuestion,
        buildBasePayload,
        loadEditData,
        resetFields,
        handleImageUpload,
        SaveProgress,
        navigationBlocker,
    } = useQuestionForm(role);
 
    const { extractEmbeddedChoices } = tinyMCEUtility();
    const theme = useTheme();
    const cardBg = questionCardSurfaceBg(theme);
 
    // Expandable sections
    const [questionDetailsExpanded, setQuestionDetailsExpanded] = useState(false);
    const [answerDetailsExpanded, setAnswerDetailsExpanded] = useState(false);
    const [settingsExpanded, setSettingsExpanded] = useState(true);
 
    // Embedded-choice specific state
    const [isChoices, setChoices] = useState([]);
    const [correctChoiceId, setCorrectChoiceId] = useState(null);
 
    // Choices live inside the passage HTML itself (the teacher highlights words in
    // the "Mark as Answer Choice" toolbar button, which wraps the selection in a
    // <span data-embedded-choice-id>) — so the choice list is always re-derived
    // from questionText rather than kept as separately-managed state.
    useEffect(() => {
        const extracted = extractEmbeddedChoices(questionText);
        setChoices(extracted);
        setCorrectChoiceId((prev) => (prev && extracted.some((c) => c.id === prev) ? prev : null));
    }, [questionText]);
 
    // Progress calculation
    const getProgress = () => {
        let progress = 0;
        if (questionText) progress += 25;
        if (isChoices.length > 0) progress += 25;
        if (correctChoiceId) progress += 25;
        progress += (getClassificationProgress(values) / 100) * 25;
        return Math.round(progress);
    };
 
    const toggleCorrect = (id) => {
        setCorrectChoiceId((prev) => (prev === id ? null : id));
    };
 
    // Unwraps the choice span, leaving its original content (plain text OR a
    // math formula's rendered markup) back in the passage untouched — replacing
    // it with a flattened text node would garble a formula choice on removal.
    const removeChoice = (id) => {
        const container = document.createElement("div");
        container.innerHTML = questionText;
        const node = container.querySelector(`[data-embedded-choice-id="${id}"]`);
        if (node) {
            node.replaceWith(...node.childNodes);
        }
        setQuestionText(container.innerHTML);
    };
 
    // Reset all values
    const handleReset = () => {
        setQuestionText("");
        setQuestionDetailsText("");
        setAnswerDetailsText("");
        setChoices([]);
        setCorrectChoiceId(null);
        setDisplayError({ status: false, message: "" });
        resetFields();
    };
 
    // Validation
    const hasValidSelection = () => {
        if (isChoices.length === 0) {
            setDisplayError({
                status: true,
                message: "Please mark at least one answer choice in the passage.",
            });
            return false;
        }
        if (!correctChoiceId) {
            setDisplayError({ status: true, message: "Please select the correct answer choice." });
            return false;
        }
        setDisplayError({ status: false, message: "" });
        return true;
    };
 
    // Submit handler - SAME PAYLOAD STRUCTURE
    const createNewQuestion = async () => {
        if (!hasValidSelection()) return;
 
        const payload = {
            ...buildBasePayload("Embedded-Multiple-Choice", [correctChoiceId]),
            choices: isChoices.map(({ id, text }) => ({ id, text })),
        };
 
        await submitQuestion(payload, () => {
            setChoices([]);
            setCorrectChoiceId(null);
        });
    };
 
    // Dialog management
    const getActiveDialog = () => {
        if (showQuestionTextEditor)
            return {
                type: "question",
                content: questionTextEditor,
                setContent: setQuestionTextEditor,
                save: saveQuestion,
                cancel: cancelQuestion,
                questionTypes: ["embeddedMultipleChoice"],
            };
        Iif (showAnswerDetailsTextEditor)
            return {
                type: "answerDetails",
                content: answerDetailsTextEditor,
                setContent: setAnswerDetailsTextEditor,
                save: saveAnswerDetails,
                cancel: cancelEditAnswerDetails,
                questionTypes: [],
            };
        Iif (showQuestionDetailsTextEditor)
            return {
                type: "questionDetails",
                content: questionDetailsTextEditor,
                setContent: setQuestionDetailsTextEditor,
                save: saveQuestionDetails,
                cancel: cancelQuestionDetails,
                questionTypes: [],
            };
        return null;
    };
 
    const activeDialog = getActiveDialog();
 
    // Load edit data
    useEffect(() => {
        loadEditData((data) => {
            setCorrectChoiceId(data.correctAnswer?.answers?.[0] ?? null);
        });
    }, []);
 
    return (
        <Box className="embedded-mc-container" sx={editorContainerSx()}>
            <SaveProgress />
            <UnsavedChangesDialog blocker={navigationBlocker} />
            {/* Dialog */}
            {activeDialog && (
                <TextEditorDialog
                    open={true}
                    editorType={activeDialog.type}
                    isEditMode={isEditMode}
                    editContent={activeDialog.content}
                    setEditContent={activeDialog.setContent}
                    onSave={activeDialog.save}
                    onCancel={activeDialog.cancel}
                    questionTypes={activeDialog.questionTypes}
                    onImageUpload={handleImageUpload}
                />
            )}
 
            {/* Header */}
            <Paper className="embedded-mc-header" elevation={0} sx={editorHeaderSx()}>
                <Box className="embedded-mc-header-content">
                    <Box className="embedded-mc-header-left">
                        <FormatUnderlinedIcon sx={{ fontSize: 28, color: "primary.main" }} />
                        <Box>
                            <Typography variant="h5" fontWeight={600}>
                                {editQuestion ? "Edit Question" : "Create Embedded Multiple-Choice Question"}
                            </Typography>
                            <Typography variant="body2" color="text.secondary">
                                {editQuestion
                                    ? "Update your question details"
                                    : "Write a passage and mark words or phrases as answer choices"}
                            </Typography>
                        </Box>
                    </Box>
                    <Box className="embedded-mc-header-actions">
                        <Button variant="outlined" color="inherit" onClick={handleCancel} startIcon={<CloseIcon />}>
                            Cancel
                        </Button>
                        <Button variant="outlined" color="warning" onClick={handleReset} startIcon={<RestartAltIcon />}>
                            Reset
                        </Button>
                        <Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
                            <Button
                                variant="contained"
                                color="primary"
                                onClick={createNewQuestion}
                                startIcon={<SaveIcon />}
                            >
                                {editQuestion ? "Update" : "Save Question"}
                            </Button>
                            <Tooltip
                                title={
                                    <Box sx={{ p: 1 }}>
                                        <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 1 }}>
                                            Required Fields:
                                        </Typography>
                                        <Stack spacing={0.5}>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {questionText ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Passage with marked choices
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {isChoices.length > 0 ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                At least one answer choice
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {correctChoiceId ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Correct answer selected
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {values.assignmentType ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Assignment type
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {values.questionPoints ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Question points
                                            </Typography>
                                        </Stack>
                                    </Box>
                                }
                                arrow
                                placement="bottom-end"
                            >
                                <IconButton size="small" sx={{ color: "primary.main" }}>
                                    <HelpOutlineIcon fontSize="small" />
                                </IconButton>
                            </Tooltip>
                        </Box>
                    </Box>
                </Box>
 
                {/* Progress bar */}
                <Box className="embedded-mc-progress">
                    <LinearProgress
                        variant="determinate"
                        value={getProgress()}
                        color="success"
                        sx={{ height: 6, borderRadius: 3 }}
                    />
                    <Typography variant="caption" color="text.secondary" sx={{ mt: 0.5 }}>
                        {getProgress()}% complete
                    </Typography>
                </Box>
            </Paper>
 
            {/* Error Alert */}
            {displayError.status && (
                <Alert
                    severity="error"
                    sx={{ mx: 3, mt: 2 }}
                    onClose={() => setDisplayError({ status: false, message: "" })}
                >
                    {displayError.message}
                </Alert>
            )}
 
            {/* Question Settings Validation Errors */}
            {Object.keys(errors).some((key) => touched[key]) && (
                <Alert severity="error" sx={{ mx: 3, mt: 2 }}>
                    <Typography variant="body2" fontWeight={600} sx={{ mb: 0.5 }}>
                        Please complete the required question settings:
                    </Typography>
                    <Stack spacing={0.25}>
                        {Object.entries(errors).map(([key, message]) =>
                            touched[key] ? (
                                <Typography key={key} variant="caption">
                                    • {message}
                                </Typography>
                            ) : null
                        )}
                    </Stack>
                </Alert>
            )}
 
            {/* Main Content */}
            <Box className="embedded-mc-main">
                {/* Left Panel - Question & Choices */}
                <Box className="embedded-mc-left-panel">
                    {/* Question Card */}
                    <Card className="embedded-mc-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box className="embedded-mc-card-header">
                                <Box className="embedded-mc-card-title">
                                    <HelpOutlineIcon color="primary" />
                                    <Typography variant="h6">Passage</Typography>
                                    {questionText && <CheckCircleIcon color="success" fontSize="small" />}
                                </Box>
                                <Button
                                    variant={questionText ? "outlined" : "contained"}
                                    size="small"
                                    startIcon={questionText ? <EditIcon /> : <AddIcon />}
                                    onClick={clickQuestionButton}
                                >
                                    {questionText ? "Edit" : "Add Passage"}
                                </Button>
                            </Box>
 
                            {questionText ? (
                                <Paper
                                    variant="outlined"
                                    className="embedded-mc-content-preview"
                                    sx={contentPreviewSx()}
                                >
                                    <EmbeddedChoicePassage
                                        html={questionText}
                                        interactive={false}
                                        showAnswers
                                        correctId={correctChoiceId}
                                        backgroundColor={cardBg}
                                    />
                                </Paper>
                            ) : (
                                <Box className="embedded-mc-empty-state" sx={emptyStateSx(theme)}>
                                    <NoteAddIcon sx={{ fontSize: 48, color: "action.disabled" }} />
                                    <Typography color="text.secondary">
                                        Click "Add Passage" to write your question
                                    </Typography>
                                    <Typography variant="caption" color="text.secondary">
                                        Highlight a word or phrase, then use the underline button in the editor toolbar
                                        to mark it as an answer choice
                                    </Typography>
                                </Box>
                            )}
 
                            {/* Question Details - Collapsible */}
                            <Box sx={{ mt: 2 }}>
                                <Button
                                    size="small"
                                    onClick={() => setQuestionDetailsExpanded(!questionDetailsExpanded)}
                                    endIcon={questionDetailsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
                                    sx={{ textTransform: "none" }}
                                >
                                    Question Details (Optional)
                                    {questionDetailsText && (
                                        <CheckCircleIcon color="success" fontSize="small" sx={{ ml: 1 }} />
                                    )}
                                </Button>
                                <Collapse in={questionDetailsExpanded}>
                                    <Box sx={{ mt: 1 }}>
                                        {questionDetailsText ? (
                                            <Paper
                                                variant="outlined"
                                                className="embedded-mc-content-preview"
                                                sx={contentPreviewSx()}
                                            >
                                                <ReadOnlyMathEditor content={questionDetailsText} />
                                                <IconButton
                                                    size="small"
                                                    onClick={clickQuestionDetailsButton}
                                                    sx={{ position: "absolute", top: 8, right: 8 }}
                                                >
                                                    <EditIcon fontSize="small" />
                                                </IconButton>
                                            </Paper>
                                        ) : (
                                            <Button
                                                variant="text"
                                                size="small"
                                                startIcon={<AddIcon />}
                                                onClick={clickQuestionDetailsButton}
                                            >
                                                Add details or hints
                                            </Button>
                                        )}
                                    </Box>
                                </Collapse>
                            </Box>
                        </CardContent>
                    </Card>
 
                    {/* Choices Card */}
                    {isChoices.length > 0 && (
                        <Card className="embedded-mc-card" sx={editorCardSx(theme)}>
                            <CardContent>
                                <Box className="embedded-mc-card-header">
                                    <Box className="embedded-mc-card-title">
                                        <ListAltIcon color="primary" />
                                        <Typography variant="h6">Answer Choices</Typography>
                                        <Chip
                                            size="small"
                                            label={`${isChoices.length} choice${isChoices.length > 1 ? "s" : ""}`}
                                            color="primary"
                                            variant="filled"
                                            sx={{ fontWeight: 500 }}
                                        />
                                    </Box>
                                </Box>
 
                                <Box className="embedded-mc-choices-list">
                                    {isChoices.map((choice, index) => {
                                        const isAnswer = correctChoiceId === choice.id;
                                        return (
                                            <Paper
                                                key={choice.id}
                                                variant="outlined"
                                                className="embedded-mc-choice-item"
                                                sx={{
                                                    bgcolor: `${cardBg} !important`,
                                                    borderColor: isAnswer ? "success.main" : "divider",
                                                }}
                                            >
                                                <Box sx={choiceBadgeSx(theme, { correct: isAnswer })}>
                                                    {letters[index] ?? index + 1}
                                                </Box>
                                                <Typography
                                                    component="div"
                                                    sx={{ flex: 1, "& .mfe-formula": { color: "inherit" } }}
                                                    dangerouslySetInnerHTML={{ __html: sanitizeRichText(choice.text) }}
                                                />
                                                <Tooltip title={isAnswer ? "Correct answer" : "Mark as correct"}>
                                                    <IconButton
                                                        size="small"
                                                        onClick={() => toggleCorrect(choice.id)}
                                                        color={isAnswer ? "success" : "default"}
                                                    >
                                                        {isAnswer ? <CheckCircleIcon /> : <CheckCircleOutlineIcon />}
                                                    </IconButton>
                                                </Tooltip>
                                                <IconButton
                                                    size="small"
                                                    onClick={() => removeChoice(choice.id)}
                                                    color="error"
                                                >
                                                    <DeleteOutlineIcon fontSize="small" />
                                                </IconButton>
                                            </Paper>
                                        );
                                    })}
                                </Box>
 
                                {/* Correct Answer Display */}
                                {correctChoiceId && (
                                    <Box
                                        sx={{
                                            mt: 2,
                                            p: 1.5,
                                            display: "flex",
                                            alignItems: "center",
                                            gap: 1,
                                            borderRadius: 1.5,
                                            ...correctAnswerBadgeSx(theme),
                                        }}
                                    >
                                        <CheckCircleIcon color="success" fontSize="small" />
                                        <Typography variant="body2" component="div" sx={{ display: "flex", gap: 0.5 }}>
                                            Correct Answer:
                                            <Box
                                                component="strong"
                                                sx={{ "& .mfe-formula": { color: "inherit" } }}
                                                dangerouslySetInnerHTML={{
                                                    __html: sanitizeRichText(
                                                        isChoices.find((c) => c.id === correctChoiceId)?.text || ""
                                                    ),
                                                }}
                                            />
                                        </Typography>
                                    </Box>
                                )}
                            </CardContent>
                        </Card>
                    )}
 
                    {/* Answer Details Card - Collapsible */}
                    <Card className="embedded-mc-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box
                                className="embedded-mc-card-header clickable"
                                onClick={() => setAnswerDetailsExpanded(!answerDetailsExpanded)}
                                sx={cardHeaderHoverSx(theme)}
                            >
                                <Box className="embedded-mc-card-title">
                                    <NoteAddIcon color="primary" />
                                    <Typography variant="h6">Answer Explanation (Optional)</Typography>
                                    {answerDetailsText && <CheckCircleIcon color="success" fontSize="small" />}
                                </Box>
                                {answerDetailsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
                            </Box>
 
                            <Collapse in={answerDetailsExpanded}>
                                <Box sx={{ mt: 2 }}>
                                    {answerDetailsText ? (
                                        <Paper
                                            variant="outlined"
                                            className="embedded-mc-content-preview"
                                            sx={{ position: "relative", ...contentPreviewSx() }}
                                        >
                                            <ReadOnlyMathEditor content={answerDetailsText} />
                                            <Box
                                                sx={{
                                                    position: "absolute",
                                                    top: 8,
                                                    right: 8,
                                                    display: "flex",
                                                    gap: 0.5,
                                                }}
                                            >
                                                <IconButton
                                                    size="small"
                                                    onClick={() => clickEditAnswerDetails(answerDetailsText)}
                                                >
                                                    <EditIcon fontSize="small" />
                                                </IconButton>
                                                <IconButton size="small" onClick={deleteAnswerDetails} color="error">
                                                    <DeleteOutlineIcon fontSize="small" />
                                                </IconButton>
                                            </Box>
                                        </Paper>
                                    ) : (
                                        <Button
                                            variant="outlined"
                                            startIcon={<AddIcon />}
                                            onClick={() => clickEditAnswerDetails("")}
                                            fullWidth
                                        >
                                            Add Answer Explanation
                                        </Button>
                                    )}
                                </Box>
                            </Collapse>
                        </CardContent>
                    </Card>
                </Box>
 
                {/* Right Panel - Tips + Settings */}
                <Box className="embedded-mc-right-panel">
                    <QuickTipsCard
                        className="embedded-mc-card embedded-mc-tips-card"
                        sx={{ ...editorCardSx(theme), ...tipsCardSx(theme) }}
                        tips={[
                            "Highlight a word or phrase in the passage, then click the underline toolbar button to mark it as a choice",
                            "Mark at least one choice, then pick the correct one from the list below",
                            "Punctuation next to a highlighted word is left out of the choice automatically",
                            "Choices can't overlap — mark separate words or phrases",
                        ]}
                    />
 
                    <Card className="embedded-mc-card embedded-mc-settings-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box
                                className="embedded-mc-card-header clickable"
                                onClick={() => setSettingsExpanded(!settingsExpanded)}
                                sx={cardHeaderHoverSx(theme)}
                            >
                                <Box className="embedded-mc-card-title">
                                    <SettingsIcon color="primary" />
                                    <Typography variant="h6">Question Settings</Typography>
                                </Box>
                                {settingsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
                            </Box>
 
                            <Collapse in={settingsExpanded}>
                                <Box sx={{ mt: 2 }}>
                                    <QuestionSettings
                                        values={values}
                                        touched={touched}
                                        errors={errors}
                                        handleChange={handleChange}
                                        handleBlur={handleBlur}
                                        setFieldValue={setFieldValue}
                                        setFieldTouched={setFieldTouched}
                                    />
                                </Box>
                            </Collapse>
                        </CardContent>
                    </Card>
                </Box>
            </Box>
        </Box>
    );
};
 
export default EmbeddedMultipleChoiceEditor;