import { useState, useEffect } from 'react'; import { useStore } from '../store'; import { motion, AnimatePresence } from 'framer-motion'; import { X, MessageSquare, User } from 'lucide-react'; export function InboxOverlay() { const { currentUser, showInbox, toggleInbox, startChat } = useStore(); const [inbox, setInbox] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { if (!showInbox || !currentUser) return; const fetchInbox = async () => { setLoading(true); try { const res = await fetch(`/api/messages/inbox/${currentUser.id}`); const data = await res.json(); setInbox(data || []); } catch (error) { console.error(error); } finally { setLoading(false); } }; fetchInbox(); }, [showInbox, currentUser]); if (!showInbox) return null; return (
e.stopPropagation()} > {/* Header */}

Your Messages

{/* List */}
{loading ? (

Loading messages...

) : inbox.length === 0 ? (

No messages yet.

Conversations with buyers or sellers will appear here.

) : (
{inbox.map(chat => ( ))}
)}
); }