(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6538],{52955:(e,t,i)=>{"use strict";i.d(t,{default:()=>o});var s=i(73365),a=i(1521),r=i(42354),n=i(96040);function o(e){let{userId:t}=e,[i,o]=(0,a.useState)(!1),c=(0,r.n)(e=>e.user),{notifications:l,markAsRead:d}=(0,n.E)(c.id),f=(null==l?void 0:l.filter(e=>!e.read))||[],h=f.length,m=e=>{d([e])};return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsxs)("button",{onClick:()=>o(!i),className:"p-2 rounded-full hover:bg-gray-100 relative cursor-pointer",children:[(0,s.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"})}),h>0&&(0,s.jsx)("span",{className:"absolute top-0 right-0 bg-red-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center",children:h})]}),i&&(0,s.jsxs)("div",{className:"absolute right-0 mt-2 w-80 bg-white rounded-md shadow-lg z-50",children:[(0,s.jsxs)("div",{className:"p-3 border-b flex justify-between items-center",children:[(0,s.jsx)("h3",{className:"font-semibold",children:"Notifications"}),(0,s.jsx)("button",{onClick:()=>{let e=l.filter(e=>!e.read).map(e=>e.id);e.length>0&&d(e)},className:"text-sm text-blue-500 hover:text-blue-700",children:"Mark all as read"})]}),(0,s.jsx)("div",{className:"max-h-96 overflow-y-auto",children:0===f.length?(0,s.jsx)("div",{className:"p-4 text-center text-gray-500",children:"No notifications"}):null==f?void 0:f.map(e=>(0,s.jsxs)("div",{className:"p-3 border-b hover:bg-gray-50 cursor-pointer ".concat(e.read?"":"bg-blue-50"),onClick:()=>m(e.id),children:[(0,s.jsx)("div",{className:"font-medium",children:e.title}),(0,s.jsx)("div",{className:"text-sm text-gray-600",children:e.message}),(0,s.jsx)("div",{className:"text-xs text-gray-400 mt-1",children:new Date(e.createdAt).toLocaleString()})]},e.id))})]})]})}i(65958)},65958:(e,t,i)=>{"use strict";(0,i(73401).v)(e=>({notifications:[],setNotifications:t=>e({notifications:t}),addNotification:t=>e(e=>({notifications:e.notifications.some(e=>e.id===t.id)?e.notifications:[...e.notifications,t]})),markAsRead:t=>e(e=>({notifications:e.notifications.map(e=>t.includes(e.id)?{...e,read:!0}:e)})),clearNotifications:()=>e({notifications:[]})}))},78056:(e,t,i)=>{Promise.resolve().then(i.bind(i,98384)),Promise.resolve().then(i.bind(i,52955)),Promise.resolve().then(i.t.bind(i,98084,23))},96040:(e,t,i)=>{"use strict";i.d(t,{E:()=>a});var s=i(1521);function a(e){let[t,i]=(0,s.useState)([]),a=(0,s.useRef)(null);return(0,s.useEffect)(()=>{if(!e)return;(async()=>{try{let e=await fetch("/api/notifications/all"),t=await e.json();t.success?i(t.notifications):console.error("Failed to fetch notifications")}catch(e){console.error("Error fetching notifications:",e)}})();let t=()=>{let e=new EventSource("/api/notifications/stream",{withCredentials:!0});a.current=e,e.onmessage=e=>{try{let t=JSON.parse(e.data);i(e=>e.some(e=>e.id===t.id)?e:[...e,t])}catch(e){console.error("Error parsing SSE message",e)}},e.addEventListener("heartbeat",()=>{}),e.onerror=i=>{console.error("SSE connection error",i),e.close(),setTimeout(t,5e3)}};return t(),()=>{a.current&&a.current.close()}},[e]),{notifications:t,markAsRead:async e=>{try{await fetch("/api/notifications/mark-read",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({notificationIds:e})}),i(t=>t.map(t=>e.includes(t.id)?{...t,read:!0}:t))}catch(e){console.error("Failed to mark notifications as read",e)}}}}},98084:e=>{e.exports={style:{fontFamily:"'geistSans', 'geistSans Fallback'",fontWeight:400,fontStyle:"normal"},className:"__className_04fa55",variable:"__variable_04fa55"}}},e=>{var t=t=>e(e.s=t);e.O(0,[3094,9534,3736,6019,2347,4870,7358],()=>t(78056)),_N_E=e.O()}]);