import Link from 'next/link'; import { DragEvent, useState } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@headlessui/react'; import { PDFIcon, EPUBIcon, FileIcon } from '@/components/icons/Icons'; import { DocumentListDocument } from '@/types/documents'; import { DocumentPreview } from '@/components/doclist/DocumentPreview'; interface DocumentListItemProps { doc: DocumentListDocument; onDelete: (doc: DocumentListDocument) => void; dragEnabled?: boolean; onDragStart?: (doc: DocumentListDocument) => void; onDragEnd?: () => void; onDragOver?: (e: DragEvent, doc: DocumentListDocument) => void; onDragLeave?: () => void; onDrop?: (e: DragEvent, doc: DocumentListDocument) => void; isDropTarget?: boolean; viewMode: 'list' | 'grid'; } export function DocumentListItem({ doc, onDelete, dragEnabled = true, onDragStart, onDragEnd, onDragOver, onDragLeave, onDrop, isDropTarget = false, viewMode, }: DocumentListItemProps) { const [loading, setLoading] = useState(false); const router = useRouter(); // Only allow drag and drop interactions for documents not in folders const isDraggable = dragEnabled && !doc.folderId; const allowDropTarget = !doc.folderId; const handleDocumentClick = (e: React.MouseEvent) => { e.preventDefault(); setLoading(true); router.push(`/${doc.type}/${encodeURIComponent(doc.id)}`); }; return (
onDragStart?.(doc)} onDragEnd={onDragEnd} onDragOver={(e) => allowDropTarget && onDragOver?.(e, doc)} onDragLeave={() => allowDropTarget && onDragLeave?.()} onDrop={(e) => allowDropTarget && onDrop?.(e, doc)} aria-busy={loading} className={ viewMode === 'grid' ? ` flex w-full min-w-0 flex-col group border border-offbase rounded-md overflow-hidden transition-colors duration-150 relative bg-base hover:bg-offbase ${allowDropTarget && isDropTarget ? 'ring-2 ring-accent' : ''} ${loading ? 'prism-outline' : ''} ` : ` w-full group ${allowDropTarget && isDropTarget ? 'ring-2 ring-accent' : ''} ${loading ? 'prism-outline' : 'bg-base hover:bg-offbase'} border border-offbase rounded-md p-1 transition-colors duration-150 relative ` } > {viewMode === 'grid' ? ( <>
{doc.type === 'pdf' ? ( ) : doc.type === 'epub' ? ( ) : ( )}

{doc.name}

{(doc.size / 1024 / 1024).toFixed(2)} MB

) : (
{doc.type === 'pdf' ? ( ) : doc.type === 'epub' ? ( ) : ( )}

{doc.name}

{(doc.size / 1024 / 1024).toFixed(2)} MB

)}
); }