import { useState, useCallback, useRef } from 'react' import { Upload, FileText, ClipboardPaste, FileUp, Sparkles, AlertCircle } from 'lucide-react' import { cn } from '@/lib/utils' import { Textarea } from '@/components/ui/Textarea' import { Input } from '@/components/ui/Input' import type { KBQuotaResponse } from '@/types/kbAccelerator' type TargetType = 'troubleshooting' | 'procedural' interface UploadScreenProps { quota: KBQuotaResponse | null onSubmitText: (content: string, title: string, targetType: TargetType) => void onSubmitFile: (file: File, targetType: TargetType) => void loading: boolean } const TARGET_TYPES = [ { value: 'troubleshooting' as const, label: 'Troubleshooting Flow', description: 'Decision tree with diagnostic questions and resolutions', }, { value: 'procedural' as const, label: 'Project Flow', description: 'Step-by-step procedure with warnings and variables', }, ] const FORMAT_LABELS: Record = { txt: 'TXT', paste: 'Paste', docx: 'DOCX', pdf: 'PDF', html: 'HTML', md: 'Markdown', } export function UploadScreen({ quota, onSubmitText, onSubmitFile, loading }: UploadScreenProps) { const [mode, setMode] = useState<'paste' | 'file'>('paste') const [content, setContent] = useState('') const [title, setTitle] = useState('') const [targetType, setTargetType] = useState('troubleshooting') const [file, setFile] = useState(null) const [dragOver, setDragOver] = useState(false) const fileInputRef = useRef(null) const canSubmit = mode === 'paste' ? content.trim().length >= 10 : file !== null const handleSubmit = () => { if (loading) return if (mode === 'paste') { onSubmitText(content, title, targetType) } else if (file) { onSubmitFile(file, targetType) } } const handleDrop = useCallback((e: React.DragEvent) => { e.preventDefault() setDragOver(false) const droppedFile = e.dataTransfer.files[0] if (droppedFile) { setFile(droppedFile) setMode('file') } }, []) const handleFileSelect = (e: React.ChangeEvent) => { const selected = e.target.files?.[0] if (selected) { setFile(selected) } } const allowedFormats = quota?.allowed_formats ?? ['txt', 'paste'] const fileFormats = allowedFormats.filter(f => f !== 'paste') return (
{/* Quota info */} {quota && (

{quota.lifetime_conversions_limit ? `${quota.lifetime_conversions_limit - quota.lifetime_conversions_used} conversions remaining` : 'Unlimited conversions'}

{quota.plan.charAt(0).toUpperCase() + quota.plan.slice(1)} plan

{!quota.can_convert && (
Conversion limit reached
)}
)} {/* Mode toggle */}
{fileFormats.length > 0 && ( )}
{/* Content area */}
{mode === 'paste' ? ( <>
setTitle(e.target.value)} placeholder="e.g., Outlook Connectivity Troubleshooting" maxLength={255} />