import React, { useState, useEffect } from 'react'; import { Comment, Notification, User } from '../types'; import { MessageSquare, Bell, Send, CheckCircle2, User as UserIcon, Clock, Trash2 } from 'lucide-react'; import { useLocalCollection } from '../hooks/useLocalCollection'; interface CollaborationProps { projectId: string; targetId: string; targetType: 'DOCUMENT' | 'TASK'; currentUser: User; } export const CommentSection: React.FC = ({ projectId, targetId, targetType, currentUser }) => { const { data: allComments, add: addComment, remove: removeComment } = useLocalCollection(`comments_${projectId}`); const [newComment, setNewComment] = useState(''); const [isLoading, setIsLoading] = useState(false); // Derive sorted & filtered comments const comments = allComments .filter(c => c.targetId === targetId && c.targetType === targetType) .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!newComment.trim() || !currentUser) return; setIsLoading(true); const commentId = `COMM-${Date.now()}`; const commentData: Comment & { id: string } = { id: commentId, targetId, targetType, authorUid: currentUser.uid, authorName: currentUser.name, text: newComment.trim(), createdAt: new Date().toISOString() }; await addComment(commentData); setNewComment(''); setIsLoading(false); }; const handleDelete = async (commentId: string) => { await removeComment(commentId); }; return (

Discussion

{comments.length}
{comments.length > 0 ? ( comments.map((comment) => (
{comment.authorName.charAt(0)}

{comment.authorName}

{new Date(comment.createdAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}

{currentUser?.uid === comment.authorUid && ( )}

{comment.text}

)) ) : (

No comments yet. Start the conversation!

)}
setNewComment(e.target.value)} disabled={isLoading} className="w-full pl-4 pr-12 py-2.5 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none text-sm transition-all" />
); }; export const NotificationCenter: React.FC<{ uid: string }> = ({ uid }) => { const { data: notifications, update: updateNotif } = useLocalCollection(`notifications_${uid}`); const [isOpen, setIsOpen] = useState(false); const markAsRead = async (id: string) => { updateNotif(id, { isRead: true }); }; const unreadCount = notifications.filter(n => !n.isRead).length; return (
{isOpen && ( <>
setIsOpen(false)} />

Notifications

{unreadCount > 0 && ( {unreadCount} New )}
{notifications.length > 0 ? ( notifications.map((n) => (
markAsRead(n.id)} className={`p-4 border-b border-slate-50 hover:bg-slate-50 transition-all cursor-pointer flex gap-3 ${!n.isRead ? 'bg-blue-50/30' : ''}`} >
{n.type === 'TASK_ASSIGNED' ? : n.type === 'TASK_COMPLETED' ? : n.type === 'DOC_UPLOADED' ? : }

{n.title}

{n.message}

{new Date(n.createdAt).toLocaleDateString()}

{!n.isRead &&
}
)) ) : (

All caught up!

)}
)}
); };