'use client'; import { useState } from 'react'; import { GeneratedQuestion, QuestionType } from '@/types/quiz'; import QuestionCard from './QuestionCard'; import { exportQuestionsToDocx } from '@/lib/exportUtils'; import { Button } from '@/components/ui/button'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Checkbox } from '@/components/ui/checkbox'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; export interface QuestionListProps { questions: GeneratedQuestion[]; questionTypes: QuestionType[]; selectedQuestions?: Set; onQuestionSelect?: (questionId: string, selected: boolean) => void; onQuestionEdit?: (question: GeneratedQuestion) => void; onQuestionDuplicate?: (question: GeneratedQuestion) => void; onQuestionPreview?: (question: GeneratedQuestion) => void; onQuestionRemove?: (questionId: string) => void; onQuestionReorder?: (questions: GeneratedQuestion[]) => void; editingQuestionId?: string | null; emptyStateMessage?: string; emptyStateIcon?: string; className?: string; title?: string; showCount?: boolean; } export default function QuestionList({ questions, questionTypes, selectedQuestions = new Set(), onQuestionSelect, onQuestionEdit, onQuestionDuplicate, onQuestionPreview, onQuestionRemove, onQuestionReorder, editingQuestionId = null, emptyStateMessage = "No questions yet. Start by creating your first question!", emptyStateIcon = "📝", className = '', title = "Question List", showCount = true, }: QuestionListProps) { const [draggedId, setDraggedId] = useState(null); const [isExporting, setIsExporting] = useState(false); const [includeAnswers, setIncludeAnswers] = useState(true); const [exportFormat, setExportFormat] = useState<'docx' | 'txt'>('docx'); const handleSelectAll = () => { if (onQuestionSelect) { const allSelected = questions.length > 0 && questions.every(q => selectedQuestions.has(q.id)); questions.forEach(question => { onQuestionSelect(question.id, !allSelected); }); } }; const handleDragStart = (questionId: string) => { setDraggedId(questionId); }; const handleDragEnd = () => { setDraggedId(null); }; const handleDrop = (targetId: string) => { if (!draggedId || !onQuestionReorder || draggedId === targetId) return; const newQuestions = [...questions]; const draggedIndex = newQuestions.findIndex(q => q.id === draggedId); const targetIndex = newQuestions.findIndex(q => q.id === targetId); if (draggedIndex !== -1 && targetIndex !== -1) { // Remove the dragged item and insert it at the target position const [draggedItem] = newQuestions.splice(draggedIndex, 1); newQuestions.splice(targetIndex, 0, draggedItem); onQuestionReorder(newQuestions); } }; const allSelected = questions.length > 0 && questions.every(q => selectedQuestions.has(q.id)); const someSelected = questions.some(q => selectedQuestions.has(q.id)); return (
🗂️ {title} {showCount && `(${questions.length})`} {/* Export and Bulk Actions */} {questions.length > 0 && (
{/* Export Options */}
{/* Format Selector */} {/* Include Answers Toggle */}
setIncludeAnswers(checked as boolean)} />
{/* Export Button */}
{/* Bulk Actions */} {onQuestionSelect && (
{someSelected && ( {selectedQuestions.size} selected )}
)}
)}
{/* Content */} {questions.length === 0 ? ( ) : (
{questions.map((question) => ( ))}
)}
); } // Empty State Component interface EmptyStateProps { message: string; icon: string; } function EmptyState({ message, icon }: EmptyStateProps) { return (
{icon}

{message}

); }