import React, { useCallback, useState } from 'react'; import { Icons } from '../constants'; interface FileUploadProps { onFileSelect: (file: File) => void; disabled: boolean; } const FileUpload: React.FC = ({ onFileSelect, disabled }) => { const [isDragging, setIsDragging] = useState(false); const handleDragOver = useCallback((e: React.DragEvent) => { e.preventDefault(); if (!disabled) setIsDragging(true); }, [disabled]); const handleDragLeave = useCallback((e: React.DragEvent) => { e.preventDefault(); if (!disabled) setIsDragging(false); }, [disabled]); const handleDrop = useCallback((e: React.DragEvent) => { e.preventDefault(); if (disabled) return; setIsDragging(false); const files = e.dataTransfer.files; if (files.length > 0) { const file = files[0]; if (validateFile(file)) { onFileSelect(file); } } }, [disabled, onFileSelect]); const handleFileInput = (e: React.ChangeEvent) => { if (disabled || !e.target.files) return; const file = e.target.files[0]; if (file && validateFile(file)) { onFileSelect(file); } }; const validateFile = (file: File) => { const validTypes = ['application/pdf', 'image/jpeg', 'image/png', 'image/webp']; // For browser based base64, we limit to ~20MB strictly to prevent browser crash. // In a real app with File API, this could be 2GB. const maxSize = 50 * 1024 * 1024; if (!validTypes.includes(file.type)) { alert("Invalid file type. Please upload PDF, JPEG, PNG, or WEBP."); return false; } if (file.size > maxSize) { alert("File too large (Max 50MB)."); return false; } return true; }; return (
!disabled && document.getElementById('fileInput')?.click()} >

Upload Document

Drag & drop or click to select Oil & Gas reports, drilling logs, or production data.

Supported: PDF, JPG, PNG (Max 50MB)

); }; export default FileUpload;