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.ca/private_html/.next/server/chunks/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/private_html/.next/server/chunks/5369.js
"use strict";exports.id=5369,exports.ids=[5369],exports.modules={1592:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.d(t,{A:()=>d});var s=r(8732),o=r(82015),n=r(63220),i=r(4722),l=e([n]);n=(l.then?(await l)():l)[0];let d=({participant:e,roomId:t,onKick:r})=>{let{data:a}=(0,i.useSession)(),[l,d]=(0,o.useState)(!1),c=a?.user?.id===e.user.id,m=a?.user?.role==="ADMIN";return c?null:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("button",{onClick:()=>d(!l),className:"p-1 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700",children:(0,s.jsx)("svg",{className:"w-5 h-5 text-gray-500",fill:"currentColor",viewBox:"0 0 20 20",children:(0,s.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,s.jsx)(n.AnimatePresence,{children:l&&(0,s.jsx)(n.motion.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,s.jsx)("ul",{className:"py-1",children:m&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("li",{className:"border-t border-gray-200 dark:border-gray-700 my-1"}),(0,s.jsx)("li",{children:(0,s.jsx)("button",{onClick:()=>{window.confirm(`Are you sure you want to kick ${e.user.name}?`)&&r(e.user.id),d(!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"})})]})})})})]})};a()}catch(e){a(e)}})},28283:(e,t,r)=>{r.d(t,{A:()=>o});var a=r(8732),s=r(82015);let o=({roomId:e})=>{let[t,r]=(0,s.useState)(""),[o,n]=(0,s.useState)([]);return((0,s.useEffect)(()=>{let t=t=>{let r=t.detail;if("TYPING"===r.type&&r.data.roomId===e){let{userName:e,isTyping:t,timestamp:a}=r.data;n(r=>t?[...r.filter(t=>t.userName!==e),{userName:e,timestamp:a}]:r.filter(t=>t.userName!==e))}};window.addEventListener("websocket-message",t);let a=Date.now(),s=o.filter(e=>a-e.timestamp<5e3);return 0===s.length?r(""):1===s.length?r(`${s[0].userName} is typing...`):2===s.length?r(`${s[0].userName} and ${s[1].userName} are typing...`):r(`${s[0].userName} and ${s.length-1} others are typing...`),()=>{window.removeEventListener("websocket-message",t)}},[o,e]),t)?(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:t})]}):null}},42584:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.d(t,{A:()=>m,z:()=>d});var s=r(8732),o=r(82015),n=r(63220),i=e([n]);n=(i.then?(await i)():i)[0];let c={"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 l(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 d(e){}let m=({onEmojiSelect:e,isOpen:t,onClose:r,position:a="bottom"})=>{let[i,d]=(0,o.useState)("Smileys & People"),[m,u]=(0,o.useState)(""),h=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&r()},a=e=>{"Escape"===e.key&&r()};return t&&(document.addEventListener("mousedown",e),document.addEventListener("keydown",a)),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",a)}},[t,r]);let g=m?Object.values(c).flat().filter(e=>e.includes(m)||l(e).toLowerCase().includes(m.toLowerCase())):c[i],x=t=>{e(t)};return(0,s.jsx)(n.AnimatePresence,{children:t&&(0,s.jsxs)(n.motion.div,{ref:h,initial:{opacity:0,scale:.9,y:"top"===a?10:-10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:"top"===a?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 ${"top"===a?"bottom-full mb-2":"top-full mt-2"}`,children:[(0,s.jsx)("div",{className:"p-3 border-b border-gray-200 dark:border-gray-700",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"text",placeholder:"Search emojis...",value:m,onChange:e=>u(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,s.jsx)("button",{type:"button",onClick:r,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,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),!m&&(0,s.jsx)("div",{className:"flex overflow-x-auto border-b border-gray-200 dark:border-gray-700",children:Object.keys(c).map(e=>(0,s.jsx)("button",{onClick:()=>d(e),className:`px-3 py-2 text-xs font-medium whitespace-nowrap border-b-2 transition-colors ${i===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,s.jsxs)("div",{className:"p-2 max-h-64 overflow-y-auto",children:[(0,s.jsx)("div",{className:"grid grid-cols-8 gap-1",children:g.map((e,t)=>(0,s.jsx)("button",{type:"button",onClick:t=>{t.preventDefault(),t.stopPropagation(),x(e)},className:"p-2 text-xl hover:bg-gray-100 dark:hover:bg-gray-700 rounded transition-colors",title:l(e),children:e},`${e}-${t}`))}),0===g.length&&(0,s.jsx)("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:(0,s.jsx)("p",{className:"text-sm",children:"No emojis found"})})]}),(0,s.jsx)("div",{className:"border-t border-gray-200 dark:border-gray-700 p-2",children:(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium",children:"Recent:"}),["\uD83D\uDC4D","❤️","\uD83D\uDE02","\uD83C\uDF89"].map((e,t)=>(0,s.jsx)("button",{type:"button",onClick:t=>{t.preventDefault(),t.stopPropagation(),x(e)},className:"p-1 text-lg hover:bg-gray-100 dark:hover:bg-gray-700 rounded",title:l(e),children:e},`recent-${e}-${t}`))]})})]})})};a()}catch(e){a(e)}})},66920:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.d(t,{A:()=>u});var s=r(8732),o=r(82015),n=r(4722),i=r(63220),l=r(22863),d=r(73392);r(13221);var c=e([i]);i=(c.then?(await c)():c)[0];let m=1e3,u=({chatId:e,onClose:t})=>{console.log("\uD83D\uDCDE [DirectMessage] Component initializing with chatId:",e);let{ws:r,markDirectMessagesAsRead:a,incomingVideoCall:c,acceptVideoCall:u}=(0,d.h)(),{data:h}=(0,n.useSession)(),g=(0,o.useRef)(null),x=(0,o.useRef)(null),p=(0,o.useRef)(null),[b,y]=(0,o.useState)([]),[f,v]=(0,o.useState)(""),[w,j]=(0,o.useState)(null),[k,N]=(0,o.useState)(!0),[C,E]=(0,o.useState)(null),[R,S]=(0,o.useState)(null),[$,I]=(0,o.useState)(null),[M,A]=(0,o.useState)(null),[T,D]=(0,o.useState)(!1),[L,O]=(0,o.useState)(null),[F,G]=(0,o.useState)(!1),[P,z]=(0,o.useState)({x:0,y:0}),[U,W]=(0,o.useState)(()=>({x:0,y:0})),[B,_]=(0,o.useState)(()=>++m);console.log("\uD83D\uDCDE [DirectMessage] Initial state - recipientId:",e,"session:",h?.user?.name);let H=()=>{m+=1,_(m)},Y=(0,o.useCallback)(e=>{if(!F)return;let t=e.clientX-P.x,r=e.clientY-P.y;t=Math.max(0,Math.min(t,window.innerWidth-384)),r=Math.max(0,Math.min(r,window.innerHeight-500)),W({x:t,y:r})},[F,P]),V=(0,o.useCallback)(()=>{G(!1)},[]);(0,o.useEffect)(()=>(F?(document.addEventListener("mousemove",Y),document.addEventListener("mouseup",V),document.body.style.cursor="grabbing",document.body.style.userSelect="none"):(document.removeEventListener("mousemove",Y),document.removeEventListener("mouseup",V),document.body.style.cursor="",document.body.style.userSelect=""),()=>{document.removeEventListener("mousemove",Y),document.removeEventListener("mouseup",V),document.body.style.cursor="",document.body.style.userSelect=""}),[F,Y,V]),(0,o.useEffect)(()=>{e&&a&&a(e)},[e,a]),(0,o.useEffect)(()=>{if(!r)return;let t=t=>{try{let r=JSON.parse(t.data);switch(console.log("Direct message WebSocket received:",r),r.type){case"DIRECT_MESSAGE":(r.data.senderId===h?.user.id&&r.data.recipientId===e||r.data.senderId===e&&r.data.recipientId===h?.user.id)&&(y(e=>[...e,r.data]),r.data.senderId===e&&a&&a(e));break;case"webrtc-offer":console.log("\uD83D\uDCDE Received webrtc-offer from:",r.senderId,"Expected from:",e);break;case"webrtc-answer":x.current&&r.senderId===e&&x.current.signal(r.data.signal);break;case"webrtc-ice-candidate":x.current&&r.senderId===e&&x.current.signal(r.data.candidate);break;case"webrtc-end-call":r.senderId===e&&X();break;case"webrtc-error":r.recipientId===e&&(console.log("❌ WebRTC Error:",r.error,r.message),D(!1),X(),"RECIPIENT_OFFLINE"===r.error?alert(`Cannot start video call: ${w?.name||"User"} is not currently online. Please try again when they are available.`):alert(`Video call failed: ${r.message}`))}}catch(e){console.error("Error parsing direct message WebSocket:",e)}};return r.addEventListener("message",t),()=>r.removeEventListener("message",t)},[r,e,h,a]);let J=async()=>{if(e){N(!0);try{let t=await fetch(`/api/chat/direct/${e}`,{method:"GET",credentials:"same-origin"});if(!t.ok)throw Error("Failed to fetch chat history");let r=await t.json();y(r.messages||[]),j(r.participants.find(t=>t.id===e)||null)}catch(e){E("Failed to load chat history"),console.error(e)}finally{N(!1)}}};(0,o.useEffect)(()=>{J(),K()},[e]);let K=async()=>{if(e)try{let t=await fetch(`/api/user/online-status/${e}`);if(t.ok){let e=await t.json();S(e.isOnline)}}catch(e){console.warn("Error checking recipient online status:",e)}};(0,o.useEffect)(()=>{let e=setInterval(K,3e4);return()=>clearInterval(e)},[e]);let q=async()=>{if(!f.trim()||!r||!h)return;let t={id:`temp-${Date.now()}`,content:f.trim(),senderId:h.user.id,recipientId:e,createdAt:new Date().toISOString(),type:"TEXT",sender:{id:h.user.id,name:h.user.name||"Me"},recipient:w||{id:e,name:"Unknown"}};y(e=>[...e,t]),v("");try{let a=await fetch(`/api/chat/direct/${e}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t.content,type:"TEXT"})});if(!a.ok)throw Error("Failed to send message");let s=await a.json();y(e=>e.map(e=>e.id===t.id?s:e)),r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({type:"DIRECT_MESSAGE",data:{...s,recipientId:e}}))}catch(e){console.error("Failed to send message:",e),y(e=>e.filter(e=>e.id!==t.id))}};(0,o.useEffect)(()=>{g.current?.scrollIntoView({behavior:"smooth"})},[b]);let X=()=>{x.current&&(x.current.destroy(),x.current=null),$&&($.getTracks().forEach(e=>e.stop()),I(null)),A(null),D(!1),O(null)};return k?(0,s.jsx)("div",{children:"Loading..."}):C?(0,s.jsxs)("div",{children:["Error: ",C]}):(0,s.jsxs)(i.motion.div,{ref:p,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:U.x,top:U.y,zIndex:B,cursor:F?"grabbing":"default"},onMouseDown:H,children:[(0,s.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 ${F?"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=>{if(e.target.closest("button, input, .no-drag"))return;H(),G(!0);let t=p.current?.getBoundingClientRect();t&&z({x:e.clientX-t.left,y:e.clientY-t.top})},children:[(0,s.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 ",w?.name||"User",F&&(0,s.jsx)("span",{className:"text-sm opacity-75",children:"✋"})]}),(0,s.jsx)("div",{className:"flex items-center space-x-2 no-drag",children:(0,s.jsx)("button",{onClick:t,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,s.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,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 no-drag",children:[0===b.length&&(0,s.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,s.jsx)("div",{className:"mb-3",children:(0,s.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,s.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,s.jsx)("h3",{className:"text-sm font-semibold text-blue-800 dark:text-blue-200 mb-2",children:"Start Chatting"}),(0,s.jsxs)("p",{className:"text-xs text-blue-600 dark:text-blue-300",children:["Send a message to ",w?.name||"this user"]})]}),b.map((e,t)=>{let r=e.senderId===h?.user?.id;return(0,s.jsx)(i.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`flex ${r?"justify-end":"justify-start"} mb-2`,children:(0,s.jsxs)("div",{className:`px-4 py-2 rounded-lg ${r?"bg-blue-500 text-white":"bg-gray-200 text-black"}`,children:[(0,s.jsx)("p",{children:e.content}),(0,s.jsx)("span",{className:"text-xs opacity-75",children:(0,l.GP)(new Date(e.createdAt),"HH:mm")})]})},e.id||t)}),(0,s.jsx)("div",{ref:g})]}),(0,s.jsx)("div",{className:"p-4 bg-white dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700 no-drag",children:(0,s.jsxs)("div",{className:"flex items-center bg-gray-100 dark:bg-gray-800 rounded-lg px-2 py-1 no-drag",children:[(0,s.jsx)("input",{type:"text",value:f,onChange:e=>v(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,s.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:!f.trim()||!r,title:"Send Message",children:(0,s.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,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]})})]})};a()}catch(e){a(e)}})},85041:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.d(t,{A:()=>c});var s=r(8732),o=r(82015),n=r(63220),i=r(4722),l=r(42584),d=e([n,l]);[n,l]=d.then?(await d)():d;let c=({messageId:e,reactions:t,onAddReaction:r,onRemoveReaction:a,className:d=""})=>{let{data:c}=(0,i.useSession)(),[m,u]=(0,o.useState)(null),[h,g]=(0,o.useState)(!1),x=t.reduce((e,t)=>(e[t.emoji]||(e[t.emoji]=[]),e[t.emoji].push(t),e),{}),p=t=>{c?.user?.id&&(x[t]?.find(e=>e.userId===c.user.id)?a(e,t):r(e,t))},b=(e,t)=>{let r=t.map(e=>e.user.name);return 1===r.length?`${r[0]} reacted with ${e}`:2===r.length?`${r[0]} and ${r[1]} reacted with ${e}`:r.length<=5?`${r.slice(0,-1).join(", ")} and ${r[r.length-1]} reacted with ${e}`:`${r.slice(0,3).join(", ")} and ${r.length-3} others reacted with ${e}`};return(0,s.jsxs)("div",{className:`flex flex-wrap items-center gap-1 mt-1 ${d}`,children:[(0,s.jsx)(n.AnimatePresence,{children:Object.entries(x).map(([e,t])=>{let r=c?.user?.id&&t.some(e=>e.userId===c.user.id);return(0,s.jsxs)(n.motion.button,{initial:{scale:0},animate:{scale:1},exit:{scale:0},whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>p(e),onMouseEnter:()=>u(e),onMouseLeave:()=>u(null),className:`
                relative inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium
                transition-all duration-200 border
                ${r?"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"}
              `,title:b(e,t),children:[(0,s.jsx)("span",{className:"text-sm",children:e}),(0,s.jsx)("span",{className:"text-xs font-medium",children:t.length}),(0,s.jsx)(n.AnimatePresence,{children:m===e&&(0,s.jsx)(n.motion.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,s.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:[b(e,t),(0,s.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"})]})})})]},e)})}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(n.motion.button,{onClick:()=>g(!h),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,s.jsx)("span",{className:"text-xs",children:"+"})}),(0,s.jsx)(l.A,{isOpen:h,onClose:()=>g(!1),onEmojiSelect:t=>{r(e,t),(0,l.z)(t),g(!1)},position:"top"})]})]})};a()}catch(e){a(e)}})},85369:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.r(t),r.d(t,{default:()=>N});var s=r(8732),o=r(82015),n=r.n(o),i=r(4722),l=r(63220),d=r(22863),c=r(43109),m=r(42893),u=r(73392),h=r(1592),g=r(66920),x=r(93819),p=r(28283),b=r(42584),y=r(85041),f=r(4659),v=r(50927),w=r(42391),j=e([l,m,h,g,b,y,f,v,w]);[l,m,h,g,b,y,f,v,w]=j.then?(await j)():j;let k=({count:e=1,className:t="h-10 w-full"})=>(0,s.jsx)(s.Fragment,{children:[...Array(e)].map((e,r)=>(0,s.jsx)("div",{className:`bg-gray-200 dark:bg-gray-700 rounded animate-pulse ${t}`},r))}),N=()=>{let{data:e}=(0,i.useSession)(),{ws:t,connected:r,sendTyping:a,joinRoom:j,leaveRoom:N,connectionState:C,directMessageNotifications:E,getTotalUnreadDirectMessages:R,reconnect:S}=(0,u.h)(),{toast:$}=(0,c.dj)();(0,o.useEffect)(()=>{if(console.log(`[GroupChat] 🔌 WebSocket status changed:`,{hasWs:!!t,connected:r,connectionState:C,readyState:t?.readyState,sessionUser:e?.user?.name}),"disconnected"===C&&e?.user?.id&&!r){let e=setTimeout(()=>{console.log("[GroupChat] \uD83D\uDD04 Auto-retrying WebSocket connection..."),S()},3e3);return()=>clearTimeout(e)}},[t,r,C,e?.user?.name,e?.user?.id,S]),(0,o.useEffect)(()=>{"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission().then(e=>{console.log("[GroupChat] Notification permission:",e)})},[]);let[I,M]=(0,o.useState)([]),[A,T]=(0,o.useState)(null),[D,L]=(0,o.useState)([]),[O,F]=(0,o.useState)(""),[G,P]=(0,o.useState)(!0),[z,U]=(0,o.useState)(!1),[W,B]=(0,o.useState)(!0),[_,H]=(0,o.useState)(new Set),[Y,V]=(0,o.useState)(!1),[J,K]=(0,o.useState)(!1),[q,X]=(0,o.useState)(""),[Q,Z]=(0,o.useState)(!1),[ee,et]=(0,o.useState)([]),er=(0,o.useRef)(null),ea=(0,o.useRef)(A),es=(0,o.useRef)(new Set);(0,o.useRef)(null);let[eo,en]=(0,o.useState)({open:!1,registrationId:null}),ei=(0,o.useRef)(null),[el,ed]=(0,o.useState)(!0),[ec,em]=(0,o.useState)(null),[eu,eh]=(0,o.useState)(null),[eg,ex]=(0,o.useState)(!1),[ep,eb]=(0,o.useState)(null),[ey,ef]=(0,o.useState)(!1),[ev,ew]=(0,o.useState)(null),[ej,ek]=(0,o.useState)(null),[eN,eC]=(0,o.useState)(!1),[eE,eR]=(0,o.useState)(!1),[eS,e$]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=()=>{let e=window.innerWidth<768;e$(e),e||(eC(!1),eR(!1))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,o.useEffect)(()=>{ea.current=A},[A]),(0,o.useEffect)(()=>{eD()},[]),(0,o.useEffect)(()=>{A?.id?(console.log(`[GroupChat] 🎯 Room selected: ${A.name} (${A.id})`),eL(A.id)):(console.log(`[GroupChat] 🎯 No room selected, clearing messages`),L([]))},[A?.id]);let eI=()=>{if(!ei.current)return!0;let{scrollTop:e,scrollHeight:t,clientHeight:r}=ei.current;return e+r>=t-10};(0,o.useEffect)(()=>{el&&er.current&&er.current.scrollIntoView({behavior:"auto",block:"end"})},[D,el]),(0,o.useEffect)(()=>{ed(!0)},[A]),(0,o.useEffect)(()=>{ev?console.log("\uD83D\uDD04 Reply mode activated for message:",ev.id,"by user:",ev.user.name):console.log("\uD83D\uDD04 Reply mode deactivated")},[ev]);let eM=(e,t="SYSTEM")=>{let r={id:`system-${Date.now()}`,content:e,createdAt:new Date().toISOString(),user:{id:"system",name:"System"},chatRoomId:A?.id||"local",type:t};L(e=>[...e,r])},eA=async t=>{if(!e)return void eM("You must be logged in to use commands.","ERROR");let[r,...a]=t.substring(1).split(" "),s=a.join(" "),[o,...n]=a,i=n.join(" ");switch(r.toLowerCase()){case"help":eM("--- Help ---"),eM("/help - Shows this help message."),eM("/clear - Clears the current chat window."),eM("/switch <room_name> - Switches to a specified room."),eM("/part - Leaves the current room."),eM("/list - Lists all available rooms."),eM("/msg <user_name> <message> - Sends a private message."),eM("/me <action> - Performs an action message."),"ADMIN"===e.user.role&&(eM("--- Admin Commands ---"),eM("/createroom <room_name> - Creates a new room."),eM("/kick <user_name> [reason] - Kicks a user from the room."));break;case"clear":L([]);break;case"list":eM("Available rooms:"),I.forEach(e=>{eM(`#${e.name} - ${e.participants.length} users`)});break;case"createroom":if("ADMIN"!==e.user.role)return void eM("Error: You do not have permission to create rooms.","ERROR");if(!s)return void eM("Usage: /createroom <room_name>","ERROR");await eG(void 0,s);break;case"switch":case"join":{if(!s)return void eM("Usage: /switch <room_name>","ERROR");let e=I.find(e=>e.name.toLowerCase()===s.toLowerCase());e?(T(e),eM(`Switched to room: ${e.name}`)):eM(`Room "${s}" not found.`,"ERROR");break}case"part":A?(eM(`You have left room: ${A.name}`),T(null)):eM("You are not in a room.","ERROR");break;case"kick":{if("ADMIN"!==e.user.role)return void eM("Error: You do not have permission to kick users.","ERROR");if(!A)return void eM("Error: You must be in a room to kick a user.","ERROR");if(!o)return void eM("Usage: /kick <user_name> [reason]","ERROR");let t=ee.find(e=>e.user.name.toLowerCase()===o.toLowerCase());if(!t)return void eM(`Error: User "${o}" not found in this room.`,"ERROR");try{let e=await fetch(`/api/chat/rooms/${A.id}/participants/${t.user.id}`,{method:"DELETE",credentials:"same-origin"}),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to kick user.")}catch(e){eT(e instanceof Error?e.message:"An unknown error occurred.")}break}case"msg":case"query":{if(!o||!i)return void eM("Usage: /msg <user_name> <message>","ERROR");let t=null;for(let e of I){let r=e.participants.find(e=>e.user.name.toLowerCase()===o.toLowerCase());if(r){t=r.user;break}}if(!t)return void eM(`Error: User "${o}" not found.`,"ERROR");if(t.id===e.user.id)return void eM("You cannot send a private message to yourself.","ERROR");try{if(!(await fetch(`/api/chat/direct/${t.id}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:i})})).ok)throw Error("Failed to send private message.");eM(`Message sent to ${t.name}: ${i}`)}catch(e){eT(e instanceof Error?e.message:"An unknown error occurred.")}break}case"me":{if(!s)return void eM("Usage: /me <action>","ERROR");if(!A)return void eM("You must be in a room to perform an action.","ERROR");let t=`optimistic-${Date.now()}`,r=`* ${e.user.name} ${s}`,a={id:t,content:r,createdAt:new Date().toISOString(),user:e.user,chatRoomId:A.id,isOptimistic:!0,isAction:!0};L(e=>[...e,a]);try{await fetch("/api/chat/group/messages",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r,chatRoomId:A.id,isAction:!0})})}catch(e){eT(e instanceof Error?e.message:"An unknown error occurred."),L(e=>e.filter(e=>e.id!==t))}break}default:eM(`Unknown command: /${r}. Type /help for a list of commands.`,"ERROR")}},eT=(0,o.useCallback)((e,t)=>{console.error(e,t),$({title:e,description:t,variant:"destructive"})},[$]);(0,o.useEffect)(()=>{if(!t)return;let r=r=>{try{let a=JSON.parse(r.data);switch(console.log(`[GroupChat] 📥 WebSocket message received:`,a.type,a),a.type){case"CHAT_MESSAGE":if(console.log(`[GroupChat] 💬 Processing chat message for room ${a.data.chatRoomId}, current room: ${A?.id}`),console.log(`[GroupChat] 📝 Message data:`,a.data),a.data.user.id!==e?.user?.id){let e=a.data.chatRoomId===A?.id,t=!document.hidden,r=I.find(e=>e.id===a.data.chatRoomId)?.name||"Chat Room";e&&t||((0,m.toast)(e=>(0,s.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsx)("div",{className:"w-8 h-8 bg-green-500 rounded-full flex items-center justify-center",children:(0,s.jsx)("span",{className:"text-white text-sm font-bold",children:a.data.user.name?.charAt(0)||"U"})})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsxs)("p",{className:"font-medium text-gray-900",children:["\uD83D\uDCAC ",a.data.user.name," in #",r]}),(0,s.jsx)("p",{className:"text-sm text-gray-600 truncate max-w-48",children:a.data.content})]}),(0,s.jsx)("button",{onClick:()=>{m.toast.dismiss(e.id);let t=I.find(e=>e.id===a.data.chatRoomId);t&&eJ(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 #${r}`,{body:`${a.data.user.name}: ${a.data.content}`,icon:"/icons/apple-touch-icon-180x180.png"}),console.log(`[GroupChat] 🔔 Notification shown for message from ${a.data.user.name} in room ${r}`))}a.data.chatRoomId===A?.id?(console.log(`[GroupChat] ✅ Adding message to current room`),L(e=>{if(e.find(e=>e.id===a.data.id))return console.log(`[GroupChat] 🔄 Message already exists, skipping duplicate`),e;let t=e.find(e=>e.isOptimistic&&e.content===a.data.content&&5e3>Math.abs(new Date(e.createdAt).getTime()-new Date(a.data.createdAt).getTime()));if(t)return console.log(`[GroupChat] 🔄 Updating optimistic message`),e.map(e=>e.id===t.id?{...a.data,isOptimistic:!1}:e);console.log(`[GroupChat] ➕ Adding new message to chat`);let r=[...e,a.data];return console.log(`[GroupChat] 📊 Total messages now: ${r.length}`),r})):console.log(`[GroupChat] ⏭️ Message for different room (${a.data.chatRoomId}), skipping`),M(e=>e.map(e=>e.id===a.data.chatRoomId?{...e,lastMessage:a.data,_count:{...e._count,messages:(e._count?.messages||0)+1}}:e));break;case"ROOM_CREATED":let o=a.room;M(e=>[o,...e]);try{t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"JOIN_ROOM",data:{chatRoomId:o.id}}))}catch(e){console.error("Failed to send JOIN_ROOM for new room:",e)}$({title:"New Room Created",description:`You were added to "${o.name}".`});break;case"TYPING":a.data.chatRoomId===A?.id&&H(e=>{let t=new Set(e);return a.data.isTyping?t.add(a.data.userName):t.delete(a.data.userName),t});break;case"USER_KICKED":a.chatRoomId===A?.id&&(a.userId===e?.user?.id&&(eM(`You have been kicked from the room by ${a.kickedBy}.`,"ERROR"),A?.id===a.chatRoomId&&T(null)),M(e=>e.map(e=>e.id===a.chatRoomId?{...e,participants:e.participants.filter(e=>e.user.id!==a.userId)}:e)));break;case"PARTICIPANT_LIST_UPDATE":a.data.chatRoomId===A?.id&&et(a.data.participants)}}catch(e){console.error("Failed to parse WebSocket message:",e)}};return t.addEventListener("message",r),()=>t.removeEventListener("message",r)},[t,A?.id,e?.user?.id,$,eM,I]),(0,o.useEffect)(()=>{t&&r&&(console.log("[GroupChat] WebSocket connected, clearing joined rooms ref to ensure re-joining"),es.current.clear())},[t,r]);let eD=async()=>{P(!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 eM("Authentication required. Please log in again.","ERROR");let t=await e.json().catch(()=>({error:"Unknown error"}));throw Error(t.error||`HTTP ${e.status}: Failed to fetch chat rooms`)}let t=await e.json();if(console.log("[GroupChat] \uD83D\uDCCB Fetched chat rooms:",t.map(e=>({id:e.id,name:e.name,messageCount:e._count?.messages}))),!t||0===t.length){console.log("[GroupChat] ⚠️ No chat rooms found"),eM("No chat rooms available. Please contact an administrator.","ERROR"),M([]);return}M(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";eM(`Error: ${e}`,"ERROR"),M([])}finally{P(!1)}},eL=(0,o.useCallback)(async(e,t,r=!1)=>{try{console.log(`[GroupChat] 🔄 Fetching messages for room: ${e}${t?` (cursor: ${t})`:""}`),U(!0);let a=new URL("/api/chat/group/messages",window.location.origin);a.searchParams.set("chatRoomId",e),a.searchParams.set("limit","50"),t&&a.searchParams.set("cursor",t);let s=await fetch(a.toString(),{method:"GET",credentials:"same-origin",headers:{"Content-Type":"application/json"}});if(!s.ok){let e=await s.json().catch(()=>({error:"Unknown error"}));throw Error(e.error||`HTTP ${s.status}: Failed to fetch messages`)}let o=await s.json();console.log(`[GroupChat] 📋 Fetched ${o.messages?.length||0} messages for room ${e} (hasMore: ${o.pagination?.hasMore})`),r?L(e=>[...o.messages||[],...e]):L(o.messages||[]),o.pagination&&console.log(`[GroupChat] 📊 Pagination info:`,o.pagination)}catch(t){console.error(`[GroupChat] ❌ Error fetching messages for room ${e}:`,t),eM(`Failed to load chat history: ${t instanceof Error?t.message:"Unknown error"}`,"ERROR"),r||L([])}finally{U(!1)}},[]);(0,o.useEffect)(()=>{e&&eD()},[e]),(0,o.useEffect)(()=>{A&&eL(A.id)},[A,eL]);let eO=(0,o.useCallback)(e=>{A&&a&&(V(e),a(A.id,e))},[A,a]),eF=async t=>{if(t.preventDefault(),(O.trim()||ep)&&A&&e){if(console.log(`[GroupChat] 📤 Sending message to room ${A.id}:`,O.trim()),O.startsWith("/")&&!ep){await eA(O),F("");return}if(!A){eM("You must be in a room to send a message.","ERROR"),F("");return}try{let t={};if(ep){ef(!0);let e=new FormData;e.append("file",ep);let r=await fetch("/api/chat/upload",{method:"POST",body:e});if(!r.ok)throw Error("Failed to upload file");t=await r.json(),eb(null),ef(!1)}let r={content:O.trim()||t.fileName||"File attachment",chatRoomId:A.id,type:ep?ep.type.startsWith("image/")?"IMAGE":"FILE":"TEXT",replyToId:ev?.id,...t},a=`optimistic-${Date.now()}`,s={id:a,content:r.content,createdAt:new Date().toISOString(),user:e.user,chatRoomId:A.id,isOptimistic:!0,fileUrl:t.fileUrl,fileName:t.fileName,fileSize:t.fileSize,mimeType:t.mimeType,replyToId:ev?.id,replyTo:ev?{id:ev.id,content:ev.content,user:ev.user}:void 0};console.log(`[GroupChat] 🎯 Adding optimistic message:`,s),L(e=>[...e,s]),F(""),ew(null),ex(!1),eO(!1),console.log(`[GroupChat] 🚀 Sending API request...`);let o=await fetch("/api/chat/group/messages",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw Error("Message failed to send.");let n=await o.json();console.log("[GroupChat] ✅ Message saved to database:",n),L(e=>e.map(e=>e.id===a?{...n,isOptimistic:!1}:e))}catch(e){console.error(`[GroupChat] ❌ Error sending message:`,e),eT(e instanceof Error?e.message:"An unknown error occurred."),ef(!1),L(e=>e.filter(e=>e.id&&!e.id.startsWith("optimistic-")))}}},eG=async(t,r)=>{t&&t.preventDefault();let a=r||q;if(a.trim()&&e?.user){Z(!0);try{let e=await fetch("/api/chat/rooms",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.trim()})});if(!e.ok)throw Error("Failed to create room");let r=await e.json();t||eM(`Room "${r.name}" has been created.`),T(r),X(""),K(!1),$({title:"Room Created",description:`"${r.name}" has been created successfully.`})}catch(e){eT(e instanceof Error?e.message:"Failed to create room")}finally{Z(!1)}}},eP=async(e,t)=>{if(window.confirm(`Are you sure you want to delete the room "${t}"? This action cannot be undone.`))try{let r=await fetch(`/api/chat/rooms?roomId=${e}`,{method:"DELETE",credentials:"same-origin"});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to delete room")}$({title:"Room Deleted",description:`"${t}" has been permanently deleted.`}),M(t=>t.filter(t=>t.id!==e)),A?.id===e&&T(null)}catch(e){eT(e instanceof Error?e.message:"Failed to delete room")}},ez=async e=>{if(A)try{let t=await fetch(`/api/admin/chat/participants?roomId=${A.id}&userId=${e}`,{method:"DELETE",credentials:"same-origin"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to kick user")}M(t=>t.map(t=>t.id===A.id?{...t,participants:t.participants.filter(t=>t.user.id!==e)}:t)),$({title:"User Kicked",description:"The user has been removed from the room."})}catch(e){eT(e instanceof Error?e.message:"An unknown error occurred.")}},eU=(t,r)=>{if(t===e?.user?.id)return void eM("You cannot start a private chat with yourself.","ERROR");eh({recipientId:t,recipientName:r})},eW=(0,o.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),L(t=>t.map(t=>t.id===e?{...t,reactions:[...t.reactions||[],a]}:t)),(0,b.z)(t)}else{let e=await r.text();console.error("Failed to add reaction:",r.status,e),$({title:"Failed to add reaction",description:"Please try again",variant:"destructive"})}}catch(e){console.error("Failed to add reaction:",e),$({title:"Failed to add reaction",description:"Please try again",variant:"destructive"})}},[$]),eB=(0,o.useCallback)(async(t,r)=>{try{console.log("Removing reaction:",{messageId:t,emoji:r});let a=await fetch(`/api/chat/group/reactions?messageId=${t}&emoji=${r}`,{method:"DELETE",credentials:"same-origin"});if(a.ok)console.log("Reaction removed successfully"),L(a=>a.map(a=>a.id===t?{...a,reactions:(a.reactions||[]).filter(t=>t.emoji!==r||t.userId!==e?.user?.id)}:a));else{let e=await a.text();console.error("Failed to remove reaction:",a.status,e),$({title:"Failed to remove reaction",description:"Please try again",variant:"destructive"})}}catch(e){console.error("Failed to remove reaction:",e),$({title:"Failed to remove reaction",description:"Please try again",variant:"destructive"})}},[$]),e_=e=>{F(t=>t+e),(0,b.z)(e)},eH=(t,r)=>{t.reactions?.some(t=>t.emoji===r&&t.userId===e?.user?.id)?eB(t.id,r):eW(t.id,r)},eY=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]},eV=n().memo(({message:t})=>{let r=(0,d.GP)(new Date(t.createdAt),"HH:mm");if("SYSTEM"===t.type||"ERROR"===t.type)return(0,s.jsxs)("div",{className:`text-sm py-1 px-4 ${"ERROR"===t.type?"text-red-500":"text-gray-500 dark:text-gray-400"}`,children:[(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 mr-2",children:["[",r,"]"]}),(0,s.jsxs)("span",{className:"italic",children:["-- ",t.content]})]},t.id);if(t.isAction)return(0,s.jsxs)("div",{className:"text-sm py-1 px-4 text-purple-600 dark:text-purple-400 italic",children:[(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 mr-2",children:["[",r,"]"]}),(0,s.jsx)("span",{children:t.content})]},t.id);let a=t.user?.name||"Unknown User",o=t.user?.id===e?.user?.id,n=t.fileUrl&&(t.mimeType?.startsWith("image/")||/\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i.test(t.fileName||""));return(0,s.jsxs)("div",{className:"group text-sm py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-800/50",children:[t.replyTo&&(0,s.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,s.jsxs)("div",{className:"flex items-center gap-2",children:[t.replyTo.fileUrl&&t.replyTo.mimeType?.startsWith("image/")&&(0,s.jsx)("img",{src:t.replyTo.fileUrl,alt:"Reply thumbnail",className:"w-8 h-8 object-cover rounded border flex-shrink-0"}),(0,s.jsxs)("span",{className:"text-gray-600 dark:text-gray-400 flex-1",children:["Replying to ",t.replyTo.user.name,":"," ",t.replyTo.fileUrl?t.replyTo.mimeType?.startsWith("image/")?(0,s.jsx)("span",{className:"italic",children:"\uD83D\uDCF7 Image"}):(0,s.jsx)("span",{className:"italic",children:"\uD83D\uDCCE File attachment"}):(0,s.jsxs)(s.Fragment,{children:[t.replyTo.content.substring(0,100),t.replyTo.content.length>100?"...":""]})]})]})}),(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(v.A,{user:t.user,size:"sm",showTooltip:!0,clickable:!0,onClick:()=>ek({userId:t.user.id,isOpen:ej?.userId!==t.user.id||!ej?.isOpen})}),ej?.userId===t.user.id&&ej?.isOpen&&(0,s.jsx)(w.A,{userId:t.user.id,isOpen:!0,onClose:()=>ek(null),position:"right",onStartDirectMessage:(e,t)=>{eU(e,t)}})]}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,s.jsxs)("span",{className:"text-gray-400 dark:text-gray-500 text-xs",children:["[",r,"]"]}),(0,s.jsxs)("span",{className:`font-semibold text-sm ${o?"text-blue-600 dark:text-blue-400":"ADMIN"===t.user.role?"text-purple-600 dark:text-purple-400":"text-green-600 dark:text-green-400"}`,children:["ADMIN"===t.user.role?"⚖️ ":"",a]}),t.user.title&&(0,s.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["• ",t.user.title]}),t.isEdited&&(0,s.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:"(edited)"})]}),t.fileUrl&&(0,s.jsx)("div",{className:"mt-1 mb-2",children:n?(0,s.jsxs)("div",{className:"relative group",children:[(0,s.jsx)("img",{src:t.fileUrl,alt:t.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 r=document.createElement("div");r.className="relative max-w-4xl max-h-full";let a=document.createElement("button");a.className="absolute -top-10 right-0 text-white hover:text-gray-300 text-xl font-bold z-10",a.innerHTML="✕",a.onclick=()=>e.remove();let s=document.createElement("img");s.src=t.fileUrl||"",s.alt=t.fileName||"Image",s.className="max-w-full max-h-full object-contain rounded-lg";let o=document.createElement("div");o.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 n=document.createElement("div");n.className="flex-1";let i=document.createElement("div");if(i.className="font-medium",i.textContent="\uD83D\uDCF7 Image",n.appendChild(i),t.fileSize){let e=document.createElement("div");e.className="text-sm text-gray-300",e.textContent=eY(t.fileSize),n.appendChild(e)}let l=document.createElement("a");l.href=t.fileUrl||"",l.download=t.fileName||"image",l.className="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded flex items-center gap-2 transition-colors",l.innerHTML=`
                          <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <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>
                          </svg>
                          Download
                        `,o.appendChild(n),o.appendChild(l),r.appendChild(a),r.appendChild(s),r.appendChild(o),e.appendChild(r),document.body.appendChild(e);let d=t=>{"Escape"===t.key&&(e.remove(),document.removeEventListener("keydown",d))};document.addEventListener("keydown",d)},onError:e=>{let t=e.target;t.style.display="none";let r=t.nextElementSibling;r&&(r.style.display="block")},loading:"lazy"}),(0,s.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,s.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,s.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,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Image failed to load"}),(0,s.jsx)("a",{href:t.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,s.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,s.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,s.jsxs)("a",{href:t.fileUrl||"#",download:t.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,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsx)("svg",{className:"w-8 h-8 text-blue-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:t.mimeType?.includes("pdf")?"\uD83D\uDCC4 PDF Document":t.mimeType?.includes("doc")?"\uD83D\uDCDD Document":t.mimeType?.includes("spreadsheet")||t.mimeType?.includes("excel")?"\uD83D\uDCCA Spreadsheet":t.mimeType?.includes("zip")||t.mimeType?.includes("rar")?"\uD83D\uDDC3️ Archive":t.mimeType?.includes("video")?"\uD83C\uDFA5 Video":t.mimeType?.includes("audio")?"\uD83C\uDFB5 Audio":"\uD83D\uDCCE File Attachment"}),t.fileSize&&(0,s.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:eY(t.fileSize)})]}),(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.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,s.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"})})})]})}),t.content&&(0,s.jsx)("div",{className:"text-gray-800 dark:text-gray-200 break-words whitespace-pre-wrap",children:t.content}),(0,s.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,s.jsx)("button",{onClick:()=>eH(t,e),className:"text-sm hover:scale-110 transition-transform opacity-60 hover:opacity-100",title:`React with ${e}`,children:e},e)),(0,s.jsx)("button",{onClick:()=>{console.log("Reply button clicked for message:",t.id),ew(t)},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,s.jsx)(y.A,{messageId:t.id,reactions:t.reactions||[],onAddReaction:eW,onRemoveReaction:eB,className:"mt-1"})]})]})]},t.id)}),eJ=async e=>{if(A?.id===e.id)return void console.log(`[GroupChat] 📍 Already in room: ${e.name}`);if(console.log(`[GroupChat] 🚪 Switching to room: ${e.name} (${e.id})`),A?.id&&N&&es.current.has(A.id))try{console.log(`[GroupChat] 👋 Leaving room: ${A.name}`),await N(A.id),es.current.delete(A.id),console.log(`[GroupChat] ✅ Left room: ${A.name}`)}catch(e){console.error(`[GroupChat] ❌ Failed to leave room ${A.name}:`,e)}if(T(e),L([]),em(e.description||`Welcome to ${e.name}`),j&&!es.current.has(e.id))try{console.log(`[GroupChat] 🔌 Joining room via WebSocket: ${e.name}`),await j(e.id),es.current.add(e.id),console.log(`[GroupChat] ✅ Successfully joined room: ${e.name}`)}catch(t){console.error(`[GroupChat] ❌ Failed to join room ${e.name}:`,t),eM(`Failed to join room: ${e.name}`,"ERROR")}else es.current.has(e.id)&&console.log(`[GroupChat] 📍 Already joined room ${e.name}, just switching view`)},eK=async e=>{try{let t=await fetch(`/api/chat/rooms/${e}/participants`,{method:"GET",credentials:"same-origin"});if(!t.ok)throw Error("Failed to fetch participants.");let r=await t.json();et(r)}catch(e){eT(e instanceof Error?e.message:"An unknown error occurred.")}};return(0,o.useEffect)(()=>{A?.id&&eK(A.id)},[A?.id]),(0,o.useMemo)(()=>D.filter(e=>!e.isOptimistic||!D.find(t=>!t.isOptimistic&&t.content===e.content&&5e3>Math.abs(new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))),[D]),(0,o.useMemo)(()=>[...I].sort((e,t)=>{let r=e.lastMessage?.createdAt?new Date(e.lastMessage.createdAt).getTime():0;return(t.lastMessage?.createdAt?new Date(t.lastMessage.createdAt).getTime():0)-r}),[I]),(0,o.useMemo)(()=>A?.participants||[],[A?.participants]),(0,o.useEffect)(()=>{"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission().then(e=>{console.log("[GroupChat] Notification permission:",e)})},[]),e?.user?.role,e?.user?.isVerifiedLawyer||e?.user?.verificationStatus,(0,s.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:[eS&&(0,s.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,s.jsx)("button",{onClick:()=>eC(!eN),className:"p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,s.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,s.jsx)("div",{className:"flex-1 text-center",children:(0,s.jsx)("h2",{className:"font-bold text-base truncate",children:A?.name||"Group Chat"})}),(0,s.jsx)("button",{onClick:()=>eR(!eE),className:"p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,s.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.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"})})})]}),eS&&(eN||eE)&&(0,s.jsx)("div",{className:"absolute inset-0 bg-black bg-opacity-50 z-20",onClick:()=>{eC(!1),eR(!1)}}),(0,s.jsxs)("aside",{className:`
        flex flex-col border-r border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900
        ${eS?`absolute top-0 left-0 h-full w-80 max-w-[85vw] z-30 transform transition-transform duration-300 ${eN?"translate-x-0":"-translate-x-full"}`:"w-64 relative"}
      `,children:[(0,s.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,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("h1",{className:"text-base font-bold",children:"Channels"}),R()>0&&(0,s.jsxs)("div",{className:"relative",children:[(0,s.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,s.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,s.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:R()>9?"9+":R()})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[e?.user?.role==="ADMIN"&&(0,s.jsx)("button",{onClick:()=>K(!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,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})})}),(0,s.jsxs)("div",{title:r?"Connected":"Disconnected",className:"relative w-2.5 h-2.5",children:[(0,s.jsx)("div",{className:`w-full h-full rounded-full ${r?"bg-green-500":"bg-red-500"}`}),r&&(0,s.jsx)("div",{className:`absolute top-0 left-0 w-full h-full rounded-full ${r?"bg-green-500":"bg-red-500"} animate-ping`})]})]})]}),J&&(0,s.jsx)("div",{className:"p-3 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-800/50",children:(0,s.jsxs)("form",{onSubmit:eG,className:"space-y-2",children:[(0,s.jsx)("input",{type:"text",value:q,onChange:e=>X(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:Q}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{type:"submit",disabled:!q.trim()||Q,className:"w-full px-2 py-1 bg-blue-600 text-white text-xs rounded hover:bg-blue-700 disabled:opacity-50",children:Q?"Creating...":"Create"}),(0,s.jsx)("button",{type:"button",onClick:()=>{K(!1),X("")},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,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[E.size>0&&(0,s.jsxs)("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800",children:[(0,s.jsxs)("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1",children:["Direct Messages (",R(),")"]}),(0,s.jsx)("div",{className:"space-y-1",children:Array.from(E.entries()).map(([e,t])=>(0,s.jsxs)("button",{onClick:()=>eU(e,t.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,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"w-6 h-6 rounded-full bg-blue-500 text-white flex items-center justify-center text-xs font-bold",children:t.senderName.charAt(0).toUpperCase()}),t.unreadCount>0&&(0,s.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:t.unreadCount>9?"9+":t.unreadCount})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:`text-sm font-semibold truncate ${t.unreadCount>0?"text-blue-600 dark:text-blue-400":"text-gray-900 dark:text-gray-100"}`,children:t.senderName}),(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.lastMessage})]}),t.unreadCount>0&&(0,s.jsx)("span",{className:"text-xs px-1.5 py-0.5 bg-red-500 text-white rounded-full font-bold",children:t.unreadCount})]},e))})]}),G?(0,s.jsx)("div",{className:"p-2 space-y-2",children:(0,s.jsx)(k,{count:8,className:"h-8 w-full rounded"})}):(0,s.jsxs)("div",{className:"p-2 space-y-1",children:[(0,s.jsxs)("h2",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 px-1",children:["Channels ",I.length>0&&`(${I.length})`]}),0===I.length&&!G&&(0,s.jsxs)("div",{className:"text-center text-gray-500 py-4",children:[(0,s.jsx)("p",{className:"text-sm",children:"No channels available"}),!r&&(0,s.jsx)("button",{onClick:S,className:"mt-2 px-3 py-1 bg-blue-600 text-white rounded text-xs hover:bg-blue-700",children:"Reconnect"})]}),I.map(t=>{let r=A?.id===t.id,a=es.current.has(t.id);return(0,s.jsxs)("div",{className:"flex items-center group",children:[(0,s.jsxs)("button",{onClick:()=>eJ(t),className:`w-full text-left flex items-center gap-2 p-1.5 rounded transition-colors duration-100 ${r?"bg-blue-600 text-white font-semibold":"hover:bg-gray-100 dark:hover:bg-gray-800/50"}`,children:[(0,s.jsx)("span",{className:`font-mono font-bold ${r?"text-blue-200":"text-gray-400"}`,children:"#"}),(0,s.jsx)("span",{className:"flex-1 truncate",children:t.name}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[a&&(0,s.jsx)("div",{className:`w-2 h-2 rounded-full ${r?"bg-green-300":"bg-green-500"}`,title:`Connected to ${t.name}`}),t._count&&t._count.messages>0&&(0,s.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${r?"bg-white text-blue-600":"bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300"}`,children:t._count.messages})]})]}),e?.user?.role==="ADMIN"&&(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),eP(t.id,t.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 ${t.name}`,children:(0,s.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,s.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"})})})]},t.id)})]})]})]}),(0,s.jsx)("main",{className:`flex-1 flex flex-col bg-white dark:bg-gray-900 ${!eS?"border-r border-gray-200 dark:border-gray-800":""} ${eS?"pt-14":""}`,children:A?(0,s.jsxs)(s.Fragment,{children:[!eS&&(0,s.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,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsxs)("h2",{className:"text-base font-bold text-gray-900 dark:text-gray-100",children:["#",A.name]}),(0,s.jsx)("button",{onClick:()=>eL(A.id),className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded text-sm",title:"Refresh messages",children:"\uD83D\uDD04"}),(0,s.jsx)(x.A,{})]}),(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsx)("button",{onClick:()=>B(!W),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,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:(0,s.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,s.jsxs)("div",{className:`overflow-y-auto p-2 ${eS?"h-[calc(100%-8rem)]":"h-[19.5rem]"} touch-pan-y`,onScroll:()=>{ed(eI())},ref:ei,children:[ec&&(0,s.jsx)("div",{className:"text-center p-3 my-2 bg-gray-100 dark:bg-gray-800 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:ec})}),z?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full",children:[(0,s.jsx)("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),(0,s.jsx)("p",{className:"text-gray-500 dark:text-gray-400 mt-3 text-xs",children:"Loading Messages..."})]}):(0,s.jsxs)("div",{children:[0===D.length?(0,s.jsx)("div",{className:"text-center text-gray-500 dark:text-gray-400 py-8",children:(0,s.jsx)("p",{children:"No messages yet. Be the first to say something!"})}):D.map(e=>(0,s.jsx)(eV,{message:e},e.id)),(0,s.jsx)("div",{ref:er})]})]}),(0,s.jsx)(p.A,{roomId:A.id}),(0,s.jsxs)("footer",{className:"p-2 border-t border-gray-200 dark:border-gray-800",children:[(0,s.jsx)(l.AnimatePresence,{children:ev&&(0,s.jsx)(l.motion.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,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[ev.fileUrl&&ev.mimeType?.startsWith("image/")&&(0,s.jsx)("img",{src:ev.fileUrl,alt:"Reply thumbnail",className:"w-8 h-8 object-cover rounded border flex-shrink-0"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:["Replying to ",ev.user.name]}),(0,s.jsx)("p",{className:"text-sm text-gray-800 dark:text-gray-200 truncate",children:ev.fileUrl?ev.mimeType?.startsWith("image/")?(0,s.jsx)("span",{className:"italic",children:"\uD83D\uDCF7 Image"}):(0,s.jsx)("span",{className:"italic",children:"\uD83D\uDCCE File attachment"}):ev.content})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[!eS&&(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("button",{type:"button",onClick:()=>ex(!eg),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-xs",title:"Add emoji",children:"\uD83D\uDE00"}),(0,s.jsx)(b.A,{isOpen:eg,onClose:()=>ex(!1),onEmojiSelect:e_,position:"bottom"})]}),(0,s.jsx)("button",{onClick:()=>ew(null),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-xs p-1",children:"\xd7"})]})]})})}),(0,s.jsxs)("form",{onSubmit:eF,className:"relative",children:[(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsx)(f.A,{onFileSelect:eb,onRemoveFile:()=>eb(null),selectedFile:ep,uploading:ey,className:"flex-shrink-0"}),(0,s.jsxs)("div",{className:"flex-1 relative",children:[(0,s.jsx)("input",{type:"text",value:O,onChange:e=>{F(e.target.value),A&&a&&(e.target.value.length>0&&!Y?(V(!0),a(A.id,!0)):0===e.target.value.length&&Y&&(V(!1),a(A.id,!1)))},onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||eF(e)},onBlur:()=>{Y&&A&&a&&(V(!1),a(A.id,!1))},placeholder:ev?`Reply to ${ev.user.name}...`:ep?"Add a caption...":`Message #${A.name}`,className:`w-full bg-gray-100 dark:bg-gray-800 border-transparent rounded pl-3 ${eS?"pr-12":"pr-20"} py-2 text-sm transition-all ${ev?"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:z||ey}),!eS&&(0,s.jsxs)("div",{className:"absolute right-10 top-1/2 transform -translate-y-1/2",children:[(0,s.jsx)("button",{type:"button",onClick:()=>ex(!eg),className:"p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors",title:"Add emoji",children:(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.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,s.jsx)(b.A,{isOpen:eg,onClose:()=>ex(!1),onEmojiSelect:e_,position:"top"})]})]}),(0,s.jsx)(l.motion.button,{type:"submit",disabled:!O.trim()&&!ep||z||ey,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:ey?(0,s.jsx)("div",{className:"w-4 h-4 animate-spin rounded-full border-2 border-white border-t-transparent"}):(0,s.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 text-center",children:[eS?"Tap to send":"Press Enter to send"," • ",ep?`File: ${ep.name}`:"Drag & drop files or use \uD83D\uDCCE"]})]})]})]}):(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center text-gray-500 p-4",children:(0,s.jsx)("div",{className:"text-center max-w-sm",children:0===I.length?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-base",children:"No chat rooms available."}),(0,s.jsx)("p",{className:"text-sm mt-2 text-gray-400",children:"Please contact an administrator to create chat rooms."}),!r&&(0,s.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,s.jsx)("p",{className:"text-orange-600 dark:text-orange-400 text-sm",children:"⚠️ Connection issues detected"}),(0,s.jsx)("button",{onClick:S,className:"mt-2 px-4 py-2 bg-orange-600 text-white rounded text-sm hover:bg-orange-700 transition-colors",children:"Reconnect"})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-base",children:"No channel selected."}),(0,s.jsx)("p",{className:"text-sm mt-2 text-gray-400",children:eS?"Tap the menu to select a channel":"Click on a channel to start chatting"})]})})})}),(0,s.jsx)(l.AnimatePresence,{children:(W&&!eS||eE&&eS)&&A&&(0,s.jsxs)(l.motion.aside,{initial:{opacity:0,x:50},animate:{opacity:1,x:0},exit:{opacity:0,x:50},transition:{duration:.2},className:`
            border-l border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 flex flex-col
            ${eS?"absolute top-0 right-0 h-full w-80 max-w-[85vw] z-30":"w-64 relative"}
          `,children:[(0,s.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,s.jsxs)("h3",{className:"text-base font-bold",children:["Users (",ee.length,")"]}),(0,s.jsx)("button",{onClick:()=>{eS?eR(!1):B(!1)},className:"p-1.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",children:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,s.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,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:ee.filter(e=>e&&e.user).map(e=>{let t=E.get(e.user.id),r=t&&t.unreadCount>0;return(0,s.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,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(v.A,{user:e.user,size:"sm",showStatus:!0,clickable:!0,onClick:()=>ek({userId:e.user.id,isOpen:ej?.userId!==e.user.id||!ej?.isOpen})}),ej?.userId===e.user.id&&ej?.isOpen&&(0,s.jsx)(w.A,{userId:e.user.id,isOpen:!0,onClose:()=>ek(null),position:"left",onStartDirectMessage:(e,t)=>{eU(e,t)}}),"ADMIN"===e.role&&(0,s.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,s.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:`${t.unreadCount} unread message${t.unreadCount>1?"s":""}`,children:t.unreadCount>9?"9+":t.unreadCount})]}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)("p",{className:`text-sm font-semibold truncate cursor-pointer ${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:()=>{eU(e.user.id,e.user.name),eS&&eR(!1)},title:`${eS?"Tap":"Double-click"} to start private chat with ${e.user.name}${r?` (${t.unreadCount} unread)`:""}`,children:[e.user.name,r&&(0,s.jsxs)("span",{className:"ml-1 text-xs text-red-500 dark:text-red-400",children:["(",t.unreadCount,")"]})]})}),(0,s.jsx)("div",{className:"ml-auto",children:(0,s.jsx)(h.A,{participant:e,roomId:A.id,onKick:ez})})]},e.user.id)})})]})}),(0,s.jsx)(l.AnimatePresence,{children:!1}),(0,s.jsx)(l.AnimatePresence,{children:eu&&(0,s.jsx)(g.A,{chatId:eu.recipientId,onClose:()=>eh(null)})})]})};a()}catch(e){a(e)}})},93819:(e,t,r)=>{r.d(t,{A:()=>o});var a=r(8732);r(82015);var s=r(73392);let o=()=>{let{connected:e,connectionState:t,connectionStats:r,reconnect:o}=(0,s.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 ${(()=>{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... (${r.reconnectAttempts})`;case"disconnected":return"Disconnected";default:return"Unknown"}})()})]}),"disconnected"===t&&r.reconnectAttempts>=10&&(0,a.jsx)("button",{onClick:o,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]})]})]})]})]})}}};

CasperSecurity Mini