"use client" import { useState, useEffect } from "react" import { cn } from "@lib/utils" import { dmSansClassName } from "@/lib/fonts" import { FileIcon } from "lucide-react" import { useHotkeys } from "react-hotkeys-hook" export interface FileData { file: File | null title: string description: string } interface FileContentProps { onSubmit?: (data: { file: File; title: string; description: string }) => void onDataChange?: (data: FileData) => void isSubmitting?: boolean isOpen?: boolean } export function FileContent({ onSubmit, onDataChange, isSubmitting, isOpen, }: FileContentProps) { const [isDragging, setIsDragging] = useState(false) const [selectedFile, setSelectedFile] = useState(null) const [title, setTitle] = useState("") const [description, setDescription] = useState("") const canSubmit = selectedFile !== null && !isSubmitting const handleSubmit = () => { if (canSubmit && onSubmit && selectedFile) { onSubmit({ file: selectedFile, title, description }) } } const updateData = ( newFile: File | null, newTitle: string, newDescription: string, ) => { onDataChange?.({ file: newFile, title: newTitle, description: newDescription, }) } const handleFileChange = (file: File | null) => { setSelectedFile(file) updateData(file, title, description) } const handleTitleChange = (newTitle: string) => { setTitle(newTitle) updateData(selectedFile, newTitle, description) } const handleDescriptionChange = (newDescription: string) => { setDescription(newDescription) updateData(selectedFile, title, newDescription) } useHotkeys("mod+enter", handleSubmit, { enabled: isOpen && canSubmit, enableOnFormTags: ["INPUT", "TEXTAREA"], }) // Reset content when modal closes useEffect(() => { if (!isOpen) { setSelectedFile(null) setTitle("") setDescription("") onDataChange?.({ file: null, title: "", description: "" }) } }, [isOpen, onDataChange]) const handleDragOver = (e: React.DragEvent) => { e.preventDefault() setIsDragging(true) } const handleDragLeave = (e: React.DragEvent) => { e.preventDefault() setIsDragging(false) } const handleDrop = (e: React.DragEvent) => { e.preventDefault() setIsDragging(false) const file = e.dataTransfer.files[0] if (file) { handleFileChange(file) } } const handleFileSelect = (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (file) { handleFileChange(file) } } return (

Upload a file (image, pdf, document, sheet)

Title (optional)

handleTitleChange(e.target.value)} placeholder="Give this file a title" disabled={isSubmitting} className="w-full p-4 rounded-[14px] bg-[#14161A] shadow-inside-out disabled:opacity-50" />

Description (optional)