import React, { useState } from 'react'; import { FileText, Image as ImageIcon, Download, Trash2, Eye, User as UserIcon, Calendar, X, FileSpreadsheet, AlertCircle, ZoomIn, } from 'lucide-react'; import { NoteItem, User } from '../types'; interface NotesViewProps { notes: NoteItem[]; currentUser: User; onDeleteNote: (noteId: string) => Promise; searchQuery: string; } export const NotesView: React.FC = ({ notes, currentUser, onDeleteNote, searchQuery, }) => { const [selectedImage, setSelectedImage] = useState(null); const [deletingId, setDeletingId] = useState(null); const canDelete = (note: NoteItem) => { const isOwner = note.uploadedBy.toLowerCase() === currentUser.username.toLowerCase(); const isAdmin = currentUser.role === 'admin'; const hasSpecialPerm = currentUser.permissions?.canEditDeleteOthers && (currentUser.permissions.allowedGroups?.includes('ALL') || currentUser.permissions.allowedGroups ?.map((g) => g.toLowerCase()) .includes(note.subject.toLowerCase())); return isOwner || isAdmin || hasSpecialPerm; }; const handleDelete = async (noteId: string) => { if (!window.confirm('Are you sure you want to delete this archived note?')) return; setDeletingId(noteId); try { await onDeleteNote(noteId); } finally { setDeletingId(null); } }; const formatSize = (bytes: number) => { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; }; return (
{/* Header Info */}

Archived Documents {searchQuery ? `(Search: "${searchQuery}")` : ''} ({notes.length})

{/* Grid of Notes */} {notes.length === 0 ? (

No notes found

{searchQuery ? `No archived materials matched your search query "${searchQuery}".` : 'There are no notes uploaded in this subject folder yet. Click "Upload Notes" to add materials.'}

) : (
{notes.map((note) => { const isImg = note.fileType === 'image'; const userCanDelete = canDelete(note); return (
{/* File Thumbnail / Preview Header */}
{isImg ? (
setSelectedImage(note)} > {note.originalName}
Preview Image
) : (
DOCX Document {formatSize(note.size)}
)} {/* Subject Tag Badge */}
{note.subject} {note.subSubject && ( {note.subSubject} )}
{/* Body Details */}

{note.originalName}

{note.description && (

{note.description}

)}
{/* Upload Metadata: Uploader + Timestamp */}
Uploaded by: {note.uploadedBy}
{new Date(note.uploadedAt).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', })}
{/* Action Buttons */}
Download {userCanDelete && ( )}
); })}
)} {/* Image Lightbox Modal */} {selectedImage && (

{selectedImage.originalName}

Uploaded by {selectedImage.uploadedBy} in {selectedImage.subject}

{selectedImage.originalName}
)}
); };