"use client"; import { AnimatePresence, motion } from "framer-motion"; import { FileUp } from "lucide-react"; import type { ReactNode } from "react"; import { toast } from "sonner"; import { IMAGE_EXTENSIONS } from "@/lib/constants"; const getFileType = (file: File): "ics" | "image" | null => { const name = file.name.toLowerCase(); if (name.endsWith(".ics")) return "ics"; if (IMAGE_EXTENSIONS.some((ext) => name.endsWith(ext))) return "image"; return null; }; interface DragDropContainerProps { children: ReactNode; isDragOver: boolean; setIsDragOver: (isDragOver: boolean) => void; onImport: (file: File) => void; onImageDrop?: (file: File) => void; } export const DragDropContainer = ({ children, isDragOver, setIsDragOver, onImport, onImageDrop, }: DragDropContainerProps) => { const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); setIsDragOver(true); }; const handleDragLeave = (e: React.DragEvent) => { e.preventDefault(); setIsDragOver(false); }; const handleDrop = (e: React.DragEvent) => { e.preventDefault(); setIsDragOver(false); if (e.dataTransfer.files?.length) { const file = e.dataTransfer.files[0]; const fileType = getFileType(file); if (fileType === "ics") { onImport(file); } else if (fileType === "image" && onImageDrop) { onImageDrop(file); } else { toast.warning("Drop an .ics file or an event screenshot"); } } }; return (
{isDragOver && (
Drop .ics or image here
)}
{children}

Drag & drop .ics files or event screenshots

); };