import { Bell, Check, Crown, FileText, MessageCircle, Star, Trophy, Users, type LucideIcon } from 'lucide-react'; import { api, type NotificationItem } from '@/api'; import { useAppData } from '@/state/AppData'; import { useAsync } from '@/lib/useAsync'; import { useToast } from '@/components/Toast'; import { EmptyState, ErrorState, LoadingState, Screen, ScreenHeader } from '@/components/ui'; import { relativeTime, toFa } from '@/lib/format'; import { MathText } from '@/lib/MathText'; const STYLE: Record = { xp_earned: { icon: Star, color: '#E8A400', bg: '#FFF8E1' }, lesson_completed: { icon: Check, color: '#5FBF8F', bg: '#EAF8F0' }, node_completed: { icon: Trophy, color: '#FF7A3D', bg: '#FFF1E6' }, order_paid: { icon: Crown, color: '#9B7BFF', bg: '#F5F1FF' }, ticket_replied: { icon: MessageCircle, color: '#4C5FD5', bg: '#EEF1FF' }, family_link_accepted: { icon: Users, color: '#FF7A3D', bg: '#FFF1E6' }, weekly_report_ready: { icon: FileText, color: '#91ADC6', bg: '#EAF2F6' }, }; const styleOf = (type: string) => STYLE[type] ?? { icon: Bell, color: '#9e9ec0', bg: '#f0eeff' }; export function NotificationsScreen() { const { setUnreadCount } = useAppData(); const toast = useToast(); const list = useAsync(async () => { const r = await api.notifications.list(); setUnreadCount(r.unreadCount); return r.items; }, []); const items = list.data ?? []; const unread = items.filter((n) => !n.isRead).length; const markLocal = (predicate: (n: NotificationItem) => boolean) => { list.setData((prev) => prev?.map((n) => (predicate(n) ? { ...n, isRead: true } : n))); }; async function markOne(n: NotificationItem) { if (n.isRead) return; markLocal((x) => x.id === n.id); setUnreadCount(Math.max(0, unread - 1)); api.notifications.markRead(n.id).catch(() => {}); } async function markAll() { markLocal(() => true); setUnreadCount(0); try { await api.notifications.markAllRead(); } catch { toast('ثبت نشد؛ دوباره امتحان کن', 'error'); list.reload(); } } return ( {unread > 0 && ( )}
{list.loading ? ( ) : list.error ? ( ) : items.length === 0 ? ( ) : (
    {items.map((n) => { const s = styleOf(n.type); const Icon = s.icon; return (
  • ); })}
)}
); }