"use client"; import { useEffect, useState } from "react"; import { FileText, BookOpen, PenTool, ClipboardList, Library, GraduationCap, Sparkles } from "lucide-react"; import { Modal, PrimaryButton, SecondaryButton } from "@/components/dashboard/dashboardPrimitives"; import { reclassifyDocument } from "@/lib/api/documents"; import { normalizeApiError } from "@/lib/api/client"; import { cn } from "@/lib/utils"; const MATERIAL_TYPE_OPTIONS = [ { value: "notes", label: "Notes", icon: FileText, description: "Typed class notes or study notes" }, { value: "chapter", label: "Chapter PDF", icon: BookOpen, description: "Textbook chapter, reference material" }, { value: "textbook", label: "Textbook", icon: Library, description: "Full textbook or reference book" }, { value: "handwritten_notes", label: "Digitized Notes", icon: PenTool, description: "Handwritten notes already converted to readable text" }, { value: "question_paper", label: "Question Paper", icon: ClipboardList, description: "Single exam or test paper" }, { value: "syllabus", label: "Syllabus", icon: GraduationCap, description: "Course syllabus or curriculum" }, ] as const; type MaterialType = typeof MATERIAL_TYPE_OPTIONS[number]["value"]; type SourceClassificationModalProps = { isOpen: boolean; onClose: () => void; documentId: string; documentTitle: string; currentMaterialType?: string | null; onClassificationComplete: (materialType: string) => void; autoDetectedType?: string | null; }; export function SourceClassificationModal({ isOpen, onClose, documentId, documentTitle, currentMaterialType, onClassificationComplete, autoDetectedType, }: SourceClassificationModalProps) { const [selectedType, setSelectedType] = useState( (currentMaterialType || autoDetectedType || null) as MaterialType | null ); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!isOpen) return; const timeoutId = window.setTimeout(() => { setSelectedType((currentMaterialType || autoDetectedType || null) as MaterialType | null); setError(null); }, 0); return () => window.clearTimeout(timeoutId); }, [autoDetectedType, currentMaterialType, isOpen]); async function handleSave() { if (!selectedType) { setError("Please select a material type"); return; } setIsSaving(true); setError(null); try { await reclassifyDocument(documentId, selectedType); onClassificationComplete(selectedType); onClose(); } catch (err) { setError(normalizeApiError(err)); } finally { setIsSaving(false); } } function handleSkip() { // If auto-detected type exists, use it; otherwise use current or default to unknown const typeToUse = selectedType || autoDetectedType || currentMaterialType || "unknown"; onClassificationComplete(typeToUse); onClose(); } return (

Classifying “{documentTitle}” helps DocDoe provide better study tools.

{autoDetectedType && !currentMaterialType && (

Auto-detected as: {autoDetectedType.replace(/_/g, " ")}

Confirm or select a different type below.

)}
{MATERIAL_TYPE_OPTIONS.map((option) => { const Icon = option.icon; const isSelected = selectedType === option.value; const isAutoDetected = autoDetectedType === option.value && !currentMaterialType; return ( ); })}
{error && (

{error}

)}
Skip for Now {isSaving ? "Saving..." : selectedType ? "Confirm" : "Select Type"}

You can change this later from the source card

); }