File size: 2,812 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * EmailInboxWidget - Gmail/Outlook Inbox Monitor
 */

import React from 'react';
import { Mail, Inbox, Star, Archive } from 'lucide-react';
import { useLiveData } from '@/hooks/useLiveData';
import { useWidgetCommunication } from '@/contexts/WidgetContext';
import { cn } from '@/lib/utils';

export default function EmailInboxWidget({ widgetId }: { widgetId: string }) {
    const { data, connected } = useLiveData({
        widgetId,
        widgetType: 'email',
        requiredSources: ['gmail', 'outlook'],
        autoConnect: true,
        pollInterval: 60000,
    });

    const { broadcastEvent } = useWidgetCommunication(widgetId);

    const unreadCount = data?.unreadCount || 0;
    const recentEmails = data?.emails || [];

    return (
        <div className="h-full flex flex-col bg-gradient-to-br from-pink-500/10 to-rose-500/10 backdrop-blur-sm border border-pink-500/30 rounded-lg overflow-hidden">
            <div className="p-4 border-b border-pink-500/20">
                <div className="flex items-center justify-between">
                    <div className="flex items-center gap-2">
                        <Mail className="w-5 h-5 text-pink-400" />
                        <span className="font-display text-sm uppercase tracking-wider text-pink-400">Inbox</span>
                    </div>
                    <div className={cn(
                        "px-3 py-1 rounded-full text-xs font-semibold",
                        unreadCount > 0 ? "bg-pink-500 text-white" : "bg-pink-500/20 text-pink-400"
                    )}>
                        {unreadCount}
                    </div>
                </div>
            </div>

            <div className="flex-1 overflow-y-auto p-3 space-y-2">
                {recentEmails.slice(0, 5).map((email: any) => (
                    <div key={email.id} className="p-3 bg-pink-500/10 border border-pink-500/30 rounded-lg hover:bg-pink-500/20 transition-all cursor-pointer">
                        <div className="flex items-start justify-between gap-2">
                            <div className="flex-1">
                                <div className="text-sm font-medium text-white mb-1">{email.from}</div>
                                <div className="text-xs text-pink-300">{email.subject}</div>
                            </div>
                            {email.starred && <Star className="w-4 h-4 text-yellow-400" />}
                        </div>
                    </div>
                ))}
            </div>

            <div className="p-3 border-t border-pink-500/20 bg-black/20">
                <button className="w-full py-2 bg-pink-500 hover:bg-pink-600 text-white rounded text-sm transition-colors">
                    Open Inbox
                </button>
            </div>
        </div>
    );
}