'use client'; import { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useI18n } from '@/i18n'; /* ------------------------------------------------------------------ */ /* Types */ /* ------------------------------------------------------------------ */ type NotificationType = 'new_lead' | 'deal_won' | 'deal_lost' | 'message' | 'task_due' | 'approval_needed'; interface Notification { id: string; type: NotificationType; titleAr: string; titleEn: string; timeAgo: string; read: boolean; } /* ------------------------------------------------------------------ */ /* Mock data */ /* ------------------------------------------------------------------ */ const typeConfig: Record = { new_lead: { icon: '👤', color: 'bg-blue-500/20 text-blue-400' }, deal_won: { icon: '🎉', color: 'bg-emerald-500/20 text-emerald-400' }, deal_lost: { icon: '📉', color: 'bg-red-500/20 text-red-400' }, message: { icon: '💬', color: 'bg-primary/20 text-primary' }, task_due: { icon: '⏰', color: 'bg-amber-500/20 text-amber-400' }, approval_needed: { icon: '✅', color: 'bg-purple-500/20 text-purple-400' }, }; const initialNotifications: Notification[] = [ { id: '1', type: 'new_lead', titleAr: 'عميل محتمل جديد: محمد السالم', titleEn: 'New lead: Mohammed Al-Salem', timeAgo: '2m', read: false }, { id: '2', type: 'deal_won', titleAr: 'تم كسب صفقة عقار الرياض — ٥٠٠,٠٠٠ ر.س', titleEn: 'Deal won: Riyadh Property — SAR 500,000', timeAgo: '15m', read: false }, { id: '3', type: 'message', titleAr: 'رسالة جديدة من أحمد الغامدي', titleEn: 'New message from Ahmed Al-Ghamdi', timeAgo: '1h', read: false }, { id: '4', type: 'task_due', titleAr: 'مهمة مستحقة: متابعة عميل شركة النور', titleEn: 'Task due: Follow up with Al-Nour Co.', timeAgo: '2h', read: true }, { id: '5', type: 'approval_needed', titleAr: 'طلب موافقة على خصم ١٥٪', titleEn: 'Discount approval request: 15%', timeAgo: '3h', read: true }, { id: '6', type: 'deal_lost', titleAr: 'صفقة خاسرة: مشروع جدة', titleEn: 'Deal lost: Jeddah Project', timeAgo: '5h', read: true }, ]; /* ------------------------------------------------------------------ */ /* Component */ /* ------------------------------------------------------------------ */ export function NotificationBell() { const { isArabic } = useI18n(); const [open, setOpen] = useState(false); const [notifications, setNotifications] = useState(initialNotifications); const ref = useRef(null); const unreadCount = notifications.filter((n) => !n.read).length; const label = (ar: string, en: string) => (isArabic ? ar : en); // Close on outside click useEffect(() => { function handleClick(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener('mousedown', handleClick); return () => document.removeEventListener('mousedown', handleClick); }, []); function markAllRead() { setNotifications((prev) => prev.map((n) => ({ ...n, read: true }))); } function markRead(id: string) { setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, read: true } : n))); } return (
{/* Bell button */} {/* Dropdown */} {open && ( {/* Header */}

{label('الإشعارات', 'Notifications')}

{unreadCount > 0 && ( )}
{/* List */}
{notifications.length === 0 ? (

{label('لا توجد إشعارات جديدة', 'No new notifications')}

) : ( notifications.map((n) => { const cfg = typeConfig[n.type]; return ( ); }) )}
{/* Footer */}
)}
); }