T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.quebec/public_html/_next/static/chunks/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/public_html/_next/static/chunks/70.4f94446cfe5087eb.js
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[70],{15773:(e,t,r)=>{"use strict";var a=r(31059).Buffer,n=a.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function s(e){var t;switch(this.encoding=function(e){var t=function(e){var t;if(!e)return"utf8";for(;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(a.isEncoding===n||!n(e)))throw Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=l,this.end=c,t=4;break;case"utf8":this.fillLast=i,t=4;break;case"base64":this.text=d,this.end=u,t=3;break;default:this.write=m,this.end=h;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=a.allocUnsafe(t)}function o(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function i(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if((192&t[0])!=128)return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if((192&t[1])!=128)return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&(192&t[2])!=128)return e.lastNeed=2,"�"}}(this,e,0);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):void(e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length)}function l(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var a=r.charCodeAt(r.length-1);if(a>=55296&&a<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function c(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function d(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function u(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function m(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):""}t.StringDecoder=s,s.prototype.write=function(e){var t,r;if(0===e.length)return"";if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""},s.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},s.prototype.text=function(e,t){var r=function(e,t,r){var a=t.length-1;if(a<r)return 0;var n=o(t[a]);return n>=0?(n>0&&(e.lastNeed=n-1),n):--a<r||-2===n?0:(n=o(t[a]))>=0?(n>0&&(e.lastNeed=n-2),n):--a<r||-2===n?0:(n=o(t[a]))>=0?(n>0&&(2===n?n=0:e.lastNeed=n-3),n):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var a=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,a),e.toString("utf8",t,a)},s.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},18651:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>D});var a=r(37876),n=r(14232),s=r(10553),o=r(23042),i=r(67421),l=r(13075),c=r(81978),d=r(97685),u=r(87958);let m=e=>{var t,r;let{participant:l,roomId:c,onKick:d}=e,{data:u}=(0,s.useSession)(),[m,h]=(0,n.useState)(!1),g=(null==u||null==(t=u.user)?void 0:t.id)===l.user.id,p=(null==u||null==(r=u.user)?void 0:r.role)==="ADMIN";return g?null:(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("button",{onClick:()=>h(!m),className:"p-1 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-500",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{d:"M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z"})})}),(0,a.jsx)(o.N,{children:m&&(0,a.jsx)(i.P.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"absolute right-0 mt-2 w-48 bg-white dark:bg-gray-800 rounded-md shadow-lg z-10 border border-gray-200 dark:border-gray-700",children:(0,a.jsx)("ul",{className:"py-1",children:p&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("li",{className:"border-t border-gray-200 dark:border-gray-700 my-1"}),(0,a.jsx)("li",{children:(0,a.jsx)("button",{onClick:()=>{window.confirm("Are you sure you want to kick ".concat(l.user.name,"?"))&&d(l.user.id),h(!1)},className:"w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50",children:"Kick from Room"})})]})})})})]})};r(87818);let h=1e3,g=e=>{var t;let{chatId:r,onClose:o}=e;console.log("\uD83D\uDCDE [DirectMessage] Component initializing with chatId:",r);let{ws:c,markDirectMessagesAsRead:d,incomingVideoCall:m,acceptVideoCall:g}=(0,u.h)(),{data:p}=(0,s.useSession)(),x=(0,n.useRef)(null),f=(0,n.useRef)(null),y=(0,n.useRef)(null),[b,v]=(0,n.useState)([]),[w,j]=(0,n.useState)(""),[k,N]=(0,n.useState)(null),[C,E]=(0,n.useState)(!0),[D,R]=(0,n.useState)(null),[S,L]=(0,n.useState)(null),[T,M]=(0,n.useState)(null),[I,O]=(0,n.useState)(null),[A,F]=(0,n.useState)(!1),[P,_]=(0,n.useState)(null),[G,U]=(0,n.useState)(!1),[z,W]=(0,n.useState)({x:0,y:0}),[B,H]=(0,n.useState)(()=>{let e=Math.floor(100*Math.random())-50,t=Math.floor(100*Math.random())-50;return{x:Math.max(0,Math.min(window.innerWidth-400-16+e,window.innerWidth-400)),y:Math.max(0,Math.min(window.innerHeight-520-16+t,window.innerHeight-520))}}),[Y,J]=(0,n.useState)(()=>++h);console.log("\uD83D\uDCDE [DirectMessage] Initial state - recipientId:",r,"session:",null==p||null==(t=p.user)?void 0:t.name);let V=()=>{J(h+=1)},K=(0,n.useCallback)(e=>{if(!G)return;let t=e.clientX-z.x,r=e.clientY-z.y;H({x:t=Math.max(0,Math.min(t,window.innerWidth-384)),y:r=Math.max(0,Math.min(r,window.innerHeight-500))})},[G,z]),q=(0,n.useCallback)(()=>{U(!1)},[]);(0,n.useEffect)(()=>(G?(document.addEventListener("mousemove",K),document.addEventListener("mouseup",q),document.body.style.cursor="grabbing",document.body.style.userSelect="none"):(document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",q),document.body.style.cursor="",document.body.style.userSelect=""),()=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",q),document.body.style.cursor="",document.body.style.userSelect=""}),[G,K,q]),(0,n.useEffect)(()=>{r&&d&&d(r)},[r,d]),(0,n.useEffect)(()=>{if(!c)return;let e=e=>{try{let t=JSON.parse(e.data);switch(console.log("Direct message WebSocket received:",t),t.type){case"DIRECT_MESSAGE":(t.data.senderId===(null==p?void 0:p.user.id)&&t.data.recipientId===r||t.data.senderId===r&&t.data.recipientId===(null==p?void 0:p.user.id))&&(v(e=>[...e,t.data]),t.data.senderId===r&&d&&d(r));break;case"webrtc-offer":console.log("\uD83D\uDCDE Received webrtc-offer from:",t.senderId,"Expected from:",r);break;case"webrtc-answer":f.current&&t.senderId===r&&f.current.signal(t.data.signal);break;case"webrtc-ice-candidate":f.current&&t.senderId===r&&f.current.signal(t.data.candidate);break;case"webrtc-end-call":t.senderId===r&&Z();break;case"webrtc-error":t.recipientId===r&&(console.log("❌ WebRTC Error:",t.error,t.message),F(!1),Z(),"RECIPIENT_OFFLINE"===t.error?alert("Cannot start video call: ".concat((null==k?void 0:k.name)||"User"," is not currently online. Please try again when they are available.")):alert("Video call failed: ".concat(t.message)))}}catch(e){console.error("Error parsing direct message WebSocket:",e)}};return c.addEventListener("message",e),()=>c.removeEventListener("message",e)},[c,r,p,d]);let X=async()=>{if(r){E(!0);try{let e=await fetch("/api/chat/direct/".concat(r),{method:"GET",credentials:"same-origin"});if(!e.ok)throw Error("Failed to fetch chat history");let t=await e.json();v(t.messages||[]),N(t.participants.find(e=>e.id===r)||null)}catch(e){R("Failed to load chat history"),console.error(e)}finally{E(!1)}}};(0,n.useEffect)(()=>{X(),$()},[r]);let $=async()=>{if(r)try{let e=await fetch("/api/user/online-status/".concat(r));if(e.ok){let t=await e.json();L(t.isOnline)}}catch(e){console.warn("Error checking recipient online status:",e)}};(0,n.useEffect)(()=>{let e=setInterval($,3e4);return()=>clearInterval(e)},[r]);let Q=async()=>{if(!w.trim()||!c||!p)return;let e={id:"temp-".concat(Date.now()),content:w.trim(),senderId:p.user.id,recipientId:r,createdAt:new Date().toISOString(),type:"TEXT",sender:{id:p.user.id,name:p.user.name||"Me"},recipient:k||{id:r,name:"Unknown"}};v(t=>[...t,e]),j("");try{let t=await fetch("/api/chat/direct/".concat(r),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e.content,type:"TEXT"})});if(!t.ok)throw Error("Failed to send message");let a=await t.json();v(t=>t.map(t=>t.id===e.id?a:t)),c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:"DIRECT_MESSAGE",data:{...a,recipientId:r}}))}catch(t){console.error("Failed to send message:",t),v(t=>t.filter(t=>t.id!==e.id))}};(0,n.useEffect)(()=>{var e;null==(e=x.current)||e.scrollIntoView({behavior:"smooth"})},[b]);let Z=()=>{f.current&&(f.current.destroy(),f.current=null),T&&(T.getTracks().forEach(e=>e.stop()),M(null)),O(null),F(!1),_(null)};return C?(0,a.jsx)("div",{children:"Loading..."}):D?(0,a.jsxs)("div",{children:["Error: ",D]}):(0,a.jsxs)(i.P.div,{ref:y,initial:{opacity:0,y:50},animate:{opacity:1,y:0},exit:{opacity:0,y:50},className:"fixed w-96 h-[500px] bg-white dark:bg-gray-800 shadow-2xl rounded-lg flex flex-col",style:{left:B.x,top:B.y,zIndex:Y,cursor:G?"grabbing":"default"},onMouseDown:V,children:[(0,a.jsxs)("header",{className:"flex items-center justify-between p-4 border-b-2 border-blue-200 dark:border-blue-700 rounded-t-lg shadow-md cursor-grab active:cursor-grabbing select-none transition-colors ".concat(G?"bg-blue-100 dark:bg-blue-800":"bg-blue-50 dark:bg-blue-900 hover:bg-blue-100 dark:hover:bg-blue-800"),onMouseDown:e=>{var t;if(e.target.closest("button, input, .no-drag"))return;V(),U(!0);let r=null==(t=y.current)?void 0:t.getBoundingClientRect();r&&W({x:e.clientX-r.left,y:e.clientY-r.top})},children:[(0,a.jsxs)("h2",{className:"font-bold text-lg text-blue-800 dark:text-blue-200 flex items-center gap-2 pointer-events-none",children:["\uD83D\uDCAC Chat with ",(null==k?void 0:k.name)||"User",G&&(0,a.jsx)("span",{className:"text-sm opacity-75",children:"✋"})]}),(0,a.jsx)("div",{className:"flex items-center space-x-2 no-drag",children:(0,a.jsx)("button",{onClick:o,className:"p-1 rounded-full text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors no-drag",title:"Close Chat",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 no-drag",children:[0===b.length&&(0,a.jsxs)("div",{className:"text-center py-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-700",children:[(0,a.jsx)("div",{className:"mb-3",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 mx-auto text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-blue-800 dark:text-blue-200 mb-2",children:"Start Chatting"}),(0,a.jsxs)("p",{className:"text-xs text-blue-600 dark:text-blue-300",children:["Send a message to ",(null==k?void 0:k.name)||"this user"]})]}),b.map((e,t)=>{var r;let n=e.senderId===(null==p||null==(r=p.user)?void 0:r.id);return(0,a.jsx)(i.P.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"flex ".concat(n?"justify-end":"justify-start"," mb-2"),children:(0,a.jsxs)("div",{className:"px-4 py-2 rounded-lg ".concat(n?"bg-blue-500 text-white":"bg-gray-200 text-black"),children:[(0,a.jsx)("p",{children:e.content}),(0,a.jsx)("span",{className:"text-xs opacity-75",children:(0,l.GP)(new Date(e.createdAt),"HH:mm")})]})},e.id||t)}),(0,a.jsx)("div",{ref:x})]}),(0,a.jsx)("div",{className:"p-4 bg-white dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700 no-drag",children:(0,a.jsxs)("div",{className:"flex items-center bg-gray-100 dark:bg-gray-800 rounded-lg px-2 py-1 no-drag",children:[(0,a.jsx)("input",{type:"text",value:w,onChange:e=>j(e.target.value),onKeyPress:e=>"Enter"===e.key&&Q(),placeholder:"Type a message...",className:"flex-1 bg-transparent border-none focus:ring-0 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 no-drag"}),(0,a.jsx)("button",{onClick:Q,className:"px-3 py-2 bg-blue-500 hover:bg-blue-600 disabled:bg-gray-400 text-white rounded-lg transition-colors disabled:cursor-not-allowed no-drag",disabled:!w.trim()||!c,title:"Send Message",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]})})]})},p=()=>{let{connected:e,connectionState:t,connectionStats:r,reconnect:n}=(0,u.h)();return(0,a.jsxs)("div",{className:"flex items-center space-x-2 text-xs text-gray-600 dark:text-gray-400",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat((()=>{switch(t){case"connected":return"bg-green-500";case"connecting":return"bg-yellow-500 animate-pulse";case"reconnecting":return"bg-orange-500 animate-pulse";case"disconnected":return"bg-red-500";default:return"bg-gray-500"}})())}),(0,a.jsx)("span",{className:"font-medium",children:(()=>{switch(t){case"connected":return"Connected";case"connecting":return"Connecting...";case"reconnecting":return"Reconnecting... (".concat(r.reconnectAttempts,")");case"disconnected":return"Disconnected";default:return"Unknown"}})()})]}),"disconnected"===t&&r.reconnectAttempts>=10&&(0,a.jsx)("button",{onClick:n,className:"ml-2 px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors",children:"Reconnect"}),e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-gray-400",children:"•"}),(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("span",{children:"\uD83D\uDCF6"}),(0,a.jsx)("span",{children:"N/A"})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("span",{children:"\uD83D\uDCCA"}),(0,a.jsxs)("span",{children:["↑",r.messagesSent," ↓",r.messagesReceived]})]})]})]})]})},x=e=>{let{roomId:t}=e,[r,s]=(0,n.useState)(""),[o,i]=(0,n.useState)([]);return((0,n.useEffect)(()=>{let e=e=>{let r=e.detail;if("TYPING"===r.type&&r.data.roomId===t){let{userName:e,isTyping:t,timestamp:a}=r.data;i(r=>t?[...r.filter(t=>t.userName!==e),{userName:e,timestamp:a}]:r.filter(t=>t.userName!==e))}};window.addEventListener("websocket-message",e);let r=Date.now(),a=o.filter(e=>r-e.timestamp<5e3);return 0===a.length?s(""):1===a.length?s("".concat(a[0].userName," is typing...")):2===a.length?s("".concat(a[0].userName," and ").concat(a[1].userName," are typing...")):s("".concat(a[0].userName," and ").concat(a.length-1," others are typing...")),()=>{window.removeEventListener("websocket-message",e)}},[o,t]),r)?(0,a.jsxs)("div",{className:"px-4 py-2 text-sm text-gray-500 dark:text-gray-400 italic flex items-center space-x-2",children:[(0,a.jsxs)("div",{className:"flex space-x-1",children:[(0,a.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),(0,a.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),(0,a.jsx)("div",{className:"w-1 h-1 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),(0,a.jsx)("span",{children:r})]}):null},f={"Smileys & People":["\uD83D\uDE00","\uD83D\uDE03","\uD83D\uDE04","\uD83D\uDE01","\uD83D\uDE06","\uD83D\uDE05","\uD83D\uDE02","\uD83E\uDD23","\uD83D\uDE0A","\uD83D\uDE07","\uD83D\uDE42","\uD83D\uDE43","\uD83D\uDE09","\uD83D\uDE0C","\uD83D\uDE0D","\uD83E\uDD70","\uD83D\uDE18","\uD83D\uDE17","\uD83D\uDE19","\uD83D\uDE1A","\uD83D\uDE0B","\uD83D\uDE1B","\uD83D\uDE1D","\uD83D\uDE1C","\uD83E\uDD2A","\uD83E\uDD28","\uD83E\uDDD0","\uD83E\uDD13","\uD83D\uDE0E","\uD83E\uDD29","\uD83E\uDD73","\uD83D\uDE0F","\uD83D\uDE12","\uD83D\uDE1E","\uD83D\uDE14","\uD83D\uDE1F","\uD83D\uDE15","\uD83D\uDE41","☹️","\uD83D\uDE23","\uD83D\uDE16","\uD83D\uDE2B","\uD83D\uDE29","\uD83E\uDD7A","\uD83D\uDE22","\uD83D\uDE2D","\uD83D\uDE24","\uD83D\uDE20","\uD83D\uDE21","\uD83E\uDD2C","\uD83E\uDD2F","\uD83D\uDE33","\uD83E\uDD75","\uD83E\uDD76","\uD83D\uDE31","\uD83D\uDE28","\uD83D\uDE30","\uD83D\uDE25","\uD83D\uDE13","\uD83E\uDD17","\uD83E\uDD14","\uD83E\uDD2D","\uD83E\uDD2B","\uD83E\uDD25","\uD83D\uDE36","\uD83D\uDE10","\uD83D\uDE11","\uD83D\uDE2C","\uD83D\uDE44","\uD83D\uDE2F","\uD83D\uDE26","\uD83D\uDE27","\uD83D\uDE2E","\uD83D\uDE32","\uD83E\uDD71","\uD83D\uDE34","\uD83E\uDD24","\uD83D\uDE2A","\uD83D\uDE35","\uD83E\uDD10","\uD83E\uDD74","\uD83E\uDD22","\uD83E\uDD2E","\uD83E\uDD27","\uD83D\uDE37","\uD83E\uDD12","\uD83E\uDD15"],"Hearts & Love":["❤️","\uD83E\uDDE1","\uD83D\uDC9B","\uD83D\uDC9A","\uD83D\uDC99","\uD83D\uDC9C","\uD83D\uDDA4","\uD83E\uDD0D","\uD83E\uDD0E","\uD83D\uDC94","❣️","\uD83D\uDC95","\uD83D\uDC9E","\uD83D\uDC93","\uD83D\uDC97","\uD83D\uDC96","\uD83D\uDC98","\uD83D\uDC9D","\uD83D\uDC9F"],Gestures:["\uD83D\uDC4D","\uD83D\uDC4E","\uD83D\uDC4C","\uD83E\uDD0C","\uD83E\uDD0F","✌️","\uD83E\uDD1E","\uD83E\uDD1F","\uD83E\uDD18","\uD83E\uDD19","\uD83D\uDC48","\uD83D\uDC49","\uD83D\uDC46","\uD83D\uDD95","\uD83D\uDC47","☝️","\uD83D\uDC4F","\uD83D\uDE4C","\uD83D\uDC50","\uD83E\uDD32","\uD83E\uDD1D","\uD83D\uDE4F"],Celebrations:["\uD83C\uDF89","\uD83C\uDF8A","\uD83E\uDD73","\uD83C\uDF88","\uD83C\uDF81","\uD83C\uDFC6","\uD83E\uDD47","\uD83C\uDF96️","\uD83C\uDFC5","⭐","\uD83C\uDF1F","✨","\uD83D\uDD25","\uD83D\uDCAF"],Objects:["\uD83D\uDCAC","\uD83D\uDCAD","\uD83D\uDCA1","\uD83D\uDC8E","\uD83D\uDD14","\uD83D\uDCE2","\uD83D\uDCE3","\uD83D\uDCEF","\uD83C\uDFAF","\uD83C\uDFAA","\uD83C\uDFAD","\uD83C\uDFA8","\uD83C\uDFAC","\uD83D\uDCF7","\uD83D\uDCF1","\uD83D\uDCBB","⌚","\uD83D\uDCDA","\uD83D\uDCD6","\uD83D\uDCDD","✏️","\uD83D\uDD8A️"],Nature:["\uD83C\uDF1E","\uD83C\uDF19","⭐","\uD83C\uDF1F","☀️","⛅","\uD83C\uDF24️","☁️","\uD83C\uDF26️","\uD83C\uDF27️","⛈️","\uD83C\uDF29️","❄️","\uD83D\uDD25","\uD83D\uDCA7","\uD83C\uDF0A","\uD83C\uDF0D","\uD83C\uDF0E","\uD83C\uDF0F","\uD83C\uDF38","\uD83C\uDF3A","\uD83C\uDF3B","\uD83C\uDF37","\uD83C\uDF39","\uD83C\uDF34","\uD83C\uDF32","\uD83C\uDF33"]};function y(e){return({"\uD83D\uDE00":"grinning face","\uD83D\uDE03":"grinning face with big eyes","\uD83D\uDE04":"grinning face with smiling eyes","\uD83D\uDE01":"beaming face with smiling eyes","\uD83D\uDE06":"grinning squinting face","\uD83D\uDE05":"grinning face with sweat","\uD83D\uDE02":"face with tears of joy","\uD83E\uDD23":"rolling on the floor laughing","\uD83D\uDE0A":"smiling face with smiling eyes","\uD83D\uDE0D":"smiling face with heart-eyes","\uD83E\uDD70":"smiling face with hearts","\uD83D\uDE18":"face blowing a kiss","\uD83D\uDC4D":"thumbs up","\uD83D\uDC4E":"thumbs down","❤️":"red heart","\uD83C\uDF89":"party popper","\uD83D\uDD25":"fire","\uD83D\uDCAF":"hundred points symbol"})[e]||e}function b(){try{let e=localStorage.getItem("recentEmojis");return e?JSON.parse(e):["\uD83D\uDC4D","❤️","\uD83D\uDE02","\uD83C\uDF89"]}catch(e){return["\uD83D\uDC4D","❤️","\uD83D\uDE02","\uD83C\uDF89"]}}function v(e){try{let t=b().filter(t=>t!==e),r=[e,...t].slice(0,8);localStorage.setItem("recentEmojis",JSON.stringify(r))}catch(e){}}let w=e=>{let{onEmojiSelect:t,isOpen:r,onClose:s,position:l="bottom"}=e,[c,d]=(0,n.useState)("Smileys & People"),[u,m]=(0,n.useState)(""),h=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&s()},t=e=>{"Escape"===e.key&&s()};return r&&(document.addEventListener("mousedown",e),document.addEventListener("keydown",t)),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[r,s]);let g=u?Object.values(f).flat().filter(e=>e.includes(u)||y(e).toLowerCase().includes(u.toLowerCase())):f[c],p=e=>{t(e)};return(0,a.jsx)(o.N,{children:r&&(0,a.jsxs)(i.P.div,{ref:h,initial:{opacity:0,scale:.9,y:"top"===l?10:-10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:"top"===l?10:-10},transition:{duration:.15},className:"absolute z-50 w-80 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-xl ".concat("top"===l?"bottom-full mb-2":"top-full mt-2"),children:[(0,a.jsx)("div",{className:"p-3 border-b border-gray-200 dark:border-gray-700",children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("input",{type:"text",placeholder:"Search emojis...",value:u,onChange:e=>m(e.target.value),className:"flex-1 px-3 py-2 bg-gray-100 dark:bg-gray-700 border-0 rounded-md text-sm focus:ring-2 focus:ring-blue-500 focus:outline-none",autoFocus:!0}),(0,a.jsx)("button",{type:"button",onClick:s,className:"p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 rounded transition-colors",title:"Close",children:(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),!u&&(0,a.jsx)("div",{className:"flex overflow-x-auto border-b border-gray-200 dark:border-gray-700",children:Object.keys(f).map(e=>(0,a.jsx)("button",{onClick:()=>d(e),className:"px-3 py-2 text-xs font-medium whitespace-nowrap border-b-2 transition-colors ".concat(c===e?"border-blue-500 text-blue-600 dark:text-blue-400":"border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:e.split(" ")[0]},e))}),(0,a.jsxs)("div",{className:"p-2 max-h-64 overflow-y-auto",children:[(0,a.jsx)("div",{className:"grid grid-cols-8 gap-1",children:g.map((e,t)=>(0,a.jsx)("button",{type:"button",onClick:t=>{t.preventDefault(),t.stopPropagation(),p(e)},className:"p-2 text-xl hover:bg-gray-100 dark:hover:bg-gray-700 rounded transition-colors",title:y(e),children:e},"".concat(e,"-").concat(t)))}),0===g.length&&(0,a.jsx)("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:(0,a.jsx)("p",{className:"text-sm",children:"No emojis found"})})]}),(0,a.jsx)("div",{className:"border-t border-gray-200 dark:border-gray-700 p-2",children:(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium",children:"Recent:"}),b().map((e,t)=>(0,a.jsx)("button",{type:"button",onClick:t=>{t.preventDefault(),t.stopPropagation(),p(e)},className:"p-1 text-lg hover:bg-gray-100 dark:hover:bg-gray-700 rounded",title:y(e),children:e},"recent-".concat(e,"-").concat(t)))]})})]})})},j=e=>{let{messageId:t,reactions:r,onAddReaction:l,onRemoveReaction:c,className:d=""}=e,{data:u}=(0,s.useSession)(),[m,h]=(0,n.useState)(null),[g,p]=(0,n.useState)(!1),x=r.reduce((e,t)=>(e[t.emoji]||(e[t.emoji]=[]),e[t.emoji].push(t),e),{}),f=e=>{var r,a;(null==u||null==(r=u.user)?void 0:r.id)&&((null==(a=x[e])?void 0:a.find(e=>e.userId===u.user.id))?c(t,e):l(t,e))},y=(e,t)=>{let r=t.map(e=>e.user.name);return 1===r.length?"".concat(r[0]," reacted with ").concat(e):2===r.length?"".concat(r[0]," and ").concat(r[1]," reacted with ").concat(e):r.length<=5?"".concat(r.slice(0,-1).join(", ")," and ").concat(r[r.length-1]," reacted with ").concat(e):"".concat(r.slice(0,3).join(", ")," and ").concat(r.length-3," others reacted with ").concat(e)};return(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1 mt-1 ".concat(d),children:[(0,a.jsx)(o.N,{children:Object.entries(x).map(e=>{var t;let[r,n]=e,s=(null==u||null==(t=u.user)?void 0:t.id)&&n.some(e=>e.userId===u.user.id);return(0,a.jsxs)(i.P.button,{initial:{scale:0},animate:{scale:1},exit:{scale:0},whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>f(r),onMouseEnter:()=>h(r),onMouseLeave:()=>h(null),className:"\n                relative inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium\n                transition-all duration-200 border\n                ".concat(s?"bg-blue-100 dark:bg-blue-900/30 border-blue-300 dark:border-blue-600 text-blue-700 dark:text-blue-300":"bg-gray-100 dark:bg-gray-700 border-gray-200 dark:border-gray-600 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600","\n              "),title:y(r,n),children:[(0,a.jsx)("span",{className:"text-sm",children:r}),(0,a.jsx)("span",{className:"text-xs font-medium",children:n.length}),(0,a.jsx)(o.N,{children:m===r&&(0,a.jsx)(i.P.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},exit:{opacity:0,y:5},transition:{duration:.15},className:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 z-10",children:(0,a.jsxs)("div",{className:"bg-gray-900 dark:bg-gray-700 text-white text-xs rounded-lg px-3 py-2 whitespace-nowrap max-w-xs",children:[y(r,n),(0,a.jsx)("div",{className:"absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-gray-900 dark:border-t-gray-700"})]})})})]},r)})}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(i.P.button,{onClick:()=>p(!g),className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors opacity-60 hover:opacity-100",whileHover:{scale:1.1},whileTap:{scale:.95},title:"Add reaction",children:(0,a.jsx)("span",{className:"text-xs",children:"+"})}),(0,a.jsx)(w,{isOpen:g,onClose:()=>p(!1),onEmojiSelect:e=>{l(t,e),v(e),p(!1)},position:"top"})]})]})};var k=r(96488),N=r(94594),C=r(62334);let E=e=>{let{count:t=1,className:r="h-10 w-full"}=e;return(0,a.jsx)(a.Fragment,{children:[...Array(t)].map((e,t)=>(0,a.jsx)("div",{className:"bg-gray-200 dark:bg-gray-700 rounded animate-pulse ".concat(r)},t))})},D=()=>{var e,t,r,h,f,y,b,D,R;let{data:S}=(0,s.useSession)(),{ws:L,connected:T,sendTyping:M,joinRoom:I,leaveRoom:O,connectionState:A,directMessageNotifications:F,getTotalUnreadDirectMessages:P,reconnect:_}=(0,u.h)(),{toast:G}=(0,c.dj)();(0,n.useEffect)(()=>{var e,t;if(console.log("[GroupChat] \uD83D\uDD0C WebSocket status changed:",{hasWs:!!L,connected:T,connectionState:A,readyState:null==L?void 0:L.readyState,sessionUser:null==S||null==(e=S.user)?void 0:e.name}),"disconnected"===A&&(null==S||null==(t=S.user)?void 0:t.id)&&!T){let e=setTimeout(()=>{console.log("[GroupChat] \uD83D\uDD04 Auto-retrying WebSocket connection..."),_()},3e3);return()=>clearTimeout(e)}},[L,T,A,null==S||null==(e=S.user)?void 0:e.name,null==S||null==(t=S.user)?void 0:t.id,_]),(0,n.useEffect)(()=>{"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission().then(e=>{console.log("[GroupChat] Notification permission:",e)})},[]);let[U,z]=(0,n.useState)([]),[W,B]=(0,n.useState)(null),[H,Y]=(0,n.useState)([]),[J,V]=(0,n.useState)(""),[K,q]=(0,n.useState)(!0),[X,$]=(0,n.useState)(!1),[Q,Z]=(0,n.useState)(!0),[ee,et]=(0,n.useState)(new Set),[er,ea]=(0,n.useState)(!1),[en,es]=(0,n.useState)(!1),[eo,ei]=(0,n.useState)(""),[el,ec]=(0,n.useState)(!1),[ed,eu]=(0,n.useState)([]),em=(0,n.useRef)(null),eh=(0,n.useRef)(W),eg=(0,n.useRef)(new Set);(0,n.useRef)(null);let[ep,ex]=(0,n.useState)({open:!1,registrationId:null}),ef=(0,n.useRef)(null),[ey,eb]=(0,n.useState)(!0),[ev,ew]=(0,n.useState)(null),[ej,ek]=(0,n.useState)(null),[eN,eC]=(0,n.useState)(!1),[eE,eD]=(0,n.useState)(null),[eR,eS]=(0,n.useState)(!1),[eL,eT]=(0,n.useState)(null),[eM,eI]=(0,n.useState)(null),[eO,eA]=(0,n.useState)(!1),[eF,eP]=(0,n.useState)(!1),[e_,eG]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>{let e=window.innerWidth<768;eG(e),e||(eA(!1),eP(!1))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,n.useEffect)(()=>{eh.current=W},[W]),(0,n.useEffect)(()=>{eH()},[]),(0,n.useEffect)(()=>{(null==W?void 0:W.id)?(console.log("[GroupChat] \uD83C\uDFAF Room selected: ".concat(W.name," (").concat(W.id,")")),eY(W.id)):(console.log("[GroupChat] \uD83C\uDFAF No room selected, clearing messages"),Y([]))},[null==W?void 0:W.id]);let eU=()=>{if(!ef.current)return!0;let{scrollTop:e,scrollHeight:t,clientHeight:r}=ef.current;return e+r>=t-10};(0,n.useEffect)(()=>{ey&&em.current&&em.current.scrollIntoView({behavior:"auto",block:"end"})},[H,ey]),(0,n.useEffect)(()=>{eb(!0)},[W]),(0,n.useEffect)(()=>{eL?console.log("\uD83D\uDD04 Reply mode activated for message:",eL.id,"by user:",eL.user.name):console.log("\uD83D\uDD04 Reply mode deactivated")},[eL]);let ez=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"SYSTEM",r={id:"system-".concat(Date.now()),content:e,createdAt:new Date().toISOString(),user:{id:"system",name:"System"},chatRoomId:(null==W?void 0:W.id)||"local",type:t};Y(e=>[...e,r])},eW=async e=>{if(!S)return void ez("You must be logged in to use commands.","ERROR");let[t,...r]=e.substring(1).split(" "),a=r.join(" "),[n,...s]=r,o=s.join(" ");switch(t.toLowerCase()){case"help":ez("--- Help ---"),ez("/help - Shows this help message."),ez("/clear - Clears the current chat window."),ez("/switch <room_name> - Switches to a specified room."),ez("/part - Leaves the current room."),ez("/list - Lists all available rooms."),ez("/msg <user_name> <message> - Sends a private message."),ez("/me <action> - Performs an action message."),"ADMIN"===S.user.role&&(ez("--- Admin Commands ---"),ez("/createroom <room_name> - Creates a new room."),ez("/kick <user_name> [reason] - Kicks a user from the room."));break;case"clear":Y([]);break;case"list":ez("Available rooms:"),U.forEach(e=>{ez("#".concat(e.name," - ").concat(e.participants.length," users"))});break;case"createroom":if("ADMIN"!==S.user.role)return void ez("Error: You do not have permission to create rooms.","ERROR");if(!a)return void ez("Usage: /createroom <room_name>","ERROR");await eK(void 0,a);break;case"switch":case"join":{if(!a)return void ez("Usage: /switch <room_name>","ERROR");let e=U.find(e=>e.name.toLowerCase()===a.toLowerCase());e?(B(e),ez("Switched to room: ".concat(e.name))):ez('Room "'.concat(a,'" not found.'),"ERROR");break}case"part":W?(ez("You have left room: ".concat(W.name)),B(null)):ez("You are not in a room.","ERROR");break;case"kick":{if("ADMIN"!==S.user.role)return void ez("Error: You do not have permission to kick users.","ERROR");if(!W)return void ez("Error: You must be in a room to kick a user.","ERROR");if(!n)return void ez("Usage: /kick <user_name> [reason]","ERROR");let e=ed.find(e=>e.user.name.toLowerCase()===n.toLowerCase());if(!e)return void ez('Error: User "'.concat(n,'" not found in this room.'),"ERROR");try{let t=await fetch("/api/chat/rooms/".concat(W.id,"/participants/").concat(e.user.id),{method:"DELETE",credentials:"same-origin"}),r=await t.json();if(!t.ok)throw Error(r.error||"Failed to kick user.")}catch(e){eB(e instanceof Error?e.message:"An unknown error occurred.")}break}case"msg":case"query":{if(!n||!o)return void ez("Usage: /msg <user_name> <message>","ERROR");let e=null;for(let t of U){let r=t.participants.find(e=>e.user.name.toLowerCase()===n.toLowerCase());if(r){e=r.user;break}}if(!e)return void ez('Error: User "'.concat(n,'" not found.'),"ERROR");if(e.id===S.user.id)return void ez("You cannot send a private message to yourself.","ERROR");try{if(!(await fetch("/api/chat/direct/".concat(e.id),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:o})})).ok)throw Error("Failed to send private message.");ez("Message sent to ".concat(e.name,": ").concat(o))}catch(e){eB(e instanceof Error?e.message:"An unknown error occurred.")}break}case"me":{if(!a)return void ez("Usage: /me <action>","ERROR");if(!W)return void ez("You must be in a room to perform an action.","ERROR");let e="optimistic-".concat(Date.now()),t="* ".concat(S.user.name," ").concat(a),r={id:e,content:t,createdAt:new Date().toISOString(),user:S.user,chatRoomId:W.id,isOptimistic:!0,isAction:!0};Y(e=>[...e,r]);try{await fetch("/api/chat/group/messages",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,chatRoomId:W.id,isAction:!0})})}catch(t){eB(t instanceof Error?t.message:"An unknown error occurred."),Y(t=>t.filter(t=>t.id!==e))}break}default:ez("Unknown command: /".concat(t,". Type /help for a list of commands."),"ERROR")}},eB=(0,n.useCallback)((e,t)=>{console.error(e,t),G({title:e,description:t,variant:"destructive"})},[G]);(0,n.useEffect)(()=>{if(!L)return;let e=e=>{try{var t,r,n;let s=JSON.parse(e.data);switch(console.log("[GroupChat] \uD83D\uDCE5 WebSocket message received:",s.type,s),s.type){case"CHAT_MESSAGE":if(console.log("[GroupChat] \uD83D\uDCAC Processing chat message for room ".concat(s.data.chatRoomId,", current room: ").concat(null==W?void 0:W.id)),console.log("[GroupChat] \uD83D\uDCDD Message data:",s.data),s.data.user.id!==(null==S||null==(t=S.user)?void 0:t.id)){let e=s.data.chatRoomId===(null==W?void 0:W.id),t=!document.hidden,n=(null==(r=U.find(e=>e.id===s.data.chatRoomId))?void 0:r.name)||"Chat Room";e&&t||((0,d.oR)(e=>{var t;return(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsx)("div",{className:"flex-shrink-0",children:(0,a.jsx)("div",{className:"w-8 h-8 bg-green-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("span",{className:"text-white text-sm font-bold",children:(null==(t=s.data.user.name)?void 0:t.charAt(0))||"U"})})}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsxs)("p",{className:"font-medium text-gray-900",children:["\uD83D\uDCAC ",s.data.user.name," in #",n]}),(0,a.jsx)("p",{className:"text-sm text-gray-600 truncate max-w-48",children:s.data.content})]}),(0,a.jsx)("button",{onClick:()=>{d.oR.dismiss(e.id);let t=U.find(e=>e.id===s.data.chatRoomId);t&&e5(t)},className:"flex-shrink-0 bg-green-500 text-white px-3 py-1 rounded text-sm hover:bg-green-600",children:"View"})]})},{duration:5e3,position:"top-right",style:{maxWidth:"400px"}}),"granted"===Notification.permission&&new Notification("New message in #".concat(n),{body:"".concat(s.data.user.name,": ").concat(s.data.content),icon:"/icons/apple-touch-icon-180x180.png"}),console.log("[GroupChat] \uD83D\uDD14 Notification shown for message from ".concat(s.data.user.name," in room ").concat(n)))}s.data.chatRoomId===(null==W?void 0:W.id)?(console.log("[GroupChat] ✅ Adding message to current room"),Y(e=>{if(e.find(e=>e.id===s.data.id))return console.log("[GroupChat] \uD83D\uDD04 Message already exists, skipping duplicate"),e;let t=e.find(e=>e.isOptimistic&&e.content===s.data.content&&5e3>Math.abs(new Date(e.createdAt).getTime()-new Date(s.data.createdAt).getTime()));if(t)return console.log("[GroupChat] \uD83D\uDD04 Updating optimistic message"),e.map(e=>e.id===t.id?{...s.data,isOptimistic:!1}:e);console.log("[GroupChat] ➕ Adding new message to chat");let r=[...e,s.data];return console.log("[GroupChat] \uD83D\uDCCA Total messages now: ".concat(r.length)),r})):console.log("[GroupChat] ⏭️ Message for different room (".concat(s.data.chatRoomId,"), skipping")),z(e=>e.map(e=>{var t;return e.id===s.data.chatRoomId?{...e,lastMessage:s.data,_count:{...e._count,messages:((null==(t=e._count)?void 0:t.messages)||0)+1}}:e}));break;case"ROOM_CREATED":let o=s.room;z(e=>[o,...e]);try{L&&L.readyState===WebSocket.OPEN&&L.send(JSON.stringify({type:"JOIN_ROOM",data:{chatRoomId:o.id}}))}catch(e){console.error("Failed to send JOIN_ROOM for new room:",e)}G({title:"New Room Created",description:'You were added to "'.concat(o.name,'".')});break;case"TYPING":s.data.chatRoomId===(null==W?void 0:W.id)&&et(e=>{let t=new Set(e);return s.data.isTyping?t.add(s.data.userName):t.delete(s.data.userName),t});break;case"USER_KICKED":s.chatRoomId===(null==W?void 0:W.id)&&(s.userId===(null==S||null==(n=S.user)?void 0:n.id)&&(ez("You have been kicked from the room by ".concat(s.kickedBy,"."),"ERROR"),(null==W?void 0:W.id)===s.chatRoomId&&B(null)),z(e=>e.map(e=>e.id===s.chatRoomId?{...e,participants:e.participants.filter(e=>e.user.id!==s.userId)}:e)));break;case"PARTICIPANT_LIST_UPDATE":s.data.chatRoomId===(null==W?void 0:W.id)&&eu(s.data.participants)}}catch(e){console.error("Failed to parse WebSocket message:",e)}};return L.addEventListener("message",e),()=>L.removeEventListener("message",e)},[L,null==W?void 0:W.id,null==S||null==(r=S.user)?void 0:r.id,G,ez,U]),(0,n.useEffect)(()=>{L&&T&&(console.log("[GroupChat] WebSocket connected, clearing joined rooms ref to ensure re-joining"),eg.current.clear())},[L,T]);let eH=async()=>{q(!0);try{console.log("[GroupChat] \uD83D\uDD04 Fetching chat rooms...");let e=await fetch("/api/chat/rooms",{method:"GET",credentials:"same-origin",headers:{"Content-Type":"application/json"}});if(!e.ok){if(401===e.status)return void ez("Authentication required. Please log in again.","ERROR");let t=await e.json().catch(()=>({error:"Unknown error"}));throw Error(t.error||"HTTP ".concat(e.status,": Failed to fetch chat rooms"))}let t=await e.json();if(console.log("[GroupChat] \uD83D\uDCCB Fetched chat rooms:",t.map(e=>{var t;return{id:e.id,name:e.name,messageCount:null==(t=e._count)?void 0:t.messages}})),!t||0===t.length){console.log("[GroupChat] ⚠️ No chat rooms found"),ez("No chat rooms available. Please contact an administrator.","ERROR"),z([]);return}z(t),console.log("[GroupChat] \uD83D\uDCCB Chat rooms loaded. Users will join rooms on selection for better performance.")}catch(t){console.error("[GroupChat] ❌ Error fetching chat rooms:",t);let e=t instanceof Error?t.message:"Failed to load chat rooms";ez("Error: ".concat(e),"ERROR"),z([])}finally{q(!1)}},eY=(0,n.useCallback)(async function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{var a,n;console.log("[GroupChat] \uD83D\uDD04 Fetching messages for room: ".concat(e).concat(t?" (cursor: ".concat(t,")"):"")),$(!0);let s=new URL("/api/chat/group/messages",window.location.origin);s.searchParams.set("chatRoomId",e),s.searchParams.set("limit","50"),t&&s.searchParams.set("cursor",t);let o=await fetch(s.toString(),{method:"GET",credentials:"same-origin",headers:{"Content-Type":"application/json"}});if(!o.ok){let e=await o.json().catch(()=>({error:"Unknown error"}));throw Error(e.error||"HTTP ".concat(o.status,": Failed to fetch messages"))}let i=await o.json();console.log("[GroupChat] \uD83D\uDCCB Fetched ".concat((null==(a=i.messages)?void 0:a.length)||0," messages for room ").concat(e," (hasMore: ").concat(null==(n=i.pagination)?void 0:n.hasMore,")")),r?Y(e=>[...i.messages||[],...e]):Y(i.messages||[]),i.pagination&&console.log("[GroupChat] \uD83D\uDCCA Pagination info:",i.pagination)}catch(t){console.error("[GroupChat] ❌ Error fetching messages for room ".concat(e,":"),t),ez("Failed to load chat history: ".concat(t instanceof Error?t.message:"Unknown error"),"ERROR"),r||Y([])}finally{$(!1)}},[]);(0,n.useEffect)(()=>{S&&eH()},[S]),(0,n.useEffect)(()=>{W&&eY(W.id)},[W,eY]);let eJ=(0,n.useCallback)(e=>{W&&M&&(ea(e),M(W.id,e))},[W,M]),eV=async e=>{if(e.preventDefault(),(J.trim()||eE)&&W&&S){if(console.log("[GroupChat] \uD83D\uDCE4 Sending message to room ".concat(W.id,":"),J.trim()),J.startsWith("/")&&!eE){await eW(J),V("");return}if(!W){ez("You must be in a room to send a message.","ERROR"),V("");return}try{let e={};if(eE){eS(!0);let t=new FormData;t.append("file",eE);let r=await fetch("/api/chat/upload",{method:"POST",body:t});if(!r.ok)throw Error("Failed to upload file");e=await r.json(),eD(null),eS(!1)}let t={content:J.trim()||e.fileName||"File attachment",chatRoomId:W.id,type:eE?eE.type.startsWith("image/")?"IMAGE":"FILE":"TEXT",replyToId:null==eL?void 0:eL.id,...e},r="optimistic-".concat(Date.now()),a={id:r,content:t.content,createdAt:new Date().toISOString(),user:S.user,chatRoomId:W.id,isOptimistic:!0,fileUrl:e.fileUrl,fileName:e.fileName,fileSize:e.fileSize,mimeType:e.mimeType,replyToId:null==eL?void 0:eL.id,replyTo:eL?{id:eL.id,content:eL.content,user:eL.user}:void 0};console.log("[GroupChat] \uD83C\uDFAF Adding optimistic message:",a),Y(e=>[...e,a]),V(""),eT(null),eC(!1),eJ(!1),console.log("[GroupChat] \uD83D\uDE80 Sending API request...");let n=await fetch("/api/chat/group/messages",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error("Message failed to send.");let s=await n.json();console.log("[GroupChat] ✅ Message saved to database:",s),Y(e=>e.map(e=>e.id===r?{...s,isOptimistic:!1}:e))}catch(e){console.error("[GroupChat] ❌ Error sending message:",e),eB(e instanceof Error?e.message:"An unknown error occurred."),eS(!1),Y(e=>e.filter(e=>e.id&&!e.id.startsWith("optimistic-")))}}},eK=async(e,t)=>{e&&e.preventDefault();let r=t||eo;if(r.trim()&&(null==S?void 0:S.user)){ec(!0);try{let t=await fetch("/api/chat/rooms",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim()})});if(!t.ok)throw Error("Failed to create room");let a=await t.json();e||ez('Room "'.concat(a.name,'" has been created.')),B(a),ei(""),es(!1),G({title:"Room Created",description:'"'.concat(a.name,'" has been created successfully.')})}catch(e){eB(e instanceof Error?e.message:"Failed to create room")}finally{ec(!1)}}},eq=async(e,t)=>{if(window.confirm('Are you sure you want to delete the room "'.concat(t,'"? This action cannot be undone.')))try{let r=await fetch("/api/chat/rooms?roomId=".concat(e),{method:"DELETE",credentials:"same-origin"});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to delete room")}G({title:"Room Deleted",description:'"'.concat(t,'" has been permanently deleted.')}),z(t=>t.filter(t=>t.id!==e)),(null==W?void 0:W.id)===e&&B(null)}catch(e){eB(e instanceof Error?e.message:"Failed to delete room")}},eX=async e=>{if(W)try{let t=await fetch("/api/admin/chat/participants?roomId=".concat(W.id,"&userId=").concat(e),{method:"DELETE",credentials:"same-origin"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to kick user")}z(t=>t.map(t=>t.id===W.id?{...t,participants:t.participants.filter(t=>t.user.id!==e)}:t)),G({title:"User Kicked",description:"The user has been removed from the room."})}catch(e){eB(e instanceof Error?e.message:"An unknown error occurred.")}},e$=(e,t)=>{var r;if(e===(null==S||null==(r=S.user)?void 0:r.id))return void ez("You cannot start a private chat with yourself.","ERROR");ek({recipientId:e,recipientName:t})},eQ=(0,n.useCallback)(async(e,t)=>{try{console.log("Adding reaction:",{messageId:e,emoji:t});let r=await fetch("/api/chat/group/reactions",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({messageId:e,emoji:t})});if(r.ok){let a=await r.json();console.log("Reaction added successfully:",a),Y(t=>t.map(t=>t.id===e?{...t,reactions:[...t.reactions||[],a]}:t)),v(t)}else{let e=await r.text();console.error("Failed to add reaction:",r.status,e),G({title:"Failed to add reaction",description:"Please try again",variant:"destructive"})}}catch(e){console.error("Failed to add reaction:",e),G({title:"Failed to add reaction",description:"Please try again",variant:"destructive"})}},[G]),eZ=(0,n.useCallback)(async(e,t)=>{try{console.log("Removing reaction:",{messageId:e,emoji:t});let r=await fetch("/api/chat/group/reactions?messageId=".concat(e,"&emoji=").concat(t),{method:"DELETE",credentials:"same-origin"});if(r.ok)console.log("Reaction removed successfully"),Y(r=>r.map(r=>r.id===e?{...r,reactions:(r.reactions||[]).filter(e=>{var r;return e.emoji!==t||e.userId!==(null==S||null==(r=S.user)?void 0:r.id)})}:r));else{let e=await r.text();console.error("Failed to remove reaction:",r.status,e),G({title:"Failed to remove reaction",description:"Please try again",variant:"destructive"})}}catch(e){console.error("Failed to remove reaction:",e),G({title:"Failed to remove reaction",description:"Please try again",variant:"destructive"})}},[G]),e0=e=>{V(t=>t+e),v(e)},e1=(e,t)=>{var r;(null==(r=e.reactions)?void 0:r.some(e=>{var r;return e.emoji===t&&e.userId===(null==S||null==(r=S.user)?void 0:r.id)}))?eZ(e.id,t):eQ(e.id,t)},e2=e=>{if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(1))+" "+["B","KB","MB","GB"][t]},e4=n.memo(e=>{var t,r,n,s,o,i,c,d,u,m,h,g,p,x;let{message:f}=e,y=(0,l.GP)(new Date(f.createdAt),"HH:mm");if("SYSTEM"===f.type||"ERROR"===f.type)return(0,a.jsxs)("div",{className:"text-sm py-1 px-4 ".concat("ERROR"===f.type?"text-red-500":"text-gray-500 dark:text-gray-400"),children:[(0,a.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 mr-2",children:["[",y,"]"]}),(0,a.jsxs)("span",{className:"italic",children:["-- ",f.content]})]},f.id);if(f.isAction)return(0,a.jsxs)("div",{className:"text-sm py-1 px-4 text-purple-600 dark:text-purple-400 italic",children:[(0,a.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 mr-2",children:["[",y,"]"]}),(0,a.jsx)("span",{children:f.content})]},f.id);let b=(null==(t=f.user)?void 0:t.name)||"Unknown User",v=(null==(r=f.user)?void 0:r.id)===(null==S||null==(n=S.user)?void 0:n.id),w=f.fileUrl&&((null==(s=f.mimeType)?void 0:s.startsWith("image/"))||/\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i.test(f.fileName||""));return(0,a.jsxs)("div",{className:"group text-sm py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-800/50",children:[f.replyTo&&(0,a.jsx)("div",{className:"mb-1 ml-16 p-2 bg-gray-100 dark:bg-gray-700 rounded border-l-4 border-blue-500 text-xs",children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[f.replyTo.fileUrl&&(null==(o=f.replyTo.mimeType)?void 0:o.startsWith("image/"))&&(0,a.jsx)("img",{src:f.replyTo.fileUrl,alt:"Reply thumbnail",className:"w-8 h-8 object-cover rounded border flex-shrink-0"}),(0,a.jsxs)("span",{className:"text-gray-600 dark:text-gray-400 flex-1",children:["Replying to ",f.replyTo.user.name,":"," ",f.replyTo.fileUrl?(null==(i=f.replyTo.mimeType)?void 0:i.startsWith("image/"))?(0,a.jsx)("span",{className:"italic",children:"\uD83D\uDCF7 Image"}):(0,a.jsx)("span",{className:"italic",children:"\uD83D\uDCCE File attachment"}):(0,a.jsxs)(a.Fragment,{children:[f.replyTo.content.substring(0,100),f.replyTo.content.length>100?"...":""]})]})]})}),(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(N.A,{user:f.user,size:"sm",showTooltip:!0,clickable:!0,onClick:()=>eI({userId:f.user.id,isOpen:(null==eM?void 0:eM.userId)!==f.user.id||!(null==eM?void 0:eM.isOpen)})}),(null==eM?void 0:eM.userId)===f.user.id&&(null==eM?void 0:eM.isOpen)&&(0,a.jsx)(C.A,{userId:f.user.id,isOpen:!0,onClose:()=>eI(null),position:"right",onStartDirectMessage:(e,t)=>{e$(e,t)}})]}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,a.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 text-xs",children:["[",y,"]"]}),(0,a.jsxs)("span",{className:"font-semibold text-sm ".concat(v?"text-blue-600 dark:text-blue-400":"ADMIN"===f.user.role?"text-purple-600 dark:text-purple-400":"text-green-600 dark:text-green-400"),children:["ADMIN"===f.user.role?"⚖️ ":"",b]}),f.user.title&&(0,a.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["• ",f.user.title]}),f.isEdited&&(0,a.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:"(edited)"})]}),f.fileUrl&&(0,a.jsx)("div",{className:"mt-1 mb-2",children:w?(0,a.jsxs)("div",{className:"relative group",children:[(0,a.jsx)("img",{src:f.fileUrl,alt:f.fileName||"Image",className:"max-w-xs max-h-64 rounded-lg border border-gray-200 dark:border-gray-600 cursor-pointer hover:opacity-90 transition-all duration-200 shadow-sm hover:shadow-md",onClick:()=>{let e=document.createElement("div");e.className="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50 p-4",e.style.zIndex="9999",e.onclick=t=>{t.target===e&&e.remove()};let t=document.createElement("div");t.className="relative max-w-4xl max-h-full";let r=document.createElement("button");r.className="absolute -top-10 right-0 text-white hover:text-gray-300 text-xl font-bold z-10",r.innerHTML="✕",r.onclick=()=>e.remove();let a=document.createElement("img");a.src=f.fileUrl||"",a.alt=f.fileName||"Image",a.className="max-w-full max-h-full object-contain rounded-lg";let n=document.createElement("div");n.className="absolute bottom-0 left-0 right-0 bg-black bg-opacity-80 text-white p-3 rounded-b-lg flex items-center justify-between";let s=document.createElement("div");s.className="flex-1";let o=document.createElement("div");if(o.className="font-medium",o.textContent="\uD83D\uDCF7 Image",s.appendChild(o),f.fileSize){let e=document.createElement("div");e.className="text-sm text-gray-300",e.textContent=e2(f.fileSize),s.appendChild(e)}let i=document.createElement("a");i.href=f.fileUrl||"",i.download=f.fileName||"image",i.className="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded flex items-center gap-2 transition-colors",i.innerHTML='\n                          <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>\n                          </svg>\n                          Download\n                        ',n.appendChild(s),n.appendChild(i),t.appendChild(r),t.appendChild(a),t.appendChild(n),e.appendChild(t),document.body.appendChild(e);let l=t=>{"Escape"===t.key&&(e.remove(),document.removeEventListener("keydown",l))};document.addEventListener("keydown",l)},onError:e=>{let t=e.target;t.style.display="none";let r=t.nextElementSibling;r&&(r.style.display="block")},loading:"lazy"}),(0,a.jsxs)("div",{className:"hidden max-w-xs p-4 bg-gray-100 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600 text-center",children:[(0,a.jsx)("svg",{className:"w-8 h-8 text-gray-400 mx-auto mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Image failed to load"}),(0,a.jsx)("a",{href:f.fileUrl||"#",target:"_blank",rel:"noopener noreferrer",className:"inline-block mt-2 text-blue-500 hover:text-blue-600 text-xs",children:"Open in new tab"})]}),(0,a.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors rounded-lg flex items-center justify-center",children:(0,a.jsx)("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity bg-black/70 text-white text-sm px-3 py-1 rounded-full pointer-events-none",children:"\uD83D\uDD0D Click to view"})})]}):(0,a.jsxs)("a",{href:f.fileUrl||"#",download:f.fileName,className:"inline-flex items-center gap-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors group cursor-pointer",children:[(0,a.jsx)("div",{className:"flex-shrink-0",children:(0,a.jsx)("svg",{className:"w-8 h-8 text-blue-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:(null==(c=f.mimeType)?void 0:c.includes("pdf"))?"\uD83D\uDCC4 PDF Document":(null==(d=f.mimeType)?void 0:d.includes("doc"))?"\uD83D\uDCDD Document":(null==(u=f.mimeType)?void 0:u.includes("spreadsheet"))||(null==(m=f.mimeType)?void 0:m.includes("excel"))?"\uD83D\uDCCA Spreadsheet":(null==(h=f.mimeType)?void 0:h.includes("zip"))||(null==(g=f.mimeType)?void 0:g.includes("rar"))?"\uD83D\uDDC3️ Archive":(null==(p=f.mimeType)?void 0:p.includes("video"))?"\uD83C\uDFA5 Video":(null==(x=f.mimeType)?void 0:x.includes("audio"))?"\uD83C\uDFB5 Audio":"\uD83D\uDCCE File Attachment"}),f.fileSize&&(0,a.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:e2(f.fileSize)})]}),(0,a.jsx)("div",{className:"flex-shrink-0",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-400 group-hover:text-blue-500 transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})})})]})}),f.content&&(0,a.jsx)("div",{className:"text-gray-800 dark:text-gray-200 break-words whitespace-pre-wrap",children:f.content}),(0,a.jsxs)("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity mt-1 flex items-center gap-1",children:[["\uD83D\uDC4D","❤️","\uD83D\uDE02","\uD83D\uDE2E"].map(e=>(0,a.jsx)("button",{onClick:()=>e1(f,e),className:"text-sm hover:scale-110 transition-transform opacity-60 hover:opacity-100",title:"React with ".concat(e),children:e},e)),(0,a.jsx)("button",{onClick:()=>{console.log("Reply button clicked for message:",f.id),eT(f)},className:"text-xs text-blue-500 hover:text-blue-700 dark:hover:text-blue-300 ml-2 font-medium",title:"Reply to this message",children:"↩️ Reply"})]}),(0,a.jsx)(j,{messageId:f.id,reactions:f.reactions||[],onAddReaction:eQ,onRemoveReaction:eZ,className:"mt-1"})]})]})]},f.id)}),e5=async e=>{if((null==W?void 0:W.id)===e.id)return void console.log("[GroupChat] \uD83D\uDCCD Already in room: ".concat(e.name));if(console.log("[GroupChat] \uD83D\uDEAA Switching to room: ".concat(e.name," (").concat(e.id,")")),(null==W?void 0:W.id)&&O&&eg.current.has(W.id))try{console.log("[GroupChat] \uD83D\uDC4B Leaving room: ".concat(W.name)),await O(W.id),eg.current.delete(W.id),console.log("[GroupChat] ✅ Left room: ".concat(W.name))}catch(e){console.error("[GroupChat] ❌ Failed to leave room ".concat(W.name,":"),e)}if(B(e),Y([]),ew(e.description||"Welcome to ".concat(e.name)),I&&!eg.current.has(e.id))try{console.log("[GroupChat] \uD83D\uDD0C Joining room via WebSocket: ".concat(e.name)),await I(e.id),eg.current.add(e.id),console.log("[GroupChat] ✅ Successfully joined room: ".concat(e.name))}catch(t){console.error("[GroupChat] ❌ Failed to join room ".concat(e.name,":"),t),ez("Failed to join room: ".concat(e.name),"ERROR")}else eg.current.has(e.id)&&console.log("[GroupChat] \uD83D\uDCCD Already joined room ".concat(e.name,", just switching view"))},e3=async e=>{try{let t=await fetch("/api/chat/rooms/".concat(e,"/participants"),{method:"GET",credentials:"same-origin"});if(!t.ok)throw Error("Failed to fetch participants.");let r=await t.json();eu(r)}catch(e){eB(e instanceof Error?e.message:"An unknown error occurred.")}};return(0,n.useEffect)(()=>{(null==W?void 0:W.id)&&e3(W.id)},[null==W?void 0:W.id]),(0,n.useMemo)(()=>H.filter(e=>!e.isOptimistic||!H.find(t=>!t.isOptimistic&&t.content===e.content&&5e3>Math.abs(new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))),[H]),(0,n.useMemo)(()=>[...U].sort((e,t)=>{var r,a;let n=(null==(r=e.lastMessage)?void 0:r.createdAt)?new Date(e.lastMessage.createdAt).getTime():0;return((null==(a=t.lastMessage)?void 0:a.createdAt)?new Date(t.lastMessage.createdAt).getTime():0)-n}),[U]),(0,n.useMemo)(()=>(null==W?void 0:W.participants)||[],[null==W?void 0:W.participants]),(0,n.useEffect)(()=>{"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission().then(e=>{console.log("[GroupChat] Notification permission:",e)})},[]),null==S||null==(h=S.user)||h.role,(null==S||null==(f=S.user)?void 0:f.isVerifiedLawyer)||null==S||null==(y=S.user)||y.verificationStatus,(0,a.jsxs)("div",{className:"relative flex h-[26rem] md:h-[32rem] w-full font-mono antialiased bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 text-sm border border-gray-200 dark:border-gray-800 rounded-lg shadow-lg overflow-hidden",children:[e_&&(0,a.jsxs)("div",{className:"absolute top-0 left-0 right-0 z-30 flex items-center justify-between p-3 bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800 h-14",children:[(0,a.jsx)("button",{onClick:()=>eA(!eO),className:"p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,a.jsx)("div",{className:"flex-1 text-center",children:(0,a.jsx)("h2",{className:"font-bold text-base truncate",children:(null==W?void 0:W.name)||"Group Chat"})}),(0,a.jsx)("button",{onClick:()=>eP(!eF),className:"p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"})})})]}),e_&&(eO||eF)&&(0,a.jsx)("div",{className:"absolute inset-0 bg-black bg-opacity-50 z-20",onClick:()=>{eA(!1),eP(!1)}}),(0,a.jsxs)("aside",{className:"\n        flex flex-col border-r border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900\n        ".concat(e_?"absolute top-0 left-0 h-full w-80 max-w-[85vw] z-30 transform transition-transform duration-300 ".concat(eO?"translate-x-0":"-translate-x-full"):"w-64 relative","\n      "),children:[(0,a.jsxs)("header",{className:"flex items-center justify-between p-3 border-b border-gray-200 dark:border-gray-800 h-14 flex-shrink-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h1",{className:"text-base font-bold",children:"Channels"}),P()>0&&(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5 text-blue-500",viewBox:"0 0 20 20",fill:"currentColor",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})}),(0,a.jsx)("span",{className:"absolute -top-1 -right-1 block h-4 w-4 rounded-full bg-red-500 text-white text-xs font-bold flex items-center justify-center border border-white dark:border-gray-900",children:P()>9?"9+":P()})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(null==S||null==(b=S.user)?void 0:b.role)==="ADMIN"&&(0,a.jsx)("button",{onClick:()=>es(!0),className:"p-1.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Create New Room",children:(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})})}),(0,a.jsxs)("div",{title:T?"Connected":"Disconnected",className:"relative w-2.5 h-2.5",children:[(0,a.jsx)("div",{className:"w-full h-full rounded-full ".concat(T?"bg-green-500":"bg-red-500")}),T&&(0,a.jsx)("div",{className:"absolute top-0 left-0 w-full h-full rounded-full ".concat(T?"bg-green-500":"bg-red-500"," animate-ping")})]})]})]}),en&&(0,a.jsx)("div",{className:"p-3 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-800/50",children:(0,a.jsxs)("form",{onSubmit:eK,className:"space-y-2",children:[(0,a.jsx)("input",{type:"text",value:eo,onChange:e=>ei(e.target.value),placeholder:"New channel name...",className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-700 rounded bg-white dark:bg-gray-800 text-sm focus:ring-1 focus:ring-blue-500 focus:border-blue-500",disabled:el}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{type:"submit",disabled:!eo.trim()||el,className:"w-full px-2 py-1 bg-blue-600 text-white text-xs rounded hover:bg-blue-700 disabled:opacity-50",children:el?"Creating...":"Create"}),(0,a.jsx)("button",{type:"button",onClick:()=>{es(!1),ei("")},className:"w-full px-2 py-1 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 text-xs rounded hover:bg-gray-300 dark:hover:bg-gray-600",children:"Cancel"})]})]})}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[F.size>0&&(0,a.jsxs)("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800",children:[(0,a.jsxs)("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1",children:["Direct Messages (",P(),")"]}),(0,a.jsx)("div",{className:"space-y-1",children:Array.from(F.entries()).map(e=>{let[t,r]=e;return(0,a.jsxs)("button",{onClick:()=>e$(t,r.senderName),className:"w-full text-left flex items-center gap-2 p-1.5 rounded transition-colors duration-100 hover:bg-gray-100 dark:hover:bg-gray-800/50",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("div",{className:"w-6 h-6 rounded-full bg-blue-500 text-white flex items-center justify-center text-xs font-bold",children:r.senderName.charAt(0).toUpperCase()}),r.unreadCount>0&&(0,a.jsx)("span",{className:"absolute -top-1 -right-1 block h-3 w-3 rounded-full bg-red-500 text-white text-xs font-bold flex items-center justify-center border border-white dark:border-gray-900",children:r.unreadCount>9?"9+":r.unreadCount})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-semibold truncate ".concat(r.unreadCount>0?"text-blue-600 dark:text-blue-400":"text-gray-900 dark:text-gray-100"),children:r.senderName}),(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:r.lastMessage})]}),r.unreadCount>0&&(0,a.jsx)("span",{className:"text-xs px-1.5 py-0.5 bg-red-500 text-white rounded-full font-bold",children:r.unreadCount})]},t)})})]}),K?(0,a.jsx)("div",{className:"p-2 space-y-2",children:(0,a.jsx)(E,{count:8,className:"h-8 w-full rounded"})}):(0,a.jsxs)("div",{className:"p-2 space-y-1",children:[(0,a.jsxs)("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 px-1",children:["Channels ",U.length>0&&"(".concat(U.length,")")]}),0===U.length&&!K&&(0,a.jsxs)("div",{className:"text-center text-gray-500 py-4",children:[(0,a.jsx)("p",{className:"text-sm",children:"No channels available"}),!T&&(0,a.jsx)("button",{onClick:_,className:"mt-2 px-3 py-1 bg-blue-600 text-white rounded text-xs hover:bg-blue-700",children:"Reconnect"})]}),U.map(e=>{var t;let r=(null==W?void 0:W.id)===e.id,n=eg.current.has(e.id);return(0,a.jsxs)("div",{className:"flex items-center group",children:[(0,a.jsxs)("button",{onClick:()=>e5(e),className:"w-full text-left flex items-center gap-2 p-1.5 rounded transition-colors duration-100 ".concat(r?"bg-blue-600 text-white font-semibold":"hover:bg-gray-100 dark:hover:bg-gray-800/50"),children:[(0,a.jsx)("span",{className:"font-mono font-bold ".concat(r?"text-blue-200":"text-gray-400"),children:"#"}),(0,a.jsx)("span",{className:"flex-1 truncate",children:e.name}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[n&&(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(r?"bg-green-300":"bg-green-500"),title:"Connected to ".concat(e.name)}),e._count&&e._count.messages>0&&(0,a.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full ".concat(r?"bg-white text-blue-600":"bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300"),children:e._count.messages})]})]}),(null==S||null==(t=S.user)?void 0:t.role)==="ADMIN"&&(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),eq(e.id,e.name)},className:"p-1 ml-1 rounded text-gray-400 hover:text-red-600 dark:hover:text-red-400 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete ".concat(e.name),children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})})]},e.id)})]})]})]}),(0,a.jsx)("main",{className:"flex-1 flex flex-col bg-white dark:bg-gray-900 ".concat(!e_?"border-r border-gray-200 dark:border-gray-800":""," ").concat(e_?"pt-14":""),children:W?(0,a.jsxs)(a.Fragment,{children:[!e_&&(0,a.jsxs)("header",{className:"flex items-center justify-between p-3 border-b border-gray-200 dark:border-gray-800 h-14 flex-shrink-0",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsxs)("h2",{className:"text-base font-bold text-gray-900 dark:text-gray-100",children:["#",W.name]}),(0,a.jsx)("button",{onClick:()=>eY(W.id),className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded text-sm",title:"Refresh messages",children:"\uD83D\uDD04"}),(0,a.jsx)(p,{})]}),(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)("button",{onClick:()=>Z(!Q),className:"p-2 rounded-full text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Toggle Members List",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:(0,a.jsx)("path",{d:"M9 6a3 3 0 11-6 0 3 3 0 016 0zM17 6a3 3 0 11-6 0 3 3 0 016 0zM12.93 17c.046-.327.07-.66.07-1a6.97 6.97 0 00-1.5-4.33A5 5 0 0119 16v1h-6.07zM6 11a5 5 0 015 5v1H1v-1a5 5 0 015-5z"})})})})]}),(0,a.jsxs)("div",{className:"overflow-y-auto p-2 ".concat(e_?"h-[calc(100%-8rem)]":"h-[19.5rem]"," touch-pan-y"),onScroll:()=>{eb(eU())},ref:ef,children:[ev&&(0,a.jsx)("div",{className:"text-center p-3 my-2 bg-gray-100 dark:bg-gray-800 rounded-lg",children:(0,a.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:ev})}),X?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-full",children:[(0,a.jsx)("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("p",{className:"text-gray-500 dark:text-gray-400 mt-3 text-xs",children:"Loading Messages..."})]}):(0,a.jsxs)("div",{children:[0===H.length?(0,a.jsx)("div",{className:"text-center text-gray-500 dark:text-gray-400 py-8",children:(0,a.jsx)("p",{children:"No messages yet. Be the first to say something!"})}):H.map(e=>(0,a.jsx)(e4,{message:e},e.id)),(0,a.jsx)("div",{ref:em})]})]}),(0,a.jsx)(x,{roomId:W.id}),(0,a.jsxs)("footer",{className:"p-2 border-t border-gray-200 dark:border-gray-800",children:[(0,a.jsx)(o.N,{children:eL&&(0,a.jsx)(i.P.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-2 p-2 bg-gray-100 dark:bg-gray-700 rounded border-l-4 border-blue-500",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[eL.fileUrl&&(null==(D=eL.mimeType)?void 0:D.startsWith("image/"))&&(0,a.jsx)("img",{src:eL.fileUrl,alt:"Reply thumbnail",className:"w-8 h-8 object-cover rounded border flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:["Replying to ",eL.user.name]}),(0,a.jsx)("p",{className:"text-sm text-gray-800 dark:text-gray-200 truncate",children:eL.fileUrl?(null==(R=eL.mimeType)?void 0:R.startsWith("image/"))?(0,a.jsx)("span",{className:"italic",children:"\uD83D\uDCF7 Image"}):(0,a.jsx)("span",{className:"italic",children:"\uD83D\uDCCE File attachment"}):eL.content})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[!e_&&(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("button",{type:"button",onClick:()=>eC(!eN),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-xs",title:"Add emoji",children:"\uD83D\uDE00"}),(0,a.jsx)(w,{isOpen:eN,onClose:()=>eC(!1),onEmojiSelect:e0,position:"bottom"})]}),(0,a.jsx)("button",{onClick:()=>eT(null),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-xs p-1",children:"\xd7"})]})]})})}),(0,a.jsxs)("form",{onSubmit:eV,className:"relative",children:[(0,a.jsxs)("div",{className:"flex items-end gap-2",children:[(0,a.jsx)(k.A,{onFileSelect:eD,onRemoveFile:()=>eD(null),selectedFile:eE,uploading:eR,className:"flex-shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 relative",children:[(0,a.jsx)("input",{type:"text",value:J,onChange:e=>{V(e.target.value),W&&M&&(e.target.value.length>0&&!er?(ea(!0),M(W.id,!0)):0===e.target.value.length&&er&&(ea(!1),M(W.id,!1)))},onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||eV(e)},onBlur:()=>{er&&W&&M&&(ea(!1),M(W.id,!1))},placeholder:eL?"Reply to ".concat(eL.user.name,"..."):eE?"Add a caption...":"Message #".concat(W.name),className:"w-full bg-gray-100 dark:bg-gray-800 border-transparent rounded pl-3 ".concat(e_?"pr-12":"pr-20"," py-2 text-sm transition-all ").concat(eL?"ring-2 ring-blue-500 border-blue-500 bg-blue-50 dark:bg-blue-900/20":"focus:ring-1 focus:ring-blue-500 focus:border-blue-500"),disabled:X||eR}),!e_&&(0,a.jsxs)("div",{className:"absolute right-10 top-1/2 transform -translate-y-1/2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>eC(!eN),className:"p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors",title:"Add emoji",children:(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),(0,a.jsx)(w,{isOpen:eN,onClose:()=>eC(!1),onEmojiSelect:e0,position:"top"})]})]}),(0,a.jsx)(i.P.button,{type:"submit",disabled:!J.trim()&&!eE||X||eR,className:"flex-shrink-0 p-2 bg-blue-500 hover:bg-blue-600 disabled:bg-gray-400 text-white rounded transition-colors disabled:cursor-not-allowed",whileHover:{scale:1.05},whileTap:{scale:.95},title:"Send message",children:eR?(0,a.jsx)("div",{className:"w-4 h-4 animate-spin rounded-full border-2 border-white border-t-transparent"}):(0,a.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,a.jsx)("path",{d:"M3.478 2.405a.75.75 0 00-.926.94l2.432 7.905H13.5a.75.75 0 010 1.5H4.984l-2.432 7.905a.75.75 0 00.926.94 60.519 60.519 0 0018.445-8.986.75.75 0 000-1.218A60.517 60.517 0 003.478 2.405z"})})})]}),(0,a.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 text-center",children:[e_?"Tap to send":"Press Enter to send"," • ",eE?"File: ".concat(eE.name):"Drag & drop files or use \uD83D\uDCCE"]})]})]})]}):(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center text-gray-500 p-4",children:(0,a.jsx)("div",{className:"text-center max-w-sm",children:0===U.length?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"text-base",children:"No chat rooms available."}),(0,a.jsx)("p",{className:"text-sm mt-2 text-gray-400",children:"Please contact an administrator to create chat rooms."}),!T&&(0,a.jsxs)("div",{className:"mt-4 p-4 bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg",children:[(0,a.jsx)("p",{className:"text-orange-600 dark:text-orange-400 text-sm",children:"⚠️ Connection issues detected"}),(0,a.jsx)("button",{onClick:_,className:"mt-2 px-4 py-2 bg-orange-600 text-white rounded text-sm hover:bg-orange-700 transition-colors",children:"Reconnect"})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"text-base",children:"No channel selected."}),(0,a.jsx)("p",{className:"text-sm mt-2 text-gray-400",children:e_?"Tap the menu to select a channel":"Click on a channel to start chatting"})]})})})}),(0,a.jsx)(o.N,{children:(Q&&!e_||eF&&e_)&&W&&(0,a.jsxs)(i.P.aside,{initial:{opacity:0,x:50},animate:{opacity:1,x:0},exit:{opacity:0,x:50},transition:{duration:.2},className:"\n            border-l border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 flex flex-col\n            ".concat(e_?"absolute top-0 right-0 h-full w-80 max-w-[85vw] z-30":"w-64 relative","\n          "),children:[(0,a.jsxs)("header",{className:"p-3 border-b border-gray-200 dark:border-gray-800 h-14 flex-shrink-0 flex items-center justify-between",children:[(0,a.jsxs)("h3",{className:"text-base font-bold",children:["Users (",ed.length,")"]}),(0,a.jsx)("button",{onClick:()=>{e_?eP(!1):Z(!1)},className:"p-1.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:ed.filter(e=>e&&e.user).map(e=>{let t=F.get(e.user.id),r=t&&t.unreadCount>0;return(0,a.jsxs)("div",{className:"flex items-center gap-2 p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800/50",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(N.A,{user:e.user,size:"sm",showStatus:!0,clickable:!0,onClick:()=>eI({userId:e.user.id,isOpen:(null==eM?void 0:eM.userId)!==e.user.id||!(null==eM?void 0:eM.isOpen)})}),(null==eM?void 0:eM.userId)===e.user.id&&(null==eM?void 0:eM.isOpen)&&(0,a.jsx)(C.A,{userId:e.user.id,isOpen:!0,onClose:()=>eI(null),position:"left",onStartDirectMessage:(e,t)=>{e$(e,t)}}),"ADMIN"===e.role&&(0,a.jsx)("span",{className:"absolute -top-1 -right-1 block h-3 w-3 rounded-full bg-yellow-500 border border-white dark:border-gray-900",title:"Admin"}),r&&(0,a.jsx)("span",{className:"absolute -top-1 -left-1 block h-4 w-4 rounded-full bg-red-500 text-white text-xs font-bold flex items-center justify-center border border-white dark:border-gray-900",title:"".concat(t.unreadCount," unread message").concat(t.unreadCount>1?"s":""),children:t.unreadCount>9?"9+":t.unreadCount})]}),(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsxs)("p",{className:"text-sm font-semibold truncate cursor-pointer ".concat(r?"text-blue-600 dark:text-blue-400 font-bold":"text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400"),onDoubleClick:()=>{e$(e.user.id,e.user.name),e_&&eP(!1)},title:"".concat(e_?"Tap":"Double-click"," to start private chat with ").concat(e.user.name).concat(r?" (".concat(t.unreadCount," unread)"):""),children:[e.user.name,r&&(0,a.jsxs)("span",{className:"ml-1 text-xs text-red-500 dark:text-red-400",children:["(",t.unreadCount,")"]})]})}),(0,a.jsx)("div",{className:"ml-auto",children:(0,a.jsx)(m,{participant:e,roomId:W.id,onKick:eX})})]},e.user.id)})})]})}),(0,a.jsx)(o.N,{children:!1}),(0,a.jsx)(o.N,{children:ej&&(0,a.jsx)(g,{chatId:ej.recipientId,onClose:()=>ek(null)})})]})}},31059:(e,t,r)=>{var a=r(82909),n=a.Buffer;function s(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=a:(s(a,t),t.Buffer=o),s(n,o),o.from=function(e,t,r){if("number"==typeof e)throw TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw TypeError("Argument must be a number");var a=n(e);return void 0!==t?"string"==typeof r?a.fill(t,r):a.fill(t):a.fill(0),a},o.allocUnsafe=function(e){if("number"!=typeof e)throw TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw TypeError("Argument must be a number");return a.SlowBuffer(e)}},95284:e=>{!function(){"use strict";var t={864:function(e){var t,r="object"==typeof Reflect?Reflect:null,a=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var n=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise(function(r,a){var n,s,o;function i(r){e.removeListener(t,l),a(r)}function l(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}p(e,t,l,{once:!0}),"error"!==t&&(n=e,s=i,o={once:!0},"function"==typeof n.on&&p(n,"error",s,o))})},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function i(e){if("function"!=typeof e)throw TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function c(e,t,r,a){if(i(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),o=s[t]),void 0===o)o=s[t]=r,++e._eventsCount;else if("function"==typeof o?o=s[t]=a?[r,o]:[o,r]:a?o.unshift(r):o.push(r),(n=l(e))>0&&o.length>n&&!o.warned){o.warned=!0;var n,s,o,c=Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,console&&console.warn&&console.warn(c)}return e}function d(){if(!this.fired)return(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0==arguments.length)?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function u(e,t,r){var a={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},n=d.bind(a);return n.listener=r,a.wrapFn=n,n}function m(e,t,r){var a=e._events;if(void 0===a)return[];var n=a[t];return void 0===n?[]:"function"==typeof n?r?[n.listener||n]:[n]:r?function(e){for(var t=Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(n):g(n,n.length)}function h(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function g(e,t){for(var r=Array(t),a=0;a<t;++a)r[a]=e[a];return r}function p(e,t,r,a){if("function"==typeof e.on)a.once?e.once(t,r):e.on(t,r);else if("function"==typeof e.addEventListener)e.addEventListener(t,function n(s){a.once&&e.removeEventListener(t,n),r(s)});else throw TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||n(e))throw RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),s.init=function(){(void 0===this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||n(e))throw RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return l(this)},s.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var o,i=Error("Unhandled error."+(o?" ("+o.message+")":""));throw i.context=o,i}var l=s[e];if(void 0===l)return!1;if("function"==typeof l)a(l,this,t);else for(var c=l.length,d=g(l,c),r=0;r<c;++r)a(d[r],this,t);return!0},s.prototype.addListener=function(e,t){return c(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return c(this,e,t,!0)},s.prototype.once=function(e,t){return i(t),this.on(e,u(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return i(t),this.prependListener(e,u(this,e,t)),this},s.prototype.removeListener=function(e,t){var r,a,n,s,o;if(i(t),void 0===(a=this._events)||void 0===(r=a[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete a[e],a.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(n=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){o=r[s].listener,n=s;break}if(n<0)return this;0===n?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,n),1===r.length&&(a[e]=r[0]),void 0!==a.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,r,a;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0==arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0==arguments.length){var n,s=Object.keys(r);for(a=0;a<s.length;++a)"removeListener"!==(n=s[a])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(a=t.length-1;a>=0;a--)this.removeListener(e,t[a]);return this},s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}},r={};function a(e){var n=r[e];if(void 0!==n)return n.exports;var s=r[e]={exports:{}},o=!0;try{t[e](s,s.exports,a),o=!1}finally{o&&delete r[e]}return s.exports}a.ab="//",e.exports=a(864)}()}}]);

CasperSecurity Mini