diff --git a/src/components/virtualTryOn/VirtualTryOnUpload.tsx b/src/components/virtualTryOn/VirtualTryOnUpload.tsx new file mode 100644 index 0000000..68b01cf --- /dev/null +++ b/src/components/virtualTryOn/VirtualTryOnUpload.tsx @@ -0,0 +1,136 @@ +"use client"; + +import { useState, useRef } from "react"; +import { Upload, X } from "lucide-react"; + +interface VirtualTryOnUploadProps { + title: string; + description: string; + onPhotoUpload: (photo: string) => void; + uploadType: "user" | "clothes"; +} + +export default function VirtualTryOnUpload({ + title, + description, + onPhotoUpload, + uploadType, +}: VirtualTryOnUploadProps) { + const [preview, setPreview] = useState(null); + const [isDragging, setIsDragging] = useState(false); + const fileInputRef = useRef(null); + + const handleFileSelect = (file: File) => { + if (file && file.type.startsWith("image/")) { + const reader = new FileReader(); + reader.onload = (e) => { + const result = e.target?.result as string; + setPreview(result); + onPhotoUpload(result); + }; + reader.readAsDataURL(file); + } + }; + + const handleDragOver = (e: React.DragEvent) => { + e.preventDefault(); + setIsDragging(true); + }; + + const handleDragLeave = () => { + setIsDragging(false); + }; + + const handleDrop = (e: React.DragEvent) => { + e.preventDefault(); + setIsDragging(false); + const files = e.dataTransfer.files; + if (files && files[0]) { + handleFileSelect(files[0]); + } + }; + + const handleFileInputChange = (e: React.ChangeEvent) => { + const files = e.target.files; + if (files && files[0]) { + handleFileSelect(files[0]); + } + }; + + const handleRemovePhoto = () => { + setPreview(null); + }; + + const handleClick = () => { + fileInputRef.current?.click(); + }; + + return ( +
+
+

+ {title} +

+

{description}

+
+ + {!preview ? ( +
+ +
+ +

+ {isDragging ? "Drop your photo here" : "Drag & drop or click to upload"} +

+

PNG, JPG, GIF up to 10MB

+
+
+ ) : ( +
+ {`${uploadType} + +
+
+
+
+ Processing... +
+
+ )} + +
+

+ Pro tip: For best results, ensure good + lighting, wear fitted clothes, and stand in a neutral pose. +

+
+
+ ); +} \ No newline at end of file