import { useState, useCallback } from 'react'; export interface Mail { id: string; from: string; to: string; subject: string; body: string; date: string; read: boolean; starred: boolean; folder: string; cc?: string[]; bcc?: string[]; flags?: string[]; } export const useMail = () => { const [mails, setMails] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const fetchMails = useCallback(async () => { setIsLoading(true); setError(null); try { const response = await fetch('/api/mail'); if (!response.ok) { throw new Error('Failed to fetch mails'); } const data = await response.json(); setMails(data.emails); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to fetch mails'); } finally { setIsLoading(false); } }, []); return { mails, isLoading, error, fetchMails, }; };