import React, { useRef, useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
const ImageUpload = ({
selectedItem,
setSelectedItem,
items,
onImageSelect,
imagePreview,
onAnalyze,
onReset,
loading,
hasImage
}) => {
const fileInputRef = useRef(null);
const cameraInputRef = useRef(null);
const [dragActive, setDragActive] = useState(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]) {
onImageSelect(e.dataTransfer.files[0]);
}
};
const handleFileChange = (e) => {
if (e.target.files && e.target.files[0]) {
onImageSelect(e.target.files[0]);
}
};
return (
{/* Header */}
Upload & Analyze
{/*
Select your produce for analysis
*/}
{/* Dropdown */}
{/* Upload Area */}
{/* Action Buttons - FIXED */}
{/* Mobile: 2 buttons (Upload + Camera) */}
fileInputRef.current?.click()}
className="flex items-center justify-center gap-2 px-4 py-3 rounded-xl bg-dark-700/50 hover:bg-dark-700 border border-dark-600 text-white transition-all duration-200"
>
Upload
cameraInputRef.current?.click()}
className="flex items-center justify-center gap-2 px-4 py-3 rounded-xl bg-dark-700/50 hover:bg-dark-700 border border-dark-600 text-white transition-all duration-200"
>
Camera
{/* Desktop: 1 button (Full width) */}
fileInputRef.current?.click()}
className="hidden lg:flex w-full items-center justify-center gap-2 px-4 py-3 rounded-xl bg-dark-700/50 hover:bg-dark-700 border border-dark-600 text-white transition-all duration-200"
>
Browse & Upload Image
{/* Analyze Button */}
{loading ? (
<>
Analyzing...
>
) : (
<>
Analyze Freshness
>
)}
);
};
export default ImageUpload;