/* eslint-disable @next/next/no-img-element -- Local preview data URLs; next/image migration is out of scope. */ import { useState } from 'react'; import { Modal, Input, Button } from './ui'; export default function UploadImageModal({ isOpen, onClose, onUpload, currentImage }) { const [uploadMethod, setUploadMethod] = useState('url'); const [imageUrl, setImageUrl] = useState(currentImage || ''); const [dragActive, setDragActive] = useState(false); const [uploading, setUploading] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); if (!imageUrl.trim()) return; setUploading(true); try { await onUpload(imageUrl); onClose(); } catch (error) { console.error('Upload failed:', error); } finally { setUploading(false); } }; const handleDrag = (e) => { e.preventDefault(); e.stopPropagation(); if (e.type === 'dragenter' || e.type === 'dragover') { setDragActive(true); } else if (e.type === 'dragleave') { setDragActive(false); } }; const handleDrop = (e) => { e.preventDefault(); e.stopPropagation(); setDragActive(false); if (e.dataTransfer.files && e.dataTransfer.files[0]) { handleFileUpload(e.dataTransfer.files[0]); } }; const handleFileUpload = (file) => { if (file.type.startsWith('image/')) { const reader = new FileReader(); reader.onload = (event) => { setImageUrl(event.target.result); setUploadMethod('file'); }; reader.readAsDataURL(file); } }; const handleFileInput = (e) => { if (e.target.files && e.target.files[0]) { handleFileUpload(e.target.files[0]); } }; return (
{uploadMethod === 'url' ? (
setImageUrl(e.target.value)} placeholder="https://example.com/image.jpg" />
) : (

Drag and drop an image here, or

PNG, JPG, GIF up to 10MB

)} {imageUrl && (
Preview { e.target.src = 'https://via.placeholder.com/400x128/f3f4f6/6b7280?text=Invalid+Image'; }} />
)}
); }