import { useState } from "react"; import { Upload, X, Check, FileText, AlertCircle } from "lucide-react"; const SYMBOLS = { annual_report: { icon: FileText, color: "#f97316" }, gst_3b: { icon: FileText, color: "#22c55e" }, gst_2a: { icon: FileText, color: "#10b981" }, gst_1: { icon: FileText, color: "#34d399" }, gst_filing: { icon: FileText, color: "#22c55e" }, bank_statement: { icon: FileText, color: "#3b82f6" }, itr: { icon: FileText, color: "#eab308" }, mca: { icon: FileText, color: "#8b5cf6" }, }; function formatSize(bytes) { if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB"; return (bytes / (1024 * 1024)).toFixed(1) + " MB"; } function truncate(str, max) { return str.length <= max ? str : str.slice(0, max) + "…"; } export default function FileDropZone({ fileType, label, description, acceptedFormats, required, file, onFileSelect, }) { const [isDragging, setIsDragging] = useState(false); const [extError, setExtError] = useState(null); const exts = acceptedFormats.split(",").map((e) => e.trim().toLowerCase()); function validate(f) { const name = f.name.toLowerCase(); return exts.some((ext) => name.endsWith(ext)); } function handleDragOver(e) { e.preventDefault(); setIsDragging(true); } function handleDragLeave() { setIsDragging(false); } function handleDrop(e) { e.preventDefault(); setIsDragging(false); const dropped = e.dataTransfer.files[0]; if (!dropped) return; if (!validate(dropped)) { setExtError(`Invalid file. Accepted: ${acceptedFormats}`); return; } setExtError(null); onFileSelect(dropped); } function handleInputChange(e) { const picked = e.target.files[0]; if (!picked) return; if (!validate(picked)) { setExtError(`Invalid file. Accepted: ${acceptedFormats}`); return; } setExtError(null); onFileSelect(picked); e.target.value = ""; } function openPicker() { document.getElementById("file-input-" + fileType).click(); } const { icon: Icon, color } = SYMBOLS[fileType] || { icon: FileText, color: "#7a7a85", }; const zoneClass = isDragging ? "dropzone dragging" : file ? "dropzone uploaded" : "dropzone"; return (
{file ? (

{file.name}

{formatSize(file.size)}

) : (

{label}

{description}

{acceptedFormats}

{required ? "Required" : "Optional"}
)}
{extError && (

{extError}

)}
); }