"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5898],{19881:(e,t,o)=>{o.d(t,{E:()=>i});var n=o(12115),s=o(14734),a=o(25112);function i(e){let[t,o]=(0,n.useState)(0),[i,l]=(0,n.useState)(!1),[r,c]=(0,n.useState)(null),{socket:d,isConnected:u}=(0,s.F)(),{lastNotification:f}=(0,a.h)(),[m,g]=(0,n.useState)("none"),[p,h]=(0,n.useState)(0),[b,x]=(0,n.useState)(0),w=(0,n.useCallback)(async()=>{if(e){l(!0),c(null);try{console.log("\uD83D\uDD04 Loading unread count for user:",e);let t=await fetch("/api/notifications?unread=true"),n=await t.json();if(n.success){let e=n.data.unreadCount;o(t=>(console.log("\uD83D\uDCCA Loaded unread count:",e,"previous:",t),t!==e&&console.log("✅ Unread count updated:",t,"->",e),e))}else c("خطا در بارگذاری تعداد اعلان‌ها")}catch(e){console.error("Error loading unread count:",e),c("خطا در اتصال به سرور")}finally{l(!1)}}},[e]),v=(0,n.useCallback)(async()=>{await w()},[w]);return(0,n.useEffect)(()=>{if(!d||!u||!e)return;"none"!==m&&"socket"!==m&&console.log("⚠️ Socket listener active alongside:",m),console.log("\uD83D\uDD0C Setting up notification socket listeners for user:",e),d.emit("joinUserRoom",e);let t=e=>{console.log("\uD83D\uDD14 New notification received via socket:",e),g("socket"),h(Date.now()),x(0),o(t=>{let o=t+1;return console.log("� SOCKET.IO notification received:",{from:t,to:o,data:e,timestamp:new Date().toISOString()}),o})};d.on("notification",t);let n=setTimeout(()=>{"none"===m&&(console.log("⚠️ Socket.IO timeout - falling back to SSE"),g("sse"))},1e4);return()=>{console.log("\uD83E\uDDF9 Cleaning up notification socket listeners"),clearTimeout(n),d.off("notification",t)}},[d,u,e,m]),(0,n.useEffect)(()=>{f&&"notification"===f.type&&"socket"!==m&&(console.log("\uD83D\uDD14 New SSE notification received:",f),g("sse"),h(Date.now()),x(0),o(e=>{let t=e+1;return console.log("� SSE notification received:",{from:e,to:t,data:f,timestamp:new Date().toISOString()}),t}))},[f,m]),(0,n.useEffect)(()=>{let e=()=>{console.log("\uD83D\uDD14 Custom newNotification event received"),o(e=>e+1)};return window.addEventListener("newNotification",e),()=>{window.removeEventListener("newNotification",e)}},[]),(0,n.useEffect)(()=>{let t;if(!e)return;if("socket"===m||"sse"===m)return void console.log("✅ Real-time method active, skipping polling");console.log("⏰ Setting up smart polling for user:",e),console.log("\uD83D\uDCCA Current method:",m,"failures:",b);let o=setInterval(async()=>{if(Date.now()-p<12e4&&"none"!==m)return void console.log("✅ Recent notification received, reducing polling frequency");console.log("⏰ POLLING notification check:",{method:"polling",timestamp:new Date().toISOString(),interval:t}),g("polling");try{await w(),x(0),console.log("✅ Polling successful")}catch(e){x(e=>e+1),console.warn("❌ Polling failed:",e)}},t=b>3?6e4:"none"===m?3e4:15e3);return()=>{clearInterval(o)}},[e,w,m,b,p]),(0,n.useEffect)(()=>{if(!e)return;let t=()=>{let e=Date.now()-p;"none"===m||"polling"===m||e>3e5?(console.log("\uD83D\uDD0D Window focused - refreshing notifications (smart)"),w()):console.log("✅ Window focused but real-time is active, skipping refresh")},o=()=>{document.hidden||(console.log("\uD83D\uDCF1 Mobile app became visible - refreshing notifications"),w())};return window.addEventListener("focus",t),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",t),document.removeEventListener("visibilitychange",o)}},[e,w,m,p]),(0,n.useEffect)(()=>{e&&w()},[e,w]),(0,n.useEffect)(()=>{e&&(window.debugNotifications=()=>{console.log("\uD83D\uDC1B NOTIFICATION DEBUG INFO:",{userId:e,unreadCount:t,realtimeMethod:m,isSocketConnected:u,consecutiveFailures:b,lastNotificationTime:new Date(p).toISOString(),timeSinceLastNotification:Math.round((Date.now()-p)/1e3)+"s"})})},[e,t,m,u,b,p]),{unreadCount:t,loading:i,error:r,refreshUnreadCount:v,realtimeMethod:m,debugInfo:{lastNotificationTime:p,consecutiveFailures:b,isSocketConnected:u}}}},27063:(e,t,o)=>{o.d(t,{Fm:()=>u,Qs:()=>m,cj:()=>l,h:()=>d,qp:()=>f});var n=o(95155);o(12115);var s=o(89511),a=o(65229),i=o(64269);function l(e){let{...t}=e;return(0,n.jsx)(s.bL,{"data-slot":"sheet",...t})}function r(e){let{...t}=e;return(0,n.jsx)(s.ZL,{"data-slot":"sheet-portal",...t})}function c(e){let{className:t,...o}=e;return(0,n.jsx)(s.hJ,{"data-slot":"sheet-overlay",className:(0,i.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/60 backdrop-blur-sm",t),...o})}function d(e){let{className:t,children:o,side:l="right",...d}=e;return(0,n.jsxs)(r,{children:[(0,n.jsx)(c,{}),(0,n.jsxs)(s.UC,{"data-slot":"sheet-content",className:(0,i.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500","right"===l&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm","left"===l&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm","top"===l&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b","bottom"===l&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",t),...d,children:[o,(0,n.jsxs)(s.bm,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none",children:[(0,n.jsx)(a.A,{className:"size-4"}),(0,n.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function u(e){let{className:t,...o}=e;return(0,n.jsx)("div",{"data-slot":"sheet-header",className:(0,i.cn)("flex flex-col gap-1.5 p-4",t),...o})}function f(e){let{className:t,...o}=e;return(0,n.jsx)(s.hE,{"data-slot":"sheet-title",className:(0,i.cn)("text-foreground font-semibold",t),...o})}function m(e){let{className:t,...o}=e;return(0,n.jsx)(s.VY,{"data-slot":"sheet-description",className:(0,i.cn)("text-muted-foreground text-sm",t),...o})}},66091:(e,t,o)=>{function n(){return"/auth/customer/signin"}function s(){return"/auth/customer/signup/phone"}function a(){return"/auth/business/signin"}function i(){return"/auth/business/signup/phone"}function l(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"customer";return"business"===e?"/auth/business/forgot-password":"/auth/customer/forgot-password"}o.d(t,{Ku:()=>s,O$:()=>l,aC:()=>a,al:()=>i,kk:()=>n})},85898:(e,t,o)=>{o.d(t,{r:()=>g});var n=o(95155),s=o(12115),a=o(36489),i=o(20063),l=o(13492),r=o(85998),c=o(64269),d=o(19881),u=o(56645),f=o(27063),m=o(66091);function g(e){var t,o;let{className:g,iconClassName:p}=e,{data:h}=(0,a.useSession)(),b=(0,i.useRouter)(),x=(0,i.usePathname)(),[w,v]=(0,s.useState)(!1),k=null==h||null==(t=h.user)?void 0:t.id,{unreadCount:N,refreshUnreadCount:j}=(0,d.E)(k);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{if(!(null==h?void 0:h.user)){let e="".concat((0,m.kk)(),"?callbackUrl=").concat(encodeURIComponent(x||"/"));b.push(e);return}v(!0)},className:(0,c.cn)("relative w-10 h-10 rounded-2xl bg-white/90 backdrop-blur-md border border-purple-100 text-gray-700 hover:text-purple-700 hover:border-purple-300 flex items-center justify-center shadow-sm hover:shadow-md transition-all active:scale-95",g),title:"اعلان‌ها","aria-label":"اعلان‌ها",children:[N>0?(0,n.jsx)(l.A,{className:(0,c.cn)("w-5 h-5 text-purple-600 animate-pulse",p)}):(0,n.jsx)(r.A,{className:(0,c.cn)("w-5 h-5 text-gray-700 transition-colors",p)}),N>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 bg-red-500 text-white text-[10px] font-black rounded-full flex items-center justify-center shadow-md animate-bounce",children:N>99?"+۹۹":(e=>{let t=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"];return e.toString().replace(/\d/g,e=>t[parseInt(e,10)])})(N)})]}),(null==h||null==(o=h.user)?void 0:o.id)&&(0,n.jsx)(f.cj,{open:w,onOpenChange:v,children:(0,n.jsxs)(f.h,{side:"bottom",className:"dir-rtl font-vazir font-farsi rounded-t-[32px] border-t border-purple-100 p-4 sm:p-6 shadow-2xl bg-white/95 backdrop-blur-xl max-w-lg mx-auto no-scrollbar max-h-[88vh] overflow-y-auto [&::-webkit-scrollbar]:hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-bottom-full data-[state=open]:duration-500 data-[state=closed]:duration-300 transition-all ease-out",children:[(0,n.jsx)("div",{className:"w-12 h-1.5 bg-gray-200 rounded-full mx-auto -mt-2 mb-3"}),(0,n.jsxs)(f.Fm,{className:"sr-only",children:[(0,n.jsx)(f.qp,{children:"مرکز اعلان‌ها"}),(0,n.jsx)(f.Qs,{children:"مشاهده و مدیریت اعلان‌های دریافتی"})]}),(0,n.jsx)("div",{className:"w-full",children:(0,n.jsx)(u.NotificationPanel,{userId:h.user.id,showCloseButton:!0,onClose:()=>v(!1),onNotificationRead:()=>{j()},className:"border-0 shadow-none p-0 bg-transparent"})})]})})]})}}}]);