"use client"; import React, { useState } from "react"; import { useRouter } from "next/navigation"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { BellRing, Package, MessageCircle } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useNotifications } from "@/lib/notification-context"; export default function UnifiedNotifications() { const router = useRouter(); const [activeTab, setActiveTab] = useState("all"); // Get notification state from context const { unreadCounts, chatMetadata, newOrders, clearOrderNotifications, totalNotifications, loading, } = useNotifications(); // Navigation handlers const handleChatClick = (chatId: string) => { router.push(`/dashboard/chats/${chatId}`); }; const handleOrderClick = (orderId: string) => { router.push(`/dashboard/orders/${orderId}`); }; // Format the price as currency const formatPrice = (price: number) => { return `£${price.toFixed(2)}`; }; return (
All {totalNotifications > 0 && ( {totalNotifications} )} Messages {unreadCounts.totalUnread > 0 && ( {unreadCounts.totalUnread} )} Orders {newOrders.length > 0 && ( {newOrders.length} )} {totalNotifications === 0 ? (

No new notifications

) : (
{/* Messages Section */} {unreadCounts.totalUnread > 0 && ( <>
Unread Messages
{Object.entries(unreadCounts.chatCounts).slice(0, 3).map(([chatId, count]) => ( handleChatClick(chatId)} >

Customer {chatMetadata[chatId]?.buyerId.slice(-4) || 'Unknown'}

{count} new {count === 1 ? 'message' : 'messages'}

{count}
))} {Object.keys(unreadCounts.chatCounts).length > 3 && (
+ {Object.keys(unreadCounts.chatCounts).length - 3} more unread chats
)} )} {/* Orders Section */} {newOrders.length > 0 && ( <>
New Paid Orders
{newOrders.slice(0, 3).map((order) => ( handleOrderClick(order._id)} >

Order #{order.orderId}

{formatPrice(order.totalPrice)}

Paid
))} {newOrders.length > 3 && (
+ {newOrders.length - 3} more new orders
)} )}
)}
{unreadCounts.totalUnread === 0 ? (

No unread messages

) : ( <>
{Object.entries(unreadCounts.chatCounts).map(([chatId, count]) => ( handleChatClick(chatId)} >

Customer {chatMetadata[chatId]?.buyerId.slice(-4) || 'Unknown'}

{count} new {count === 1 ? 'message' : 'messages'}

{count}
))}
)}
{newOrders.length === 0 ? (

No new paid orders

) : ( <>
New Paid Orders
{newOrders.map((order) => ( handleOrderClick(order._id)} >

Order #{order.orderId}

{formatPrice(order.totalPrice)}

Paid
))}
)}
); }