import { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; import { Button } from './ui/button'; import { Badge } from './ui/badge'; import { Switch } from './ui/switch'; import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs'; import { Bell, AlertTriangle, Info, Check, X, Mail, MessageSquare, Smartphone } from 'lucide-react'; import { User } from '../types'; import { mockNotifications } from '../mockData'; interface NotificationCenterProps { user: User; } export default function NotificationCenter({ user }: NotificationCenterProps) { const [notifications, setNotifications] = useState(mockNotifications); const [filter, setFilter] = useState<'all' | 'unread' | 'critical'>('all'); // Notification preferences const [emailEnabled, setEmailEnabled] = useState(true); const [smsEnabled, setSmsEnabled] = useState(true); const [whatsappEnabled, setWhatsappEnabled] = useState(false); const [criticalAlerts, setCriticalAlerts] = useState(true); const [inventoryAlerts, setInventoryAlerts] = useState(true); const [healthAlerts, setHealthAlerts] = useState(true); const filteredNotifications = notifications.filter(notif => { if (filter === 'unread') return !notif.read; if (filter === 'critical') return notif.priority === 'critical'; return true; }); const unreadCount = notifications.filter(n => !n.read).length; const criticalCount = notifications.filter(n => n.priority === 'critical' && !n.read).length; const handleMarkAsRead = (id: string) => { setNotifications(notifications.map(n => n.id === id ? { ...n, read: true } : n )); }; const handleMarkAllAsRead = () => { setNotifications(notifications.map(n => ({ ...n, read: true }))); }; const handleDelete = (id: string) => { setNotifications(notifications.filter(n => n.id !== id)); }; const getNotificationIcon = (type: string) => { switch (type) { case 'alert': return AlertTriangle; case 'warning': return AlertTriangle; case 'info': return Info; default: return Bell; } }; const getNotificationColor = (priority: string) => { switch (priority) { case 'critical': return 'bg-red-50 border-red-200'; case 'high': return 'bg-orange-50 border-orange-200'; case 'medium': return 'bg-yellow-50 border-yellow-200'; case 'low': return 'bg-blue-50 border-blue-200'; default: return 'bg-gray-50 border-gray-200'; } }; const getPriorityBadgeColor = (priority: string) => { switch (priority) { case 'critical': return 'bg-red-100 text-red-800'; case 'high': return 'bg-orange-100 text-orange-800'; case 'medium': return 'bg-yellow-100 text-yellow-800'; case 'low': return 'bg-blue-100 text-blue-800'; default: return 'bg-gray-100 text-gray-800'; } }; const getTimeAgo = (timestamp: string) => { const now = new Date(); const time = new Date(timestamp); const diffInHours = Math.floor((now.getTime() - time.getTime()) / (1000 * 60 * 60)); if (diffInHours < 1) return 'Just now'; if (diffInHours < 24) return `${diffInHours}h ago`; const diffInDays = Math.floor(diffInHours / 24); return `${diffInDays}d ago`; }; return (
Manage alerts and communication preferences
{unreadCount} unread
Require attention
Communication methods
{notification.title}
{notification.message}
No notifications
{filter === 'unread' ? "You're all caught up!" : filter === 'critical' ? "No critical alerts at this time" : "You'll see notifications here"}
Choose how you want to receive alerts
Email Notifications
{user.email}
SMS Alerts
{user.phone}
{user.phone}
Customize which alerts you want to receive
Critical System Alerts
Water quality issues, equipment failures
Inventory Alerts
Low stock, expiring items
Health & Disease Alerts
Disease detection, mortality spikes
Daily Reports
Performance summaries, growth updates
Scheduled Tasks
Feeding reminders, sampling schedules
Set times when non-critical notifications are paused
Enable Quiet Hours
10:00 PM - 7:00 AM
Note: Critical alerts will always be delivered immediately