"use client"; import { useEffect, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw, Mail } from "lucide-react"; import { useSession } from "next-auth/react"; interface Email { id: string; subject: string; sender: { name: string; email: string; }; date: string; isUnread: boolean; } export function Email() { const [emails, setEmails] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [refreshing, setRefreshing] = useState(false); const { status } = useSession(); const fetchEmails = async (isRefresh = false) => { if (isRefresh) setRefreshing(true); setLoading(true); // Placeholder data - replace with actual API call const mockEmails = [ { id: '1', subject: 'Project Update: Q1 Milestones', sender: { name: 'Project Manager', email: 'pm@example.com' }, date: '2024-03-20 09:30', isUnread: true }, { id: '2', subject: 'Team Meeting Notes', sender: { name: 'Team Lead', email: 'lead@example.com' }, date: '2024-03-19 15:45', isUnread: false }, { id: '3', subject: 'Important: System Maintenance', sender: { name: 'IT Support', email: 'it@example.com' }, date: '2024-03-19 11:20', isUnread: true }, ]; try { // Simulate API call await new Promise(resolve => setTimeout(resolve, 1000)); setEmails(mockEmails); setError(null); } catch (err) { setError('Failed to fetch emails'); console.error('Error fetching emails:', err); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { if (status === 'authenticated') { fetchEmails(); } }, [status]); if (status === 'loading' || loading) { return ( Email

Loading...

); } return ( Email {error ? (

{error}

) : (
{emails.length === 0 ? (

No emails available

) : ( emails.map((email) => (
{email.sender.name}
{email.isUnread && ( )} {email.date}

{email.subject}

)) )}
)}
); }