import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { X, Plus, Trash2, Triangle, Diamond, Circle, Square, Clock } from 'lucide-react'; import { Question, AnswerOption } from '../types'; import { useBodyScrollLock } from '../hooks/useBodyScrollLock'; interface QuestionEditModalProps { question: Question; onSave: (question: Question) => void; onClose: () => void; } const ShapeIcon: React.FC<{ shape: string; className?: string; size?: number }> = ({ shape, className, size = 20 }) => { const props = { size, className }; switch (shape) { case 'triangle': return ; case 'diamond': return ; case 'circle': return ; case 'square': return ; default: return ; } }; const colorMap: Record = { red: 'bg-red-500 border-red-500', blue: 'bg-blue-500 border-blue-500', yellow: 'bg-yellow-500 border-yellow-500', green: 'bg-green-500 border-green-500' }; const shapes = ['triangle', 'diamond', 'circle', 'square'] as const; const colors = ['red', 'blue', 'yellow', 'green'] as const; export const QuestionEditModal: React.FC = ({ question, onSave, onClose }) => { const [text, setText] = useState(question.text); const [options, setOptions] = useState(question.options); const [timeLimit, setTimeLimit] = useState(question.timeLimit); useBodyScrollLock(true); const handleOptionTextChange = (index: number, newText: string) => { setOptions(prev => prev.map((opt, i) => i === index ? { ...opt, text: newText } : opt )); }; const handleReasonChange = (index: number, reason: string) => { setOptions(prev => prev.map((opt, i) => i === index ? { ...opt, reason } : opt )); }; const handleCorrectChange = (index: number) => { setOptions(prev => prev.map((opt, i) => ({ ...opt, isCorrect: i === index }))); }; const handleDeleteOption = (index: number) => { if (options.length <= 2) return; const deletedWasCorrect = options[index].isCorrect; const newOptions = options.filter((_, i) => i !== index); if (deletedWasCorrect && newOptions.length > 0) { newOptions[0].isCorrect = true; } setOptions(newOptions.map((opt, i) => ({ ...opt, shape: shapes[i % 4], color: colors[i % 4] }))); }; const handleAddOption = () => { if (options.length >= 6) return; const newIndex = options.length; setOptions(prev => [...prev, { text: '', isCorrect: false, shape: shapes[newIndex % 4], color: colors[newIndex % 4], reason: '' }]); }; const handleSave = () => { if (!text.trim()) return; if (options.some(o => !o.text.trim())) return; if (!options.some(o => o.isCorrect)) return; onSave({ ...question, text: text.trim(), options, timeLimit }); }; const isValid = text.trim() && options.every(o => o.text.trim()) && options.some(o => o.isCorrect) && options.length >= 2; return ( e.stopPropagation()} >

Edit Question