1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8752],{52660:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/chat/admin",function(){return n(35545)}])},35545:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return H}});var r=n(85893),o=n(48862),s=n(67294),l=n(2734),i=n(98396),a=n(99226),c=n(16688),d=n(90629),u=n(51233),m=n(15861),x=n(23795),h=n(83321),p=n(98619),f=n(18987),g=n(69661),j=n(59334),v=n(87918),S=n(67720),Z=n(49051),b=n(18770),I=n(82134),w=n(95066),y=n(85376),C=n(37251),T=n(93659);let E=[T.v.adminId],_=e=>{let{onSelectChatRoomId:t,isSmallScreen:n,incommingMsg:o,user:l,roomType:i,headerLabel:T,onClickPingAdmin:_}=e,[k,M]=(0,s.useState)(),[L,R]=(0,s.useState)(),z=(0,c.PV)(),{mutation:N,isLoading:F}=(0,c.Uo)(),H=null==l?void 0:l.userId,[P,A]=(0,s.useState)(!1),[O,W]=(0,s.useState)(void 0);function B(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];z.mutate({cursor:t?O:void 0,limit:null!=e?e:15,roomTypes:[i]},{onSuccess:e=>{let n=e.data,r=e.nextCursor;W(r),t?M(e=>[...e||[],...n]):M(n)},onError:e=>{console.log("initial load error",e)},onSettled:()=>{A(!1)}})}function X(e){let n=null==k?void 0:k.filter(t=>t.roomId==e);if(n&&n.length>0){let r=n[0];t(e,r)}R(e)}return(0,s.useEffect)(()=>{o.length>0&&H&&function(e,t){let n=e.filter(e=>e.messages.length>0),r=(0,b.Rh)(n,t),o=[...k||[]],s=new Map(o.map(e=>[e.roomId,e]));for(let e of r){let t=e.roomId==L;s.has(e.roomId)?s.set(e.roomId,e):o.push({...e,unreadMessageCount:t?0:e.unreadMessageCount})}let l=o.map(e=>s.get(e.roomId)||e),i=(0,b.$I)(l);M(i)}(o,H)},[o]),(0,s.useEffect)(()=>{if(L){let e=null==k?void 0:k.map(e=>L==e.roomId?{...e,unreadMessageCount:0}:e);M(e)}},[L]),(0,s.useEffect)(()=>{B(15,!1)},[]),(0,r.jsxs)(d.Z,{elevation:2,sx:{width:n?"100%":"340px",minWidth:n?"100%":"340px",display:"flex",flexDirection:"column",borderRight:"2px solid #eee",borderRadius:"0px",maxHeight:"100%"},children:[(0,r.jsxs)(u.Z,{direction:"row",justifyContent:"space-between",sx:{p:2,borderBottom:"1px solid #eee",height:"90px",minHeight:"70px"},children:[(0,r.jsxs)(u.Z,{direction:"column",children:[(0,r.jsx)(m.Z,{variant:"h6",children:T||"à¹à¸à¸"}),"Consult"===i&&(0,r.jsx)(x.Z,{href:I.q.subscription,target:"_blank",children:(0,r.jsx)(w.jQ,{chipText:(0,r.jsxs)(u.Z,{direction:"row",gap:.5,alignItems:"center",children:[(0,r.jsx)(y.Z,{}),(0,r.jsx)(m.Z,{variant:"body2",children:"สำหรัภPremium"})]})})})]}),(null==l?void 0:l.userId)&&(null==l?void 0:l.userId)!==E[0]&&(0,r.jsxs)(h.Z,{sx:{height:"50px"},variant:"contained",onClick:function(){H||(0,C.l)(),N.mutate({userIds:E,roomType:i},{onSuccess:e=>{B(15,!1)},onError:e=>{console.log("chat creation error",e),(null==k?void 0:k[0].roomId)&&X(null==k?void 0:k[0].roomId)}})},disabled:F,children:[" ",H?"à¸à¸±à¸à¸«à¸²à¹à¸à¸à¸¡à¸´à¸":"à¹à¸à¹à¸²à¸ªà¸¹à¹à¸£à¸°à¸à¸"]})]}),(0,r.jsx)(a.Z,{sx:{overflow:"auto"},onScroll:function(e){let t=e.currentTarget,n=t.scrollTop+t.clientHeight>=t.scrollHeight-10;n&&!P&&O&&(A(!0),B(15,!0))},children:null==k?void 0:k.map(e=>{var t;let{roomId:n,lastMessage:o,lastMessageAt:i,members:a,unreadMessageCount:c}=e,{displayName:d,profileImage:x,currentMemberTier:h}=a.filter(e=>e.userId!=H).length>0?a.filter(e=>e.userId!=H)[0]:{displayName:"à¹à¸¡à¹à¸£à¸°à¸à¸¸",profileImage:"",currentMemberTier:"Standard"};return(0,r.jsxs)(s.Fragment,{children:[(0,r.jsxs)(p.Z,{selected:n===L,onClick:()=>X(n),children:[(0,r.jsx)(f.Z,{children:(0,r.jsx)(g.Z,{src:x,alt:x,style:{width:"40px",height:"40px"}})}),(0,r.jsx)(j.Z,{primary:(0,r.jsxs)(u.Z,{direction:"row",justifyContent:"space-between",children:[(0,r.jsxs)(m.Z,{children:[d,(null==l?void 0:l.role)==="Admin"&&"Standard"!==h&&(0,r.jsx)(v.Z,{label:h,size:"small",color:"Premium"===h?"error":"success",sx:{ml:1}})]}),c&&c>=0?(0,r.jsx)(v.Z,{color:"success",label:c>99?"99+":c,size:"small"}):(0,r.jsx)(r.Fragment,{})]}),secondary:(0,r.jsxs)(u.Z,{direction:"row",justifyContent:"space-between",children:[(0,r.jsx)(m.Z,{variant:"body2",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"120px"},children:(null==o?void 0:o.messageType)==="Text"?null!==(t=null==o?void 0:o.message)&&void 0!==t?t:"":"รูà¸à¸ าà¸"}),(0,r.jsx)(m.Z,{variant:"caption",children:i?(0,Z.rJ)(i):""})]})})]}),(0,r.jsx)(S.Z,{})]},e.roomId)})})]})};var k=n(47138),M=n(88541),L=n(14852),R=n(16659);function z(e){let{roomType:t,roomListHeaderLabel:n}=e,o=(0,l.Z)(),c=(0,i.Z)(o.breakpoints.down("sm")),[d,u]=(0,s.use
1State)(void 0),[m,x]=(0,s.useState)(),[h,p]=(0,s.useState)(!1),[f,g]=(0,s.useState)(!1),[j,v]=(0,s.useState)(null),S=(0,s.useRef)(null),Z=(0,s.useRef)(null),b=(0,s.useRef)(0),[I,w]=(0,s.useState)([]),[y,C]=(0,s.useState)(),{user:E}=(0,L.C)(e=>e.auth);function z(e,t){u(e),x(t),c&&p(!0)}async function N(){let e=T.v.apiV2Url,n="".concat(e,"/api/chat/room/messages/stream?roomType=").concat(t),r=await R.B.getAccessToken(),o=new M.EventSourcePolyfill(n,{headers:{Authorization:"Bearer ".concat(r)}});return o.onopen=()=>{g(!0),v(null)},o.onmessage=e=>{try{let t=JSON.parse(e.data);w(t)}catch(e){v("Failed to parse message data")}},o.addEventListener("heartbeat",e=>{console.log("heartbeat event:",e)}),o.onerror=()=>{if(g(!1),o.close(),S.current=null,b.current<5){let e=1e3*Math.pow(2,b.current);Z.current=setTimeout(()=>{b.current++,N()},e)}else v("Max reconnection attempts reached")},S.current=o,o}return(0,s.useEffect)(()=>{if(I){let e=I.filter(e=>e.roomId==d);e&&C(e)}},[I,d]),(0,s.useEffect)(()=>(N(),()=>{S.current&&S.current.close(),Z.current&&clearTimeout(Z.current),g(!1)}),[]),(0,r.jsx)(a.Z,{display:"flex",height:{xs:"calc(100vh - 125px)",sm:"calc(100vh - 150px)"},children:c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.Z,{sx:{width:"100%",display:h?"none":"block"},children:(0,r.jsx)(_,{onSelectChatRoomId:z,isSmallScreen:c,incommingMsg:I,user:E,roomType:t,headerLabel:n})}),h&&(0,r.jsx)(k.z,{roomId:d,isSmallScreen:c,onCloseChatWindow:function(){p(!1)},chatInfo:m,incommingMsgs:y,user:E})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(_,{onSelectChatRoomId:z,isSmallScreen:c,incommingMsg:I,user:E,roomType:t,headerLabel:n}),(0,r.jsx)(k.z,{roomId:d,isSmallScreen:c,chatInfo:m,incommingMsgs:y,user:E})]})})}var N=n(88409),F=n(40044);function H(){let[e,t]=(0,s.useState)(0),{user:n}=(0,L.C)(e=>e.auth),l=(null==n?void 0:n.role)==="Admin",i=(e,n)=>{t(n)};return l?(0,r.jsxs)(o.Z,{sx:{paddingX:0,overflow:{xs:"hidden",sm:"hidden"}},maxWidth:"xl",children:[(0,r.jsxs)(N.Z,{value:e,onChange:i,sx:{mt:{xs:2,sm:0}},children:[(0,r.jsx)(F.Z,{label:"à¸à¸£à¸¶à¸à¸©à¸²",sx:{fontSize:"18px"}}),(0,r.jsx)(F.Z,{label:"รายà¸à¸²à¸à¸à¸±à¸à¸«à¸²",sx:{fontSize:"18px"}}),(0,r.jsx)(F.Z,{label:"à¸à¸´à¸à¸¡ à¹à¸à¸°à¸à¸³",sx:{fontSize:"18px"}})]}),0===e&&(0,r.jsx)(z,{roomType:"Consult",roomListHeaderLabel:"à¸à¸£à¸¶à¸à¸©à¸²à¸à¸¹à¹à¹à¸à¸µà¹à¸¢à¸§à¸à¸²à¸"}),1===e&&(0,r.jsx)(z,{roomType:"ReportIssue",roomListHeaderLabel:"รายà¸à¸²à¸à¸à¸±à¸à¸«à¸²"}),2===e&&(0,r.jsx)(z,{roomType:"Feedback",roomListHeaderLabel:"à¸à¸´à¸à¸¡ à¹à¸à¸°à¸à¸³"})]}):(0,r.jsx)(m.Z,{children:"Page Not Found"})}}},function(e){e.O(0,[6572,9440,9212,9774,2888,179],function(){return e(e.s=52660)}),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.