import React, { useRef, DragEvent } from "react"; import { Paper, Box, Typography, Button, Tooltip } from "@mui/material"; import { X, Info, Plus } from "lucide-react"; import { editSightStore } from "@shared"; import { toast } from "react-toastify"; interface ImageUploadCardProps { title: string; imageKey?: "thumbnail" | "watermark_lu" | "watermark_rd" | "image"; imageUrl: string | null | undefined; onImageClick: () => void; onDeleteImageClick: () => void; onSelectFileClick: () => void; setUploadMediaOpen: (open: boolean) => void; tooltipText?: string; setHardcodeType?: (type: string) => void; } export const ImageUploadCard: React.FC = ({ title, imageKey, imageUrl, onImageClick, onDeleteImageClick, onSelectFileClick, setUploadMediaOpen, setHardcodeType, tooltipText, }) => { const fileInputRef = useRef(null); const { setFileToUpload } = editSightStore; const handleZoneClick = () => { fileInputRef.current?.click(); }; const handleFileInputChange = async ( event: React.ChangeEvent ) => { const file = event.target.files?.[0]; if (file) { if (file.type.startsWith("image/") && file.type !== "image/gif") { setFileToUpload(file); setUploadMediaOpen(true); if (imageKey && setHardcodeType) { setHardcodeType(imageKey); } } else if (file.type === "image/gif") { toast.error("GIF файлы не поддерживаются"); } else { toast.error("Пожалуйста, выберите изображение"); } } event.target.value = ""; }; const token = localStorage.getItem("token"); const handleDragOver = (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); }; const handleDragLeave = (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); }; const handleDrop = async (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); const files = event.dataTransfer.files; if (files && files.length > 0) { const file = files[0]; if (file.type.startsWith("image/") && file.type !== "image/gif") { setFileToUpload(file); setUploadMediaOpen(true); } else if (file.type === "image/gif") { toast.error("GIF файлы не поддерживаются"); } else { toast.error("Пожалуйста, выберите изображение"); } } }; return ( {title} {tooltipText && ( )} {imageUrl && ( )} {imageUrl ? ( {title} ) : (

Перетащите файл

или

{/* Hidden file input */}
)}
); };