import React, { useState, useEffect } from 'react'; import { Bell, X, Calendar, DollarSign, AlertCircle, UserCheck, MessageSquare, ShieldAlert } from 'lucide-react'; import { HybridBackend } from '../services/backend.ts'; import { Notificacao } from '../types.ts'; export const NotificationCenter: React.FC = () => { const [isOpen, setIsOpen] = useState(false); const [notificacoes, setNotificacoes] = useState([]); const [unreadCount, setUnreadCount] = useState(0); const fetch = async () => { try { const data = await HybridBackend.getNotifications(); setNotificacoes(data); setUnreadCount(data.filter(n => !n.lida).length); } catch (err) { console.error("Erro ao carregar notificações"); } }; useEffect(() => { fetch(); const interval = setInterval(fetch, 30000); // Polling cada 30s return () => clearInterval(interval); }, []); const toggleOpen = () => setIsOpen(!isOpen); const markAsRead = async (id: string) => { await HybridBackend.markNotificationRead(id); setNotificacoes(prev => prev.map(n => n.id === id ? { ...n, lida: true } : n)); setUnreadCount(prev => Math.max(0, prev - 1)); }; const getIcon = (tipo: string) => { switch (tipo) { case 'agenda': return ; case 'financeiro': return ; case 'lead': return ; case 'sistema': return ; default: return ; } }; const getTypeLabel = (tipo: string) => { switch (tipo) { case 'agenda': return 'Agenda'; case 'financeiro': return 'Financeiro'; case 'lead': return 'Novo Lead'; case 'sistema': return 'Sistema'; default: return 'Geral'; } }; return (
{isOpen && ( <>

Centro de Notificações

Você tem {unreadCount} novas mensagens

{notificacoes.length === 0 ? (

Tudo limpo por aqui!

Não há notificações para mostrar no momento.

) : (
{notificacoes.map(notif => (
{!notif.lida && (
)}
{getIcon(notif.tipo)}
{getTypeLabel(notif.tipo)} {new Date(notif.data).toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' })}

{notif.titulo}

{notif.mensagem}

{!notif.lida && ( )}
))}
)}
)}
); };