"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8054],{19881:(t,e,o)=>{o.d(e,{E:()=>i});var a=o(12115),n=o(14734),s=o(25112);function i(t){let[e,o]=(0,a.useState)(0),[i,r]=(0,a.useState)(!1),[l,c]=(0,a.useState)(null),{socket:u,isConnected:d}=(0,n.F)(),{lastNotification:p}=(0,s.h)(),[g,f]=(0,a.useState)("none"),[h,m]=(0,a.useState)(0),[b,j]=(0,a.useState)(0),v=(0,a.useCallback)(async()=>{if(t){r(!0),c(null);try{console.log("\uD83D\uDD04 Loading unread count for user:",t);let e=await fetch("/api/notifications?unread=true"),a=await e.json();if(a.success){let t=a.data.unreadCount;o(e=>(console.log("\uD83D\uDCCA Loaded unread count:",t,"previous:",e),e!==t&&console.log("✅ Unread count updated:",e,"->",t),t))}else c("خطا در بارگذاری تعداد اعلان‌ها")}catch(t){console.error("Error loading unread count:",t),c("خطا در اتصال به سرور")}finally{r(!1)}}},[t]),y=(0,a.useCallback)(async()=>{await v()},[v]);return(0,a.useEffect)(()=>{if(!u||!d||!t)return;"none"!==g&&"socket"!==g&&console.log("⚠️ Socket listener active alongside:",g),console.log("\uD83D\uDD0C Setting up notification socket listeners for user:",t),u.emit("joinUserRoom",t);let e=t=>{console.log("\uD83D\uDD14 New notification received via socket:",t),f("socket"),m(Date.now()),j(0),o(e=>{let o=e+1;return console.log("� SOCKET.IO notification received:",{from:e,to:o,data:t,timestamp:new Date().toISOString()}),o})};u.on("notification",e);let a=setTimeout(()=>{"none"===g&&(console.log("⚠️ Socket.IO timeout - falling back to SSE"),f("sse"))},1e4);return()=>{console.log("\uD83E\uDDF9 Cleaning up notification socket listeners"),clearTimeout(a),u.off("notification",e)}},[u,d,t,g]),(0,a.useEffect)(()=>{p&&"notification"===p.type&&"socket"!==g&&(console.log("\uD83D\uDD14 New SSE notification received:",p),f("sse"),m(Date.now()),j(0),o(t=>{let e=t+1;return console.log("� SSE notification received:",{from:t,to:e,data:p,timestamp:new Date().toISOString()}),e}))},[p,g]),(0,a.useEffect)(()=>{let t=()=>{console.log("\uD83D\uDD14 Custom newNotification event received"),o(t=>t+1)};return window.addEventListener("newNotification",t),()=>{window.removeEventListener("newNotification",t)}},[]),(0,a.useEffect)(()=>{let e;if(!t)return;if("socket"===g||"sse"===g)return void console.log("✅ Real-time method active, skipping polling");console.log("⏰ Setting up smart polling for user:",t),console.log("\uD83D\uDCCA Current method:",g,"failures:",b);let o=setInterval(async()=>{if(Date.now()-h<12e4&&"none"!==g)return void console.log("✅ Recent notification received, reducing polling frequency");console.log("⏰ POLLING notification check:",{method:"polling",timestamp:new Date().toISOString(),interval:e}),f("polling");try{await v(),j(0),console.log("✅ Polling successful")}catch(t){j(t=>t+1),console.warn("❌ Polling failed:",t)}},e=b>3?6e4:"none"===g?3e4:15e3);return()=>{clearInterval(o)}},[t,v,g,b,h]),(0,a.useEffect)(()=>{if(!t)return;let e=()=>{let t=Date.now()-h;"none"===g||"polling"===g||t>3e5?(console.log("\uD83D\uDD0D Window focused - refreshing notifications (smart)"),v()):console.log("✅ Window focused but real-time is active, skipping refresh")},o=()=>{document.hidden||(console.log("\uD83D\uDCF1 Mobile app became visible - refreshing notifications"),v())};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",o)}},[t,v,g,h]),(0,a.useEffect)(()=>{t&&v()},[t,v]),(0,a.useEffect)(()=>{t&&(window.debugNotifications=()=>{console.log("\uD83D\uDC1B NOTIFICATION DEBUG INFO:",{userId:t,unreadCount:e,realtimeMethod:g,isSocketConnected:d,consecutiveFailures:b,lastNotificationTime:new Date(h).toISOString(),timeSinceLastNotification:Math.round((Date.now()-h)/1e3)+"s"})})},[t,e,g,d,b,h]),{unreadCount:e,loading:i,error:l,refreshUnreadCount:y,realtimeMethod:g,debugInfo:{lastNotificationTime:h,consecutiveFailures:b,isSocketConnected:d}}}},27063:(t,e,o)=>{o.d(e,{Fm:()=>d,Qs:()=>g,cj:()=>r,h:()=>u,qp:()=>p});var a=o(95155);o(12115);var n=o(89511),s=o(65229),i=o(64269);function r(t){let{...e}=t;return(0,a.jsx)(n.bL,{"data-slot":"sheet",...e})}function l(t){let{...e}=t;return(0,a.jsx)(n.ZL,{"data-slot":"sheet-portal",...e})}function c(t){let{className:e,...o}=t;return(0,a.jsx)(n.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/50",e),...o})}function u(t){let{className:e,children:o,side:r="right",...u}=t;return(0,a.jsxs)(l,{children:[(0,a.jsx)(c,{}),(0,a.jsxs)(n.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"===r&&"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"===r&&"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"===r&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b","bottom"===r&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",e),...u,children:[o,(0,a.jsxs)(n.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,a.jsx)(s.A,{className:"size-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function d(t){let{className:e,...o}=t;return(0,a.jsx)("div",{"data-slot":"sheet-header",className:(0,i.cn)("flex flex-col gap-1.5 p-4",e),...o})}function p(t){let{className:e,...o}=t;return(0,a.jsx)(n.hE,{"data-slot":"sheet-title",className:(0,i.cn)("text-foreground font-semibold",e),...o})}function g(t){let{className:e,...o}=t;return(0,a.jsx)(n.VY,{"data-slot":"sheet-description",className:(0,i.cn)("text-muted-foreground text-sm",e),...o})}},66091:(t,e,o)=>{function a(){return"/auth/customer/signin"}function n(){return"/auth/customer/signup/phone"}function s(){return"/auth/business/signin"}function i(){return"/auth/business/signup/phone"}function r(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"customer";return"business"===t?"/auth/business/forgot-password":"/auth/customer/forgot-password"}o.d(e,{Ku:()=>n,O$:()=>r,aC:()=>s,al:()=>i,kk:()=>a})},85898:(t,e,o)=>{o.d(e,{r:()=>f});var a=o(95155),n=o(12115),s=o(36489),i=o(20063),r=o(13492),l=o(85998),c=o(64269),u=o(19881),d=o(94088),p=o(27063),g=o(66091);function f(t){var e,o;let{className:f,iconClassName:h}=t,{data:m}=(0,s.useSession)(),b=(0,i.useRouter)(),j=(0,i.usePathname)(),[v,y]=(0,n.useState)(!1),w=null==m||null==(e=m.user)?void 0:e.id,{unreadCount:x,refreshUnreadCount:k}=(0,u.E)(w);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",onClick:()=>{if(!(null==m?void 0:m.user)){let t="".concat((0,g.kk)(),"?callbackUrl=").concat(encodeURIComponent(j||"/"));b.push(t);return}y(!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",f),title:"اعلان‌ها","aria-label":"اعلان‌ها",children:[x>0?(0,a.jsx)(r.A,{className:(0,c.cn)("w-5 h-5 text-purple-600 animate-pulse",h)}):(0,a.jsx)(l.A,{className:(0,c.cn)("w-5 h-5 text-gray-700 transition-colors",h)}),x>0&&(0,a.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:x>99?"+۹۹":(t=>{let e=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"];return t.toString().replace(/\d/g,t=>e[parseInt(t,10)])})(x)})]}),(null==m||null==(o=m.user)?void 0:o.id)&&(0,a.jsx)(p.cj,{open:v,onOpenChange:y,children:(0,a.jsxs)(p.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,a.jsx)("div",{className:"w-12 h-1.5 bg-gray-200 rounded-full mx-auto -mt-2 mb-3"}),(0,a.jsxs)(p.Fm,{className:"sr-only",children:[(0,a.jsx)(p.qp,{children:"مرکز اعلان‌ها"}),(0,a.jsx)(p.Qs,{children:"مشاهده و مدیریت اعلان‌های دریافتی"})]}),(0,a.jsx)("div",{className:"w-full",children:(0,a.jsx)(d.NotificationPanel,{userId:m.user.id,showCloseButton:!0,onClose:()=>y(!1),onNotificationRead:()=>{k()},className:"border-0 shadow-none p-0 bg-transparent"})})]})})]})}},96093:(t,e,o)=>{function a(t){return t?t.startsWith("http")?t:t.startsWith("/uploads/")?"https://asset.playmo.ir/public".concat(t):"https://asset.playmo.ir/public/uploads/avatars/".concat(t):null}function n(t){return t?t.startsWith("http")?t:t.startsWith("/uploads/")?"https://asset.playmo.ir/public".concat(t):"https://asset.playmo.ir/public/uploads/cafes/".concat(t):"/images/cafe-logo-placeholder.svg"}function s(t){return!t||Array.isArray(t)&&0===t.length?["/images/cafe-placeholder.svg"]:(Array.isArray(t)?t:[t]).map(t=>t?t.startsWith("http")?t:t.startsWith("/uploads/")?"https://asset.playmo.ir/public".concat(t):"https://asset.playmo.ir/public/uploads/cafes/".concat(t):"/images/cafe-placeholder.svg")}function i(t){return!t||Array.isArray(t)&&0===t.length?["/images/event-placeholder.svg"]:(Array.isArray(t)?t:[t]).map(t=>t?t.startsWith("http")?t:t.startsWith("/uploads/")?"https://asset.playmo.ir/public".concat(t):"https://asset.playmo.ir/public/uploads/events/".concat(t):"/images/event-placeholder.svg")}o.d(e,{EY:()=>n,Vd:()=>u,Wb:()=>s,cG:()=>a,eI:()=>l,i0:()=>c,zL:()=>i});let r={کارتی:"cards.jpg",card:"cards.jpg",خانوادگی:"family.jpg",family:"family.jpg",استراتژی:"strategy.jpg",استراتژیک:"strategy.jpg",strategy:"strategy.jpg",فان:"party.jpg",مهمانی:"party.jpg","فان / مهمانی":"party.jpg",پارتی:"party.jpg",party:"party.jpg",جنگی:"war.jpg",war:"war.jpg",دونفره:"couple2.jpg",رقابتی:"couple2.jpg","دونفره / رقابتی":"couple2.jpg",duel:"couple2.jpg",اقتصادی:"economy.jpg",مدیریتی:"economy.jpg","اقتصادی / مدیریتی":"economy.jpg",economic:"economy.jpg",economy:"economy.jpg",ماجراجویی:"adventure.jpg","هم کاری":"adventure.jpg",هم‌کاری:"adventure.jpg","ماجراجویی / هم‌کاری":"adventure.jpg",adventure:"adventure.jpg",فکری:"abstract.jpg",انتزاعی:"abstract.jpg","فکری / انتزاعی":"abstract.jpg",abstract:"abstract.jpg",حدسی:"hidden-role.jpg","نقش مخفی":"hidden-role.jpg",نقش‌مخفی:"hidden-role.jpg","حدسی / نقش‌مخفی":"hidden-role.jpg",deduction:"hidden-role.jpg"};function l(t){var e;if(!t)return null;let o=t.trim().replace(/[^\u0600-\u06FFa-z0-9\s-\/]/g,"").trim();if(!o)return null;let a=o.split("-")[0].trim();if(!a)return null;let n=r[a]||r[a.toLowerCase()]||(null==(e=Object.entries(r).find(t=>{let[e]=t;return e.toLowerCase()===a.toLowerCase()}))?void 0:e[1]);return n?"https://asset.playmo.ir/public/uploads/genre/".concat(n):(console.warn('[getGenreImageUrl] Genre not found in mapping: "'.concat(a,'" (original: "').concat(t,'")')),"https://asset.playmo.ir/public/uploads/genre/abstract.jpg")}function c(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"webp";if(!t)return"https://asset.playmo.ir/public/uploads/archetypes/default.".concat(e);if(t.startsWith("http"))return t;if(t.startsWith("/uploads/"))return"https://asset.playmo.ir/public".concat(t);let o=t.toLowerCase().replace(/_/g,"-");return o.endsWith(".png")||o.endsWith(".jpg")||o.endsWith(".webp")||o.endsWith(".svg")?"https://asset.playmo.ir/public/uploads/archetypes/".concat(o):"https://asset.playmo.ir/public/uploads/archetypes/".concat(o,".").concat(e)}function u(t){return!1}}}]);