All files / src/utils/components/question-bank/question-content/drag-and-drop DragAndDropEditor.jsx

93.75% Statements 120/128
87.85% Branches 94/107
84.61% Functions 33/39
93.16% Lines 109/117

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 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782                                                                                                                    4x 300x 300x 300x 298x   2x     4x                                                                                             360x   360x 360x     360x 360x 360x     360x 360x 360x 360x 360x           360x     360x 4x     360x 2x       360x 720x 720x 720x 720x 720x 720x       360x 29x 29x 29x 29x     360x 1x 1x 1x 1x     360x 1x 1x 1x 1x     360x 29x 1x 2x         28x 28x 28x     29x 29x 29x 29x     360x 5x 10x 5x       360x 2x 2x 2x 2x 2x 2x 2x 2x       360x 8x 3x 3x   5x 1x 1x   4x 4x       360x 8x   4x 4x                   4x 4x 4x 4x         360x 360x 44x               316x 60x                 256x                 256x                 256x     360x     360x 29x 2x 2x 2x 2x       360x                                                                                                                                                                         253x                                                                                                                                         372x             4x                                                                                                                                                                                                                                                                         2x                               300x                                             1x         5x                                                                                                                                                                                                                                                                                    
import React, { useEffect, useState } from "react";
import "./DragAndDropEditor.scss";
import {
    Alert,
    Box,
    Button,
    Card,
    CardContent,
    Checkbox,
    Chip,
    Collapse,
    FormControlLabel,
    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";
 
// 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 DragIndicatorIcon from "@mui/icons-material/DragIndicator";
import SettingsIcon from "@mui/icons-material/Settings";
import NoteAddIcon from "@mui/icons-material/NoteAdd";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
 
import DragDropFeature from "./DragDrop";
import {
    useQuestionForm,
    TextEditorDialog,
    QuestionSettings,
    QuickTipsCard,
    getClassificationProgress,
    editorContainerSx,
    editorHeaderSx,
    cardHeaderHoverSx,
    editorCardSx,
    contentPreviewSx,
    emptyStateSx,
    neutralSurfaceSx,
    tipsCardSx,
} from "../utils";
import { sanitizeRichText } from "@/utils/helpers/sanitizeHtml";
 
const unwrapBlock = (html) => {
    const el = document.createElement("div");
    el.innerHTML = html;
    if (el.children.length === 1 && el.children[0].tagName === "P") {
        return el.children[0].innerHTML;
    }
    return html;
};
 
const MainV2 = ({ role = "teacher" }) => {
    const {
        displayError,
        setDisplayError,
        editQuestion,
        isEditMode,
        setEditMode,
        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 { dragDropHTML, regexBlank, regexDropHere } = tinyMCEUtility();
    const theme = useTheme();
 
    // Expandable sections
    const [questionDetailsExpanded, setQuestionDetailsExpanded] = useState(false);
    const [answerDetailsExpanded, setAnswerDetailsExpanded] = useState(false);
    const [settingsExpanded, setSettingsExpanded] = useState(true);
 
    // Drag-and-drop specific state
    const [isBlanks, setBlanks] = useState([]);
    const [isChoices, setChoices] = useState([]);
    const [choiceTextEditor, setChoiceTextEditor] = useState("");
    const [showChoiceTextEditor, setShowChoiceTextEditor] = useState(false);
    const [editingChoiceIndex, setEditingChoiceIndex] = useState(null);
    // Grading order: by default each drop zone is checked against the answer
    // authored FOR that specific zone (position-sensitive — see the backend's
    // _POSITION_SENSITIVE_TYPES). This lets a teacher opt a question into
    // unordered grading instead, where a correct answer counts wherever the
    // student dropped it among the zones.
    const [isUnordered, setUnordered] = useState(false);
 
    // Question conversion (specific to drag-and-drop)
    const dragDropToString = (question) => {
        return regexDropHere ? question.replace(regexDropHere, "__blank__") : question;
    };
 
    const stringToDragDrop = (question) => {
        return regexBlank ? question.replace(regexBlank, dragDropHTML) : question;
    };
 
    // Progress calculation
    const getProgress = () => {
        let progress = 0;
        if (questionText) progress += 25;
        if (isChoices.length > 0) progress += 25;
        if (isBlanks.length > 0 && isBlanks.some((b) => b.answer)) progress += 25;
        progress += (getClassificationProgress(values) / 100) * 25;
        return Math.round(progress);
    };
 
    // Choice handlers
    const clickAddChoice = () => {
        setShowChoiceTextEditor(true);
        setChoiceTextEditor("");
        setEditingChoiceIndex(null);
        setEditMode(false);
    };
 
    const clickEditChoice = (choice, index) => {
        setShowChoiceTextEditor(true);
        setChoiceTextEditor(choice.text);
        setEditingChoiceIndex(index);
        setEditMode(true);
    };
 
    const cancelChoice = () => {
        setChoiceTextEditor("");
        setShowChoiceTextEditor(false);
        setEditingChoiceIndex(null);
        setEditMode(false);
    };
 
    const saveChoice = () => {
        if (isEditMode && editingChoiceIndex !== null) {
            setChoices((prev) =>
                prev.map((choice, idx) => (idx === editingChoiceIndex ? { ...choice, text: choiceTextEditor } : choice))
            );
        } else {
            // Derive the new id from the current max (not length) so it can't
            // collide with a surviving choice after a delete. (EI-2906)
            setChoices((prev) => {
                const nextId = prev.reduce((max, c) => Math.max(max, (c.id ?? -1) + 1), 0);
                return [...prev, { id: nextId, text: choiceTextEditor }];
            });
        }
        setChoiceTextEditor("");
        setShowChoiceTextEditor(false);
        setEditingChoiceIndex(null);
        setEditMode(false);
    };
 
    const deleteChoice = (index) => {
        const deletedText = isChoices[index].text;
        setChoices((prev) => prev.filter((_, i) => i !== index));
        setBlanks((prev) => prev.map((blank) => (blank.answer === deletedText ? { ...blank, answer: "" } : blank)));
    };
 
    // Reset all values
    const handleReset = () => {
        setQuestionText("");
        setQuestionDetailsText("");
        setAnswerDetailsText("");
        setBlanks([]);
        setChoices([]);
        setUnordered(false);
        setDisplayError({ status: false, message: "" });
        resetFields();
    };
 
    // Validation
    const hasValidChoices = () => {
        if (isChoices.length === 0) {
            setDisplayError({ status: true, message: "Please add at least one choice." });
            return false;
        }
        if (isBlanks.length === 0) {
            setDisplayError({ status: true, message: "Please add at least one blank in the question." });
            return false;
        }
        setDisplayError({ status: false, message: "" });
        return true;
    };
 
    // Submit handler - SAME PAYLOAD STRUCTURE
    const createNewQuestion = async () => {
        if (!hasValidChoices()) return;
 
        const basePayload = buildBasePayload("Drag-and-Drop", [...isBlanks]);
        const payload = {
            ...basePayload,
            question: dragDropToString(questionText),
            choices: [...isChoices],
            correctAnswer: {
                ...basePayload.correctAnswer,
                unordered: isUnordered,
            },
        };
 
        await submitQuestion(payload, () => {
            setBlanks([]);
            setChoices([]);
            setUnordered(false);
        });
    };
 
    // Dialog management
    const getActiveDialog = () => {
        if (showQuestionTextEditor)
            return {
                type: "question",
                content: questionTextEditor,
                setContent: setQuestionTextEditor,
                save: saveQuestion,
                cancel: cancelQuestion,
                questionTypes: ["dragAndDrop"],
            };
        if (showChoiceTextEditor)
            return {
                type: "choice",
                content: choiceTextEditor,
                setContent: setChoiceTextEditor,
                save: saveChoice,
                cancel: cancelChoice,
                questionTypes: [],
                disabledToolbarButtons: ["matheditor", "graph2d", "insertimage", "inserttable"],
            };
        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) => {
            setQuestionText(stringToDragDrop(data.question));
            setBlanks([...data.correctAnswer.answers]);
            setChoices([...data.choices]);
            setUnordered(Boolean(data.correctAnswer?.unordered));
        });
    }, []);
 
    return (
        <Box className="dragdrop-v2-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}
                    disabledToolbarButtons={activeDialog.disabledToolbarButtons ?? []}
                />
            )}
 
            {/* Header */}
            <Paper className="dragdrop-v2-header" elevation={0} sx={editorHeaderSx()}>
                <Box className="dragdrop-v2-header-content">
                    <Box className="dragdrop-v2-header-left">
                        <DragIndicatorIcon sx={{ fontSize: 28, color: "primary.main" }} />
                        <Box>
                            <Typography variant="h5" fontWeight={600}>
                                {editQuestion ? "Edit Question" : "Create Drag-and-Drop Question"}
                            </Typography>
                            <Typography variant="body2" color="text.secondary">
                                {editQuestion
                                    ? "Update your question details"
                                    : "Build an interactive drag-and-drop question"}
                            </Typography>
                        </Box>
                    </Box>
                    <Box className="dragdrop-v2-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" />
                                                )}
                                                Question with drop zones
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {isChoices.length > 0 ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Draggable choices added
                                            </Typography>
                                            <Typography
                                                variant="caption"
                                                sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
                                            >
                                                {isBlanks.length > 0 && isBlanks.some((b) => b.answer) ? (
                                                    <CheckCircleIcon fontSize="small" color="success" />
                                                ) : (
                                                    <CheckCircleOutlineIcon fontSize="small" />
                                                )}
                                                Correct answers placed
                                            </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="dragdrop-v2-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="dragdrop-v2-main">
                {/* Left Panel - Question & Choices */}
                <Box className="dragdrop-v2-left-panel">
                    {/* Question Card */}
                    <Card className="dragdrop-v2-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box className="dragdrop-v2-card-header">
                                <Box className="dragdrop-v2-card-title">
                                    <HelpOutlineIcon color="primary" />
                                    <Typography variant="h6">Question</Typography>
                                    {questionText && <CheckCircleIcon color="success" fontSize="small" />}
                                </Box>
                                <Button
                                    variant={questionText ? "outlined" : "contained"}
                                    size="small"
                                    startIcon={questionText ? <EditIcon /> : <AddIcon />}
                                    onClick={clickQuestionButton}
                                >
                                    {questionText ? "Edit" : "Add Question"}
                                </Button>
                            </Box>
 
                            {questionText ? (
                                <Paper
                                    variant="outlined"
                                    className="dragdrop-v2-content-preview"
                                    sx={contentPreviewSx()}
                                >
                                    <DragDropFeature
                                        isQuestionText={questionText}
                                        isChoices={isChoices}
                                        setChoices={setChoices}
                                        isBlanks={isBlanks}
                                        setBlanks={setBlanks}
                                    />
                                </Paper>
                            ) : (
                                <Box className="dragdrop-v2-empty-state" sx={emptyStateSx(theme)}>
                                    <NoteAddIcon sx={{ fontSize: 48, color: "action.disabled" }} />
                                    <Typography color="text.secondary">
                                        Click "Add Question" to write your question with drop zones
                                    </Typography>
                                    <Typography variant="caption" color="text.secondary">
                                        Use the drag-and-drop button in the editor to add drop zones
                                    </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="dragdrop-v2-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 */}
                    <Card className="dragdrop-v2-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box className="dragdrop-v2-card-header">
                                <Box className="dragdrop-v2-card-title">
                                    <DragIndicatorIcon color="primary" />
                                    <Typography variant="h6">Draggable Choices</Typography>
                                    <Chip
                                        size="small"
                                        label={`${isChoices.length} choice${isChoices.length !== 1 ? "s" : ""}`}
                                        color={isChoices.length > 0 ? "success" : "default"}
                                        variant={isChoices.length > 0 ? "filled" : "outlined"}
                                        sx={{
                                            fontWeight: 500,
                                            color: isChoices.length > 0 ? "white" : "text.primary",
                                        }}
                                    />
                                </Box>
                            </Box>
 
                            {isBlanks.length > 1 && (
                                <Box sx={{ mb: 2 }}>
                                    <FormControlLabel
                                        control={
                                            <Checkbox
                                                id="drag-and-drop-unordered-grading"
                                                data-testid="drag-and-drop-unordered-checkbox"
                                                checked={isUnordered}
                                                onChange={(e) => setUnordered(e.target.checked)}
                                            />
                                        }
                                        label="Grade drop zones unordered"
                                    />
                                    <Typography variant="caption" color="text.secondary" sx={{ display: "block" }}>
                                        {isUnordered
                                            ? "A correct answer counts in ANY drop zone, not just the one it was assigned to."
                                            : "Each drop zone is checked against the answer assigned to that specific zone."}
                                    </Typography>
                                </Box>
                            )}
 
                            {isChoices.length > 0 ? (
                                <Box className="dragdrop-v2-choices-grid">
                                    {isChoices.map((choice, index) => (
                                        <Paper
                                            key={index}
                                            className="dragdrop-v2-choice-item"
                                            variant="outlined"
                                            sx={neutralSurfaceSx(theme)}
                                        >
                                            <DragIndicatorIcon
                                                fontSize="small"
                                                sx={{ color: "grey.400", mr: 1, flexShrink: 0 }}
                                            />
                                            <Box
                                                dangerouslySetInnerHTML={{
                                                    __html: sanitizeRichText(unwrapBlock(choice.text)),
                                                }}
                                                sx={{
                                                    flex: 1,
                                                    fontSize: "1.1rem",
                                                    lineHeight: "normal",
                                                    "& p": { margin: 0, padding: 0 },
                                                    "& .mfe-formula": { color: "inherit" },
                                                }}
                                            />
                                            <Box className="dragdrop-v2-choice-actions">
                                                <IconButton size="small" onClick={() => clickEditChoice(choice, index)}>
                                                    <EditIcon fontSize="small" />
                                                </IconButton>
                                                <IconButton
                                                    size="small"
                                                    onClick={() => deleteChoice(index)}
                                                    color="error"
                                                >
                                                    <DeleteOutlineIcon fontSize="small" />
                                                </IconButton>
                                            </Box>
                                        </Paper>
                                    ))}
                                </Box>
                            ) : (
                                <Box className="dragdrop-v2-empty-state" sx={{ py: 3, ...emptyStateSx(theme) }}>
                                    <DragIndicatorIcon sx={{ fontSize: 40, color: "action.disabled" }} />
                                    <Typography color="text.secondary">No choices added yet</Typography>
                                </Box>
                            )}
 
                            <Button
                                variant="outlined"
                                startIcon={<AddIcon />}
                                onClick={clickAddChoice}
                                fullWidth
                                sx={{ mt: 2 }}
                            >
                                Add New Choice
                            </Button>
                        </CardContent>
                    </Card>
 
                    {/* Answer Details Card - Collapsible */}
                    <Card className="dragdrop-v2-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box
                                className="dragdrop-v2-card-header clickable"
                                onClick={() => setAnswerDetailsExpanded(!answerDetailsExpanded)}
                                sx={cardHeaderHoverSx(theme)}
                            >
                                <Box className="dragdrop-v2-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="dragdrop-v2-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="dragdrop-v2-right-panel">
                    <QuickTipsCard
                        className="dragdrop-v2-card dragdrop-v2-tips-card"
                        sx={{ ...editorCardSx(theme), ...tipsCardSx(theme) }}
                        tips={[
                            "Use the drag-and-drop button in the editor to add drop zones",
                            "Add choices that students can drag into the blanks",
                            "Drag choices to the correct drop zones to set answers",
                            "You can add more choices than blanks as distractors",
                        ]}
                    />
 
                    <Card className="dragdrop-v2-card dragdrop-v2-settings-card" sx={editorCardSx(theme)}>
                        <CardContent>
                            <Box
                                className="dragdrop-v2-card-header clickable"
                                onClick={() => setSettingsExpanded(!settingsExpanded)}
                                sx={cardHeaderHoverSx(theme)}
                            >
                                <Box className="dragdrop-v2-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 MainV2;