'use client' /* eslint-disable @next/next/no-img-element */ import { useState, useRef } from 'react' import { Image as ImageIcon, Upload, X } from 'lucide-react' interface ImageUploadProps { selectedImage: File | null onImageSelect: (file: File | null) => void onClear: () => void /** Override default upload prompt (e.g. "Past photo") */ title?: string hint?: string } export default function ImageUpload({ selectedImage, onImageSelect, onClear, title = 'Add a crop photo', hint = 'Use a close, well-lit photo of the leaf or damaged area.', }: ImageUploadProps) { const [dragActive, setDragActive] = useState(false) const fileInputRef = useRef(null) const cameraInputRef = useRef(null) const handleDrag = (e: React.DragEvent) => { e.preventDefault() e.stopPropagation() if (e.type === 'dragenter' || e.type === 'dragover') { setDragActive(true) } else if (e.type === 'dragleave') { setDragActive(false) } } const handleDrop = (e: React.DragEvent) => { e.preventDefault() e.stopPropagation() setDragActive(false) if (e.dataTransfer.files && e.dataTransfer.files[0]) { handleFile(e.dataTransfer.files[0]) } } const handleFileInput = (e: React.ChangeEvent) => { if (e.target.files && e.target.files[0]) { handleFile(e.target.files[0]) } } const handleFile = (file: File) => { if (file.type.startsWith('image/')) { onImageSelect(file) } } const imageUrl = selectedImage ? URL.createObjectURL(selectedImage) : null return (
{!imageUrl ? (

{title}

{hint}

) : (
Crop image preview { console.error('Image failed to load:', imageUrl) e.currentTarget.style.display = 'none' }} />
)}
) }