amworkchat
Version:
Customizable React chat component for workplace communication
1 lines • 58.6 kB
JavaScript
import e,{useState as t,useRef as r,useCallback as n,useEffect as a,createContext as l,useContext as o,Fragment as s}from"react";import{Pause as i,Play as c,X as u,File as d,Send as m,Users as f,Expand as g,Shrink as p,Maximize as h,Minimize as v,Upload as y,Reply as x,Trash2 as b,Star as w,CheckCheck as E,ArrowUpFromLine as N,SquareArrowOutUpRight as C,ChevronUp as k,MessageSquareText as I,UserRound as D,Search as U,BotIcon as M}from"lucide-react";import T from"axios";import S from"moment";import{io as A}from"socket.io-client";import{Light as P}from"react-syntax-highlighter";import{docco as _}from"react-syntax-highlighter/dist/esm/styles/hljs";function R(){return R=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},R.apply(null,arguments)}var j=T,z=T.create({baseURL:"https://chatapi.nte.ai/v3",headers:{"Content-Type":"application/json"}});function L(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}z.interceptors.request.use(function(e){var t=localStorage.getItem("authToken");return console.log("tokentoken",t),t&&(e.headers.Authorization=t),e},function(e){return Promise.reject(e)});var F=/*#__PURE__*/l();function O(e,t){try{var r=e()}catch(e){return t(!0,e)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,r)}var B=function(l){var o,s=l.children,i=t([]),c=i[0],u=i[1],d=t({}),m=d[0],f=d[1];t({});var g=t([]),p=g[0],h=g[1],v=t(!0),y=v[0],x=v[1],b=t({}),w=b[0],E=b[1],N=t(""),C=N[0],k=N[1],I=t(""),D=I[0],U=I[1],M=r({}),T=r({}),P=t("chat"),_=P[0],j=P[1],B=t(3),G=B[0],W=B[1],Y=t([]),H=Y[0],J=Y[1],V=t([]),K=V[0],q=V[1],$=t([]),Q=$[0],X=$[1],Z=t([]),ee=Z[0],te=Z[1],re=t([]),ne=re[0],ae=re[1],le=t([]),oe=le[0],se=le[1];t("");var ie=t("")[0],ce=t({}),ue=ce[0],de=ce[1],me=t(""),fe=me[0],ge=me[1],pe=t(null),he=pe[0],ve=pe[1],ye=t(!1),xe=ye[0],be=ye[1],we=t(!1),Ee=we[0],Ne=we[1],Ce=t(!1),ke=Ce[0],Ie=Ce[1],De=t(!1),Ue=De[0],Me=De[1],Te=r(c),Se=r(H),Ae=r(xe),Pe=t(null),_e=Pe[0],Re=Pe[1],je=t(!1),ze=je[0],Le=je[1],Fe=r(null),Oe=r(null),Be=t(""),Ge=Be[0],We=Be[1],Ye=t(!1),He=Ye[0],Je=Ye[1],Ve=t(""),Ke=Ve[0],qe=Ve[1],$e=t(""),Qe=$e[0],Xe=$e[1],Ze=t(""),et=Ze[0],tt=Ze[1],rt=t(""),nt=rt[0],at=rt[1],lt=r(null),ot=t(""),st=ot[0],it=ot[1],ct=r(null),ut=r(null),dt=t(!1),mt=dt[0],ft=dt[1],gt=t({top:0,left:0,width:0})[1],pt=t(""),ht=pt[0],vt=pt[1],yt=t([]),xt=yt[0],bt=yt[1],wt=ne.filter(function(e){return e.userId.name.toLowerCase().includes(ht.toLowerCase())}),Et=function(){Re(null),Le(!1),Fe.current.value="",E(function(e){var t;return R({},e,((t={})[fe]="",t))})},Nt=n(function(e){e.preventDefault(),e.stopPropagation(),Je(!0)},[]),Ct=n(function(e){e.preventDefault(),e.stopPropagation(),Je(!0)},[]),kt=n(function(e){e.preventDefault(),e.stopPropagation(),Je(!1)},[]),It=n(function(e){e.preventDefault(),e.stopPropagation(),Je(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0&&(Re(e.dataTransfer.files[0]),Le(!0))},[]);a(function(){Te.current=c},[c]),a(function(){Se.current=H,H.length>0&&localStorage.setItem("userListStore",JSON.stringify(H))},[H]),a(function(){Ae.current=xe},[xe]);var Dt=function(){try{var e=O(function(){return L(function(){return Promise.resolve(z.get("chatUser/userList")).then(function(e){"success"===e.data.status&&(J(e.data.response),te(e.data.response))})},function(e){console.error("fetchChatUserList error:",e)})},function(e,t){if(e)throw t;return t});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}};function Ut(e,t,r){if(!Array.isArray(e))return console.error("Expected an array, but got:",e),[];var n=e.findIndex(function(e){return e._id==t});if(-1===n)return e;var a=e.splice(n,1)[0];return e.splice(r,0,a),e}a(function(){var e=localStorage.getItem("authUser");if(""!==fe){c.includes(fe);var t=c.find(function(e){return e===fe})||fe,r=oe.map(function(t){var r,n,a,l,o=((null==(r=t.fromUserId)?void 0:r._id)||(null==t||null==(n=t.userId)?void 0:n._id))===e,s=(null==(a=t.toUserId)?void 0:a._id)!==e?t.toUserId:t.fromUserId;return"user"===et.type?{_id:t._id,sender:o?"me":"reciver",text:t.messageContent,isRead:t.isRead,user:s,time:S(null==t?void 0:t.updatedAt).format("ddd hh:mm A"),type:null==t?void 0:t.messageType,link:(null==t?void 0:t.fileUrl)||"",fileType:(null==t?void 0:t.fileType)||"",createdAt:null==t?void 0:t.createdAt,isForwarded:t.isForwarded,isDeleted:t.isDeleted,isStared:t.isStared,replyMessageId:t.replyMessageId||""}:"bot"===Qe.type?{_id:t._id,sender:o?"me":"reciver",text:t.messageContent,time:S(null==t?void 0:t.updatedAt).format("ddd hh:mm A"),type:null==t?void 0:t.messageType,link:(null==t?void 0:t.fileUrl)||"",fileType:(null==t?void 0:t.fileType)||"",createdAt:null==t?void 0:t.createdAt,ctaInfo:(null==t?void 0:t.ctaInfo)||"",ctaData:t.ctaData}:{_id:t._id,sender:o?"me":"reciver",text:t.messageContent,isRead:t.isRead,user:t.userId,time:S(null==t?void 0:t.updatedAt).format("ddd hh:mm A"),type:null==t?void 0:t.messageType,link:(null==t?void 0:t.fileUrl)||"",fileType:(null==t?void 0:t.fileType)||"",createdAt:null==t?void 0:t.createdAt,name:null==t||null==(l=t.userId)?void 0:l.name,isForwarded:t.isForwarded,isDeleted:t.isDeleted,isStared:t.isStared,replyMessageId:t.replyMessageId||""}});console.log("modifychat",r);var n={};r.forEach(function(e){var t=S(e.createdAt).format("YYYY-MM-DD");n[t]||(n[t]=[]),n[t].push(e)});var a=Object.keys(n).sort(function(e,t){return S(t).diff(S(e))}).map(function(e){var t=S(e);return{date:t.isSame(S(),"day")?"Today":t.isSame(S().subtract(1,"day"),"day")?"Yesterday":t.format("DD MMM YYYY"),chats:n[e],chatUserId:m[fe]}});if(c.length>=G){if(!c.includes(t)){var l=[].concat(c);l.shift(),l.push(t),u(l)}de(function(e){var r;return R({},e,((r={})[t]=a,r))})}else u(function(e){return e.includes(t)?e:[].concat(e,[t])}),de(function(e){var r;return R({},e,((r={})[t]=a,r))});setTimeout(function(){var e=document.getElementById("chat-input-"+t);e&&e.focus()},100)}},[oe,Qe,et]),a(function(){var e=localStorage.getItem("authToken");if(localStorage.getItem("authUser"),e){var t="https://chatapi.nte.ai/chat";console.log("apiUrl",t);var r=A(t,{transports:["websocket"],auth:{token:e}});return r.on("connect",function(){console.log("Connected to socket server with ID:",r.id)}),r.on("disconnect",function(e){console.log("Socket disconnected:",e)}),r.on("receiveMessage",function(e){if(localStorage.getItem("authUser"),console.log("Received message:",e),Te.current.includes(e.fromUserId._id)||Ne(!0),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.fromUserId._id,0).map(function(t){return t._id==e.fromUserId._id?R({},t,{isDeleted:!1,messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,msg:"New",unReadCount:Te.current.includes(e.fromUserId._id)?0:t.unReadCount<0?1:t.unReadCount+1}):t});Se.current=t,J(t)}else console.error("userChatRef.current is not an array:",Se.current);be(!1),Te.current.includes(e.fromUserId._id)&&(Ae.current=!0,be(!0),se(function(t){return[e].concat(t)}),r.emit("readMessage",{user_id:e.fromUserId._id}))}),r.on("redMessage",function(e){se(function(t){return t.map(function(t){return Te.current.includes(e)?R({},t,{isRead:!0}):t})})}),r.on("ownMessage",function(e){if(console.log("ownMessage",e),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.toUserId._id,0).map(function(t){return t._id==e.toUserId._id?R({},t,{messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,msg:"Read",isDeleted:!1}):t});Se.current=t,J(t)}else console.error("userChatRef.current is not an array:",Se.current);Te.current.includes(e.toUserId._id)&&se(function(t){return[e].concat(t)})}),r.on("deletedMessage",function(e){console.log("deletedMessage response:",e,e.fromUserId,Te.current._id),J(function(t){return t.map(function(t){return t.chatUserId===e.chatUserId&&e._id===t.messageId?R({},t,{isDeleted:!0}):t})}),Te.current.includes(e.fromUserId)&&se(function(t){return t.map(function(t){return t._id===e._id?R({},t,{isDeleted:!0}):t})})}),r.on("receiveGroupMessage",function(e){if(Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.groupId,0).map(function(t){return t.chatUserId==e.groupId?R({},t,{messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,isDeleted:!1}):t});Se.current=t,J(t)}else console.error("newDatanewDatanewData.current is not an array:",Se.current);Te.current.includes(e.groupId)&&se(function(t){return[e].concat(t)})}),r.on("deleteGroupMessage",function(e){if(console.log("deleteGroupMessage",e),se(function(t){return t.map(function(t){return t._id===e.messageId?R({},t,{isDeleted:!0}):t})}),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.groupId,0).map(function(t){return t.chatUserId==e.groupId&&t.messageId===e.messageId?R({},t,{createdAt:new Date,isDeleted:!0}):t});Se.current=t,J(t)}else console.error("newDatanewDatanewData.current is not an array:",Se.current)}),r.on("deleteGroupMessage",function(e){if(console.log("deleteGroupMessage",e),se(function(t){return t.map(function(t){return t._id===e.messageId?R({},t,{isDeleted:!0}):t})}),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.groupId,0);console.log("newDatanewDatanewDataarr",t);var r=t.map(function(t){return t.chatUserId==e.groupId?R({},t,{createdAt:new Date,isDeleted:!0}):t});console.log("newDatanewDatanewsadasData",r),Se.current=r,J(r)}else console.error("newDatanewDatanewData.current is not an array:",Se.current)}),r.on("botMessage",function(e){if(console.log("botMessage response:",e),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.toUser,0);console.log("newDatanewDatanewDataarr",t);var r=t.map(function(t){return t._id==e.toUser?R({},t,{messageContent:e.messageContent,createdAt:e.createdAt}):t});console.log("newDatanewDatanewData",r),Se.current=r,J(r)}else console.error("newDatanewDatanewData.current is not an array:",Se.current);Te.current.includes(e.toUser)&&se(function(t){return[e].concat(t)})}),r.on("initiateBot",function(e){if(console.log("botMessageinitiateBot response:",e),Array.isArray(Se.current)){var t=Ut([].concat(Se.current),e.toUser,0);console.log("newDatanewDatanewDataarr",t);var r=t.map(function(t){return t._id==e.toUser?R({},t):t});console.log("newDatanewDatanewData",r),Se.current=r,J(r)}else console.error("newDatanewDatanewData.current is not an array:",Se.current)}),ve(r),function(){r&&r.disconnect()}}},[]),a(function(){var e=JSON.parse(localStorage.getItem("userListStore")||"[]");0==H.length&&Ue&&(J(e),setTimeout(function(){Me(!1)},200))},[Ue]),a(function(){"undefined"!=typeof window&&(localStorage.setItem("activeChats",JSON.stringify(c)),localStorage.setItem("minimizedChats",JSON.stringify(p)),localStorage.setItem("newMessage",JSON.stringify(ue)))},[c,p,ue]),a(function(){if("undefined"!=typeof window){var e=localStorage.getItem("activeChats"),t=localStorage.getItem("minimizedChats"),r=localStorage.getItem("newMessage");e&&u(JSON.parse(e)),t&&h(JSON.parse(t)),r&&E(JSON.parse(r))}},[]);var Mt=function(e){var t=M.current[e];t&&(t.style.height="auto",t.style.height=t.scrollHeight+"px")},Tt=function(){if(ct.current){var e=ct.current.getBoundingClientRect();gt({top:e.top-250,left:e.left,width:e.width}),ft(!0)}},St=function(e,t){try{var r=m[e]||[],n=function(){if(0===r.length)return Promise.resolve(function(e,t){try{var r=L(function(){return Promise.resolve(z.post("chatUser/addChatUser",{toUser:e})).then(function(r){"success"===r.data.status&&(f(function(t){var n,a=t[e]||[];return a.includes(r.data.chatUserId)?t:R({},t,((n={})[e]=[].concat(a,[r.data.chatUserId]),n))}),Pt(e,r.data.chatUserId,t))})},function(e){console.log("d",e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}(e,t)).then(function(){});Pt(e,r[0],t)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},At=function(e,t){try{return _t(e,t),Promise.resolve()}catch(e){return Promise.reject(e)}},Pt=function(e,t,r){var n;if(localStorage.getItem("authUser"),null!=(n=w[e])&&n.trim()){he.emit("sendMessage",{user_id:e,messageType:_e?"F":"M",message:w[e],chatUserId:t,fileType:_e?_e.type:"",fileUrl:r||"",replyMessageId:nt._id||""}),E(function(t){var r;return R({},t,((r={})[e]="",r))}),We(""),Et(),at("");var a=M.current[e];a&&(a.style.height="auto")}},_t=function(e,t){try{var r;if(null!=(r=w[e])&&r.trim()){var n={groupId:null==Ke?void 0:Ke.chatUserId,messageType:_e?"F":"M",message:w[e],fileType:_e?_e.type:"",fileUrl:t||"",replyMessageId:nt._id||"",mentionedUsers:xt.map(function(e){var t;return null==e||null==(t=e.userId)?void 0:t._id})};he.emit("sendGroupMessage",n),E(function(e){var t;return R({},e,((t={})[null==Ke?void 0:Ke.chatUserId]="",t))}),We(""),at(""),Et(),bt([])}return Promise.resolve()}catch(e){return Promise.reject(e)}};a(function(){c.forEach(function(e){T.current[e]&&!p.includes(e)&&T.current[e].scrollIntoView({behavior:"smooth"})})},[c,p,oe]),a(function(){""!==Ge&&("group"===Ke.type?At(fe,Ge):St(fe,Ge))},[Ge]);var Rt=((o={activeChats:c,minimizedChats:p,newMessage:w,messageEndRef:T,handleUserClick:function(e){ge(null==e?void 0:e._id),ft(!1),bt([]),"group"===(null==e?void 0:e.type)?(tt(""),function(e){try{var t=L(function(){return Promise.resolve(z.get("/group/history/"+e.chatUserId)).then(function(t){"success"===t.data.status&&(f(e.chatUserId),se(t.data.chatHistory))})},function(e){console.log("fetchGroupChatHistory",e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}(e),qe(e),function(e){try{var t=L(function(){return Promise.resolve(z.get("/group/groupInfo/"+e)).then(function(e){console.log("fetchChatGroupInfo",e.data),ae("success"===e.data.status?e.data.groupInfo.userList:[])})},function(e){console.log("fetchChatGroupInfo",e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}(null==e?void 0:e.chatUserId)):"bot"===(null==e?void 0:e.type)?(function(e){try{var t=L(function(){return Promise.resolve(z.get("/bot/chatHistory/"+e.chatUserId)).then(function(e){console.log("fetchBotChatHistory",e.data),"success"===e.data.status&&se(e.data.chatList)})},function(e){console.log("fetchBotChatHistory",e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}(e),Xe(e)):(qe(""),function(e){try{var t=L(function(){return Promise.resolve(z.post("chatUser/chatHistory",{toUser:e})).then(function(t){console.log("fetchChatHistory",t.data),"success"===t.data.status&&(se(t.data.chatHistory),""!=t.data.chatUserId&&f(function(r){var n,a=r[e]||[];return a.includes(t.data.chatUserId)?r:R({},r,((n={})[e]=[].concat(a,[t.data.chatUserId]),n))}))})},function(e){console.log("fetchChatHistory",e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}(null==e?void 0:e._id),tt(e)),he.emit("readMessage",{user_id:null==e?void 0:e._id});var t=Se.current.map(function(t){return t._id==(null==e?void 0:e._id)?R({},t,{msg:"Read",unReadCount:0}):t}),r=JSON.stringify(H)===JSON.stringify(t);Se.current=t,r||J(t)},toggleMinimize:function(e){h(function(t){return t.includes(e)?t.filter(function(t){return t!==e}):[].concat(t,[e])})},closeChat:function(e){u(function(t){return t.filter(function(t){return t!==e})}),h(function(t){return t.filter(function(t){return t!==e})})},handleMessageChange:function(e,t){if(ge(e),E(function(r){var n;return R({},r,((n={})[e]=t,n))}),"group"===Ke.type){var r=t.lastIndexOf("@");if(console.log("valueatIndex",t,r),-1!==r){var n=t.substring(r+1);""===n?(vt(""),Tt()):n.includes(" ")?ft(!1):(vt(n),mt||Tt())}else ft(!1);bt(function(e){return e.filter(function(e){return t.includes("@"+e.userId.name)})})}},sendMessage:St,handleKeyDown:function(e,t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),St(e))},minimizedContact:y,setMinimizedContact:x,activeTab:_,setActiveTab:j,handleSwitchTab:function(e){j(e),"contact"===e?function(){try{var e=O(function(){return L(function(){return Promise.resolve(z.get("chatUser/contactList")).then(function(e){console.log("fetchContacts",e.data),"success"===e.data.status&&(q(e.data.userData),X(e.data.userData))})},function(e){console.log("fetchContacts",e)})},function(e,t){if(e)throw t;return t});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}():Dt()},fetchChatUserList:Dt,userList:H,contactList:K,maxChat:G,setMaxChat:W,messages:oe,setMessages:se,chats:ue,setChats:de,messageAlert:xe,setMessageAlert:be,setToUser:ge,handleAttachmentClick:function(e){ge(e),Fe.current.click()},fileInputRef:Fe,handleFileSelect:function(e){e.target.files.length>0&&(Re(e.target.files[0]),Le(!0))},showPreviewDialog:ze,isImageFile:function(e){return e&&e.type.startsWith("image/")},handleCancelFileUpload:Et,formatFileSize:function(e){return e<1024?e+" B":e<1048576?(e/1024).toFixed(1)+" KB":(e/1048576).toFixed(1)+" MB"},fileToUpload:_e,fetchUploadFileApi:function(e){try{var t=L(function(){var e=new FormData;return e.append("files",_e),Promise.resolve(z.post("chatFile/fileUpload",e,{headers:{"Content-Type":"multipart/form-data"}})).then(function(e){"success"===e.data.status&&(console.log("fetchUploadFileApi",e.data),We(e.data.url),E(function(e){var t;return R({},e,((t={})[fe]=_e.name,t))}))})},function(){});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},isDragging:He,handleDragOver:Nt,handleDragEnter:Ct,handleDragLeave:kt,handleDrop:It,dropAreaRef:Oe,textareaRef:M,messageWorkchatAlert:Ee,setMessageWorkchatAlert:Ne,messageWorkchatUserAlert:ke,setMessageWorkchatUserAlert:Ie}).fetchChatUserList=Dt,o.handleSendGroupMessage=At,o.searchContactVal=C,o.handleContactSearch=function(e){var t=e.target.value.trim();k(t);var r=t?Q.filter(function(e){return e.name.toLowerCase().includes(t.toLowerCase())}):Q;q(r)},o.searchVal=D,o.handleSearchUser=function(e){U(e.target.value);var t=e.target.value.trim(),r=t?ee.filter(function(e){return e.name.toLowerCase().includes(t.toLowerCase())}):ee;J(r)},o.replyMessageData=nt,o.setReplyMessageData=at,o.handleReplyMessage=function(e){at(e)},o.showModal=mt,o.modalRef=ut,o.setShowModal=ft,o.groupInputRef=ct,o.filteredMentionGroupMembers=wt,o.handleMentionUserSelect=function(e){var t=w[fe]||"",r=t.lastIndexOf("@");if(-1!==r){var n=t.substring(0,r),a=t.substring(r+1),l="@"+e.userId.name+" ",o=a.split(" ").slice(1).join(" "),s=""+n+l+(o?" "+o:"");E(function(e){var t;return R({},e,((t={})[fe]=s,t))}),bt(function(t){return t.some(function(t){return t.userId._id===e.userId._id})?t:[].concat(t,[e])}),ft(!1),requestAnimationFrame(function(){var e;null==(e=ct.current)||e.focus(),Mt(fe)})}},o.autoResizeTextarea=Mt,o.messagesContainerRef=lt,o.scrollToMessage=function(e){var t=document.getElementById("message-"+e);console.log("messageElement",t),t&<.current&&(t.scrollIntoView({behavior:"smooth",block:"center"}),it(e),setTimeout(function(){it("")},2e3))},o.setHighlightReply=it,o.highlightReply=st,o.handleDeleteMessage=function(e){try{var t={id:e._id};console.log("handleDelete",ie),he.emit("deleteMessage",t),se(function(t){return t.map(function(t){return t._id===e._id?R({},t,{isDeleted:!0}):t})});var r=H.map(function(t){return t.messageId===e._id?R({},t,{isDeleted:!0}):t});console.log("newData",r),Se.current=r,J(r)}catch(e){console.log("handleDelete",e)}},o.handleDeleteGroupMessage=function(e){try{var t={id:null==e?void 0:e._id,groupId:null==e?void 0:e.groupId};console.log("handleDelete",t,oe[0]),he.emit("deleteGroupMessage",t),se(function(t){return t.map(function(t){return t._id===e._id?R({},t,{isDeleted:!0}):t})})}catch(e){console.log("handleDelete",e)}},o/*#__PURE__*/);return e.createElement(F.Provider,{value:Rt},s)},G=/*#__PURE__*/l(),W=function(t){/*#__PURE__*/return e.createElement(G.Provider,{value:{handleCognitoVerification:function(e,t){try{var r={cognitoUserId:e,email:t},n=function(e,t){try{var n=Promise.resolve(j.post("https://chatapi.nte.ai/v3/user/verifyCognito",r)).then(function(e){"success"===e.data.status?(localStorage.setItem("authToken",e.data.token),localStorage.setItem("authUser",e.data._id)):console.error("Something went worng")})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){console.error("Cognito Verification Error:",e)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}}},t.children)},Y=function(n){var a,l,o=n.src,s=r(null),u=t(!1),d=u[0],m=u[1],f=t(0),g=f[0],p=f[1],h=t(0),v=h[0],y=h[1];/*#__PURE__*/return e.createElement("div",{className:"flex flex-col bg-gray-100 rounded-xl overflow-hidden w-full max-w-sm shadow"},/*#__PURE__*/e.createElement("video",{ref:s,src:o,onTimeUpdate:function(){var e=s.current;p(e.currentTime/e.duration*100)},onLoadedMetadata:function(){y(s.current.duration)},onEnded:function(){return m(!1)},className:"w-full max-h-60",controls:!1}),/*#__PURE__*/e.createElement("div",{className:"flex items-center gap-2 px-3 py-2"},/*#__PURE__*/e.createElement("button",{onClick:function(){var e=s.current;e.paused?(e.play(),m(!0)):(e.pause(),m(!1))}},/*#__PURE__*/e.createElement(d?i:c,{size:20,style:{color:"red"}})),/*#__PURE__*/e.createElement("input",{type:"range",value:g,onChange:function(e){var t=parseFloat(e.target.value);s.current.currentTime=t/100*s.current.duration,p(t)},className:"w-full accent-blue-500 h-1"}),/*#__PURE__*/e.createElement("span",{className:"text-xs text-gray-600 w-12 text-right"},(a=v,Math.floor(a/60)+":"+((l=Math.floor(a%60))<10?"0":"")+l))))},H=function(n){var a,l,o=n.src,s=r(null),u=t(!1),d=u[0],m=u[1],f=t(0),g=f[0],p=f[1],h=t(0),v=h[0],y=h[1];/*#__PURE__*/return e.createElement("div",{className:"flex items-center gap-2 bg-gray-100 rounded-full px-3 py-2 w-full max-w-xs"},/*#__PURE__*/e.createElement("button",{onClick:function(){var e=s.current;e.paused?(e.play(),m(!0)):(e.pause(),m(!1))}},/*#__PURE__*/e.createElement(d?i:c,{size:20,className:"text-primary"})),/*#__PURE__*/e.createElement("input",{type:"range",value:g,onChange:function(e){var t=s.current,r=parseFloat(e.target.value);t.currentTime=r/100*t.duration,p(r)},className:"w-full accent-blue-500 h-1"}),/*#__PURE__*/e.createElement("span",{className:"text-xs text-gray-600 w-10 text-right"},(a=v,Math.floor(a/60)+":"+((l=Math.floor(a%60))<10?"0":"")+l)),/*#__PURE__*/e.createElement("audio",{ref:s,src:o,onTimeUpdate:function(){var e=s.current;p(e.currentTime/e.duration*100)},onLoadedMetadata:function(){y(s.current.duration)},onEnded:function(){return m(!1)}}))},J=function(t){var r=t.text,n=t.color,a=null==r?void 0:r.replace(/(https?:\/\/)/g," $1").trim(),l=/https?:\/\/[^\s]+/g,o=null==a?void 0:a.split(/(https?:\/\/[^\s]+)/g);/*#__PURE__*/return e.createElement(s,null,o.map(function(t,r){return l.test(t)?/*#__PURE__*/e.createElement("a",{key:r,href:t,target:"_blank",rel:"noopener noreferrer",className:"underline italic",style:{color:n}},t):/*#__PURE__*/e.createElement("span",{key:r},t)}))},V=function(r){var n=r.code,a=t(!1),l=a[1];/*#__PURE__*/return e.createElement("div",{className:"relative p-4 bg-white rounded-md overflow-x-auto border border-gray-200 text-xs"},/*#__PURE__*/e.createElement("button",{onClick:function(){try{var e=function(e,t){try{var r=function(){function e(){l(!0),setTimeout(function(){return l(!1)},2e3)}var t=function(){if(navigator.clipboard)return Promise.resolve(navigator.clipboard.writeText(n)).then(function(){});var e=document.createElement("textarea");e.value=n,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}();return t&&t.then?t.then(e):e()}()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){console.error("Copy failed:",e)});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},className:"absolute top-2 right-2 px-2 py-1 text-sm bg-gray-200 hover:bg-gray-300 rounded text-gray-700"},a[0]?"Copied!":"Copy"),/*#__PURE__*/e.createElement(P,{language:null,style:_,showLineNumbers:!0},n))},K=function(t){var r,n,a=t.fileToUpload,l=t.handleCancelFileUpload,o=t.fetchUploadFileApi,i=t.color,c=void 0===i?"#000":i;return t.showPreviewDialog?/*#__PURE__*/e.createElement("div",{style:{position:"fixed",inset:0,zIndex:9999,backgroundColor:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center"}},/*#__PURE__*/e.createElement("div",{style:{backgroundColor:"#fff",borderRadius:"0.5rem",boxShadow:"0 10px 25px rgba(0,0,0,0.1)",maxWidth:"32rem",width:"100%"}},/*#__PURE__*/e.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"1rem",borderBottom:"1px solid #e5e7eb"}},/*#__PURE__*/e.createElement("h2",{style:{fontSize:"1.125rem",fontWeight:"600"}},"Preview"),/*#__PURE__*/e.createElement("button",{onClick:l,style:{color:"#6b7280",cursor:"pointer"}},/*#__PURE__*/e.createElement(u,{size:24}))),/*#__PURE__*/e.createElement("div",{style:{padding:"1rem"}},a&&/*#__PURE__*/e.createElement(s,null,(null==(r=a)||null==(n=r.type)?void 0:n.startsWith("image/"))?/*#__PURE__*/e.createElement("div",{style:{display:"flex",justifyContent:"center"}},/*#__PURE__*/e.createElement("img",{src:URL.createObjectURL(a),alt:"Preview",style:{maxHeight:"16rem",borderRadius:"0.5rem"}})):a.type.startsWith("video/")?/*#__PURE__*/e.createElement("video",{controls:!0,style:{width:"100%",maxHeight:"16rem",borderRadius:"0.5rem"},src:URL.createObjectURL(a)}):a.type.startsWith("audio/")?/*#__PURE__*/e.createElement("audio",{controls:!0,style:{width:"100%"},src:URL.createObjectURL(a)}):"application/pdf"===a.type?/*#__PURE__*/e.createElement("iframe",{src:URL.createObjectURL(a),style:{width:"100%",height:"16rem",border:"1px solid #e5e7eb",borderRadius:"0.5rem"},title:"PDF Preview"}):/*#__PURE__*/e.createElement("div",{style:{display:"flex",alignItems:"center",backgroundColor:"#f3f4f6",padding:"1rem",borderRadius:"0.5rem"}},/*#__PURE__*/e.createElement(d,{size:32,style:{color:"#374151",marginRight:"0.75rem"}}),/*#__PURE__*/e.createElement("div",null,/*#__PURE__*/e.createElement("p",{style:{fontWeight:"500"}},null==a?void 0:a.name),/*#__PURE__*/e.createElement("p",{style:{fontSize:"0.875rem",color:"#6b7280"}},function(e){if(!e)return"0 B";var t=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,t)).toFixed(2)+" "+["B","KB","MB","GB","TB"][t]}(null==a?void 0:a.size)),/*#__PURE__*/e.createElement("a",{href:URL.createObjectURL(a),download:a.name,style:{color:"#2563eb",fontSize:"0.875rem",marginTop:"0.25rem",display:"inline-block"}},"Download file"))))),/*#__PURE__*/e.createElement("div",{style:{display:"flex",justifyContent:"flex-end",padding:"1rem",borderTop:"1px solid #e5e7eb"}},/*#__PURE__*/e.createElement("button",{onClick:l,style:{padding:"0.5rem 1rem",color:"#374151",marginRight:"0.5rem",borderRadius:"0.375rem",backgroundColor:"transparent",cursor:"pointer"},onMouseOver:function(e){return e.currentTarget.style.backgroundColor="#f3f4f6"},onMouseOut:function(e){return e.currentTarget.style.backgroundColor="transparent"}},"Cancel"),/*#__PURE__*/e.createElement("button",{onClick:o,style:{padding:"0.5rem 1rem",color:"#fff",borderRadius:"0.375rem",display:"flex",alignItems:"center",backgroundColor:c,cursor:"pointer"}},/*#__PURE__*/e.createElement(m,{size:18,style:{marginRight:"0.25rem"}}),"Send")))):null},q=function(t){var r=JSON.parse(t.data);console.log("mapDetails",r);var n="https://maps.google.com/maps?q="+(null==r?void 0:r.latitude)+","+(null==r?void 0:r.longitude)+"&z=15&output=embed&markers=color:red%7C"+(null==r?void 0:r.latitude)+","+(null==r?void 0:r.longitude);return console.log("mapUrl",n),/*#__PURE__*/e.createElement("div",{className:"bg-white p-4 rounded-xl shadow border "},/*#__PURE__*/e.createElement("div",{className:"w-full h-40 rounded-lg overflow-hidden"},/*#__PURE__*/e.createElement("iframe",{width:"100%",height:"100%",loading:"lazy",allowFullScreen:!0,src:n,style:{border:0},referrerPolicy:"no-referrer-when-downgrade"})))},$=function(r){var n=r.color,l=r.noOfChat,i=r.senderContainerColor,c=r.senderTextColor,T=r.receiverContainerColor,S=r.receiverTextColor,A=r.sendButtonColor,P=r.chatWidth,_=r.chatHeight,R=r.cognitoUserId,j=r.email,z=r.senderDateTextColor,L=r.receiverDateTextColor,O=r.senderLinkTextColor,B=r.receiverLinkTextColor,W=r.groupUserNameColors,$=r.ctaButtonColor,Q=r.ctaButtonText,X=r.headerTextColor,Z=o(F),ee=Z.activeChats,te=Z.minimizedChats,re=Z.newMessage,ne=Z.toggleMinimize,ae=Z.closeChat,le=Z.handleMessageChange,oe=Z.sendMessage,se=Z.handleKeyDown,ie=Z.handleUserClick,ce=Z.minimizedContact,ue=Z.setMinimizedContact,de=Z.activeTab,me=Z.handleSwitchTab,fe=Z.fetchChatUserList,ge=Z.userList,pe=Z.contactList,he=Z.setMaxChat,ve=Z.chats,ye=Z.messageAlert,xe=Z.setMessageAlert,be=Z.handleAttachmentClick,we=Z.fileInputRef,Ee=Z.handleFileSelect,Ne=Z.showPreviewDialog,Ce=Z.handleCancelFileUpload,ke=Z.fileToUpload,Ie=Z.fetchUploadFileApi,De=Z.isDragging,Ue=Z.handleDragOver,Me=Z.handleDragEnter,Te=Z.handleDragLeave,Se=Z.handleDrop,Ae=Z.dropAreaRef,Pe=Z.textareaRef,_e=Z.messageWorkchatAlert,Re=Z.setMessageWorkchatAlert,je=Z.messageWorkchatUserAlert,ze=Z.setMessageWorkchatUserAlert,Le=Z.handleSendGroupMessage,Fe=Z.searchContactVal,Oe=Z.handleContactSearch,Be=Z.searchVal,Ge=Z.handleSearchUser,We=Z.replyMessageData,Ye=Z.setReplyMessageData,He=Z.handleReplyMessage,Je=Z.showModal,Ve=Z.modalRef,Ke=Z.setShowModal,qe=Z.groupInputRef,$e=Z.filteredMentionGroupMembers,Qe=Z.handleMentionUserSelect,Xe=Z.autoResizeTextarea,Ze=Z.messagesContainerRef,et=Z.scrollToMessage,tt=Z.highlightReply,rt=Z.handleDeleteMessage,nt=Z.handleDeleteGroupMessage,at=o(G).handleCognitoVerification,lt=localStorage.getItem("authUser"),ot=function(e){return e.split("/")[0]},st=function(e){return"."+e.split(".").at(-1)};a(function(){fe()},[]),a(function(){l&&he(l)},[]),a(function(){at(R,j)},[R,j]);var it=function(e){var t=window.open(e,"_blank","noopener,noreferrer");t&&(t.opener=null)},ct=t(!1),ut=ct[0],dt=ct[1],mt=function(e){return[/<[\w\d]+\s?.*?>/,/\bfunction\b|\bconst\b/,/\bdef\b|\bimport\b/,/=\s*{.*?}/,/<\/[\w\d]+>/].some(function(t){return t.test(e)})},ft=function(e){var t=(null==e?void 0:e.charCodeAt(0))%W.length;return W[t]};return a(function(){We&&Je&&dt(!0)},[We,Je]),/*#__PURE__*/e.createElement("div",{className:"fixed bottom-0 right-0 flex gap-4 z-50 "},ee.map(function(t){var r,a=JSON.parse(localStorage.getItem("userListStore")||"[]"),l=ge.find(function(e){return e._id===t})||pe.find(function(e){return e._id===t})||a.find(function(e){return e._id===t})||ge.find(function(e){return e.userId._id===t}),o=ve[t]||[],C=te.includes(t);return ze(C),console.log("useruseruser",l,ge,pe),/*#__PURE__*/e.createElement("div",{key:t,className:"w-64 bg-white rounded-t-lg shadow-lg flex flex-col self-end ",style:{height:C?"40px":ut?"550px":_,width:ut?"500px":P},ref:Ae,onDragOver:Ue,onDragEnter:Me,onDragLeave:Te,onDrop:Se},/*#__PURE__*/e.createElement("div",{className:"px-3 py-2 border-b flex items-center justify-between rounded-t-lg",style:{backgroundColor:n||"#000"}},/*#__PURE__*/e.createElement("div",{className:"flex items-center cursor-pointer flex-1",onClick:function(e){e.stopPropagation(),ne(t),xe(!1)}},/*#__PURE__*/e.createElement("div",{className:"relative"},null!=l&&l.profileImage?/*#__PURE__*/e.createElement("img",{src:null==l?void 0:l.profileImage,alt:l.name.charAt(0),className:"w-8 h-8 rounded-full text-center justify-center items-center border flex text-white"}):/*#__PURE__*/e.createElement("span",{className:"w-8 h-8 rounded-full text-center justify-center items-center border flex text-white"},"group"===(null==l?void 0:l.type)?/*#__PURE__*/e.createElement(f,null):null==l||null==(r=l.name)?void 0:r.charAt(0)),"available"===(null==l?void 0:l.status)&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 bg-green-500 rounded-full border-2 border-blue-600"})),/*#__PURE__*/e.createElement("div",{className:"ml-2"},/*#__PURE__*/e.createElement("div",{className:"font-medium text-sm",style:{color:X||"#fff"}},(null==l?void 0:l.name)||""),"bot"===l.type&&/*#__PURE__*/e.createElement("div",{className:"font-medium text-white text-[10px]"},"BOT")),C&&ye&&/*#__PURE__*/e.createElement("div",{className:"bg-red-600 w-4 h-4 text-xs text-center rounded ml-1"},"1")),/*#__PURE__*/e.createElement("div",{className:"flex space-x-2"},!C&&/*#__PURE__*/e.createElement("div",null,/*#__PURE__*/e.createElement(ut?p:g,{size:16,className:"text-white cursor-pointer",onClick:function(e){e.stopPropagation(),dt(!ut)}})),C?/*#__PURE__*/e.createElement(h,{size:16,className:"text-white cursor-pointer",onClick:function(e){e.stopPropagation(),ne(t),xe(!1)}}):/*#__PURE__*/e.createElement(v,{size:16,className:"text-white cursor-pointer",onClick:function(e){e.stopPropagation(),ne(t)}}),/*#__PURE__*/e.createElement(u,{size:16,className:"text-white cursor-pointer",onClick:function(e){e.stopPropagation(),ae(t),ze(!1)}}))),De?/*#__PURE__*/e.createElement("div",{className:"flex items-center justify-center pointer-events-none h-full"},/*#__PURE__*/e.createElement("div",{className:"bg-blue-100 border border-blue-300 p-8 rounded-lg shadow-md text-center "},/*#__PURE__*/e.createElement(y,{size:48,className:"mx-auto text-primary mb-2"}),/*#__PURE__*/e.createElement("p",{className:"text-lg font-medium"},"Drop file here"),/*#__PURE__*/e.createElement("p",{className:"text-sm text-gray-500"},"to upload and send"))):!C&&/*#__PURE__*/e.createElement(s,null,"user"===l.type&&/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[].concat(o).map(function(t,r){/*#__PURE__*/return e.createElement("div",{ref:Ze,key:r},/*#__PURE__*/e.createElement("div",{className:"text-xs bg-primary/20 text-primary px-2 py-1 mx-auto my-4 backdrop-blur-sm border-b w-fit rounded border-gray-400"},null==t?void 0:t.date),[].concat(t.chats).reverse().map(function(t,r){var a,l;/*#__PURE__*/return e.createElement("div",{id:"message-"+t._id,key:r,className:"mb-2 flex flex-col "+("me"===t.sender?"items-end":"items-start")+" "+(tt==t._id?"transition-colors duration-1000 bg-yellow-100 rounded-xl":"")},/*#__PURE__*/e.createElement("div",{className:"relative group max-w-[75%]"},t.isDeleted?/*#__PURE__*/e.createElement("div",{className:"p-2 text-xs italic rounded-xl shadow-md whitespace-pre-wrap break-words \n "+("me"===t.sender?"rounded-br-none ":"rounded-bl-none "),style:{backgroundColor:"me"===t.sender?i:T,color:"me"===t.sender?c:S}},"me"===t.sender?"You deleted this message":"This message was deleted"):/*#__PURE__*/e.createElement("div",{className:"p-2 rounded-xl shadow-md whitespace-pre-wrap break-words \n "+("me"===t.sender?"rounded-br-none ":"rounded-bl-none "),style:{backgroundColor:"me"===t.sender?i:T,color:"me"===t.sender?c:S}},(null==t?void 0:t.replyMessageId)&&/*#__PURE__*/e.createElement("div",{className:" p-2 rounded border-l-4 cursor-pointer shadow\n "+(t.isSent?"bg-gray-600 border-teal-600":"bg-gray-100 border-teal-600")+"\n \n ",onClick:function(e){e.stopPropagation(),et(t.replyMessageId._id)},style:{}},/*#__PURE__*/e.createElement("div",{className:"text-xs font-medium mb-1 text-black text-primary"},(null==t||null==(a=t.replyMessageId)||null==(a=a.fromUserId)?void 0:a._id)===lt?"You":null==t||null==(l=t.replyMessageId)||null==(l=l.fromUserId)?void 0:l.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-700 truncate"},null==t?void 0:t.replyMessageId.messageContent)),"image"===ot(t.fileType)&&/*#__PURE__*/e.createElement("img",{src:t.link,alt:"Preview",className:"max-h-32 rounded cursor-pointer mx-auto",onClick:function(){return it(t.link)}}),"video"===ot(t.fileType)&&/*#__PURE__*/e.createElement(Y,{src:t.link,color:n}),"audio"===ot(t.fileType)&&/*#__PURE__*/e.createElement(H,{src:t.link,color:n}),"application"===ot(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex items-center bg-gray-200 p-2 rounded cursor-pointer",onClick:function(){return it(t.link)}},/*#__PURE__*/e.createElement(d,{size:20,className:"text-black mr-2"}),/*#__PURE__*/e.createElement("p",{className:"text-sm font-medium text-black"},"Document",st(t.link))),!mt(t.text)&&"image"!==ot(t.fileType)&&""!==t.text&&"L"!==t.type&&/*#__PURE__*/e.createElement("div",{className:"text-sm mt-1"},/*#__PURE__*/e.createElement(J,{text:(null==t?void 0:t.text)||"",color:"me"===t.sender?O:B})),mt(t.text)&&/*#__PURE__*/e.createElement(V,{code:t.text})),!t.isDeleted&&/*#__PURE__*/e.createElement("div",{className:"absolute top-1/2 -translate-y-1/2 z-10 flex items-center gap-2 px-2\n "+("me"===t.sender?"right-full ml-2":"left-full mr-2")+"\n opacity-0 group-hover:opacity-100 transition-opacity"},/*#__PURE__*/e.createElement(x,{onClick:function(){He(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18}),"me"===t.sender&&/*#__PURE__*/e.createElement(b,{onClick:function(){rt(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18}))),/*#__PURE__*/e.createElement("div",{className:"text-xs mt-1 flex gap-1 items-center "+("me"===t.sender?"justify-end text-gray-600":"justify-start text-gray-800"),style:{color:"me"===t.sender?z:L}},"me"===t.sender&&t.isStared&&/*#__PURE__*/e.createElement("span",null,/*#__PURE__*/e.createElement(w,{fill:"#eab308",className:"text-yellow-500",size:10})),/*#__PURE__*/e.createElement("span",null,t.time),"me"===t.sender&&/*#__PURE__*/e.createElement(E,{size:16,className:t.isRead?"text-blue-500":"text-gray-400"}),"me"!==t.sender&&t.isStared&&/*#__PURE__*/e.createElement("span",null,/*#__PURE__*/e.createElement(w,{fill:"#eab308",className:"text-yellow-500",size:10}))))}))})),We&&/*#__PURE__*/e.createElement("div",{className:"px-4 py-2 bg-gray-100 border-b border-gray-200 flex items-start sm:items-center "},/*#__PURE__*/e.createElement("div",{className:"w-1 h-12 rounded-full mr-3 flex-shrink-0",style:{backgroundColor:A||"#000"}}),/*#__PURE__*/e.createElement("div",{className:"flex-1 min-w-0"}," ",/*#__PURE__*/e.createElement("div",{className:"flex items-center justify-between gap-2"},/*#__PURE__*/e.createElement("span",{className:"text-xs font-medium text-gray-600 whitespace-nowrap"},"Replying to","reciver"===We.sender?null==We?void 0:We.user.name:"You"),/*#__PURE__*/e.createElement("button",{onClick:function(){return Ye("")},className:"text-gray-400 hover:text-gray-600 transition-colors flex-shrink-0"},/*#__PURE__*/e.createElement(u,{className:"w-4 h-4"}))),/*#__PURE__*/e.createElement("p",{className:"text-sm text-gray-800 mt-1 w-full line-clamp-2"},null==We?void 0:We.text))),/*#__PURE__*/e.createElement("div",{className:"p-2 border-t"},/*#__PURE__*/e.createElement("div",{className:"flex items-center"},/*#__PURE__*/e.createElement("button",{className:"mr-2 p-1 rounded-full bg-blue-500 text-white ",style:{backgroundColor:A||"#000"},onClick:function(){return be(t)}},/*#__PURE__*/e.createElement(N,{size:16})),/*#__PURE__*/e.createElement("input",{type:"file",ref:we,onChange:Ee,className:"hidden"}),/*#__PURE__*/e.createElement("textarea",{ref:function(e){return Pe.current[t]=e},className:"flex-1 border rounded-lg py-1 max-h-60 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500 resize-none px-2 overflow-auto no-scrollbar",placeholder:"Type a message...",autoFocus:!0,value:re[t]||"",onChange:function(e){le(t,e.target.value),Xe(t)},onKeyDown:function(e){return se(t,e)},rows:1}),/*#__PURE__*/e.createElement("button",{className:"ml-2 p-1 rounded-full bg-blue-500 text-white ",style:{backgroundColor:A||"#000"},onClick:function(){return oe(t)}},/*#__PURE__*/e.createElement(m,{size:16}))))),"group"===l.type&&/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[].concat(o).map(function(t,r){/*#__PURE__*/return e.createElement("div",{ref:Ze,key:r},/*#__PURE__*/e.createElement("div",{className:"text-xs bg-primary/20 text-primary px-2 py-1 mx-auto my-4 backdrop-blur-sm border-b w-full flex items-center justify-center border-gray-500"},null==t?void 0:t.date),[].concat(t.chats).reverse().map(function(t,r){var a,o,s="me"===t.sender,u="reciver"===t.sender;return console.log("message",t),"E"!==t.type?/*#__PURE__*/e.createElement("div",{id:"message-"+t._id,key:r,className:"mb-2 flex "+(s?"justify-end":"justify-start")+" "+(tt==t._id?"transition-colors duration-1000 bg-yellow-100 rounded-xl":"")},!s&&(l.profileImage?/*#__PURE__*/e.createElement("img",{src:l.profileImage,alt:l.name.charAt(0),className:"w-6 h-6 rounded-full mr-1 self-end mb-5 border"}):/*#__PURE__*/e.createElement("span",{className:"w-6 h-6 rounded-full mr-1 flex items-center mb-5 justify-center self-end border text-xs text-black bg-gray-200"},l.name.charAt(0))),/*#__PURE__*/e.createElement("div",{className:"flex flex-col max-w-[80%] relative group"},u&&/*#__PURE__*/e.createElement("span",{className:"text-xs font-semibold mb-1",style:{color:ft(null==t?void 0:t.name)}},null==t?void 0:t.name),t.isDeleted?/*#__PURE__*/e.createElement("div",{className:"p-2 text-xs italic rounded-xl shadow-md whitespace-pre-wrap break-words \n "+("me"===t.sender?"rounded-br-none ":"rounded-bl-none "),style:{backgroundColor:"me"===t.sender?i:T,color:"me"===t.sender?c:S}},"me"===t.sender?"You deleted this message":"This message was deleted"):/*#__PURE__*/e.createElement("div",{className:" p-2 rounded-lg shadow-md break-words whitespace-pre-wrap "+(s?"bg-blue-500 text-white rounded-br-none":"bg-gray-200 text-gray-800 rounded-bl-none"),style:{backgroundColor:s?i:T,color:s?c:S}},(null==t?void 0:t.replyMessageId)&&/*#__PURE__*/e.createElement("div",{className:" p-2 rounded border-l-4 cursor-pointer "+(t.isSent?"bg-gray-600 border-teal-600":"bg-gray-100 border-teal-600")+" ",onClick:function(e){e.stopPropagation(),et(t.replyMessageId._id)}},/*#__PURE__*/e.createElement("div",{className:"text-xs font-medium mb-1 text-black"},(null==t||null==(a=t.replyMessageId)||null==(a=a.userId)?void 0:a._id)===lt?"You":null==t||null==(o=t.replyMessageId)||null==(o=o.userId)?void 0:o.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-700 truncate"},null==t?void 0:t.replyMessageId.messageContent)),"image"===ot(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex justify-center items-center mb-1"},/*#__PURE__*/e.createElement("img",{onClick:function(){return it(t.link)},src:t.link,alt:"Preview",className:"max-h-28 rounded cursor-pointer"})),"video"===ot(t.fileType)&&/*#__PURE__*/e.createElement(Y,{src:t.link,color:n}),"audio"===ot(t.fileType)&&/*#__PURE__*/e.createElement(H,{src:t.link,color:n}),"application"===ot(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex items-center bg-gray-100 p-2 rounded cursor-pointer mb-1",onClick:function(){return it(t.link)}},/*#__PURE__*/e.createElement(d,{size:20,className:"text-black mr-2"}),/*#__PURE__*/e.createElement("p",{className:"text-sm text-black"},"Document",st(t.link))),"L"===t.type&&/*#__PURE__*/e.createElement(q,{data:t.text}),/*#__PURE__*/e.createElement("div",{className:"text-sm"},!mt(t.text)&&"image"!=ot(t.fileType)&&""!==t.text&&"L"!==t.type&&/*#__PURE__*/e.createElement(J,{text:t.text,color:s?O:B}),mt(t.text)&&/*#__PURE__*/e.createElement(V,{code:null==t?void 0:t.text}))),!t.isDeleted&&/*#__PURE__*/e.createElement("div",{className:"absolute top-1/2 -translate-y-1/2 z-10 flex items-center gap-2 px-2\n "+("me"===t.sender?"right-full ml-2":"left-full mr-2")+"\n opacity-0 group-hover:opacity-100 transition-opacity"},/*#__PURE__*/e.createElement(x,{onClick:function(){He(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18}),"me"===t.sender&&/*#__PURE__*/e.createElement(b,{onClick:function(){nt(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18})),/*#__PURE__*/e.createElement("div",{className:"text-xs mt-1 flex gap-1 items-center "+("me"===t.sender?"justify-end text-gray-600":"justify-start text-gray-800"),style:{color:"me"===t.sender?z:L}},"me"===t.sender&&t.isStared&&/*#__PURE__*/e.createElement("span",null,/*#__PURE__*/e.createElement(w,{fill:"#eab308",className:"text-yellow-500",size:10})),/*#__PURE__*/e.createElement("span",null,t.time),"me"!==t.sender&&t.isStared&&/*#__PURE__*/e.createElement("span",null,/*#__PURE__*/e.createElement(w,{fill:"#eab308",className:"text-yellow-500",size:10}))))):/*#__PURE__*/e.createElement("div",{className:"text-xs bg-primary/20 text-primary px-2 py-1 rounded-md mx-auto my-1.5 w-fit backdrop-blur-sm",style:{backgroundColor:n,color:X}},t.text)}))})),Je&&/*#__PURE__*/e.createElement("div",{ref:Ve,className:" bg-white rounded-lg shadow-2xl border border-gray-200 z-50 overflow-hidden animate-slide-up w-[96%] self-center max-h-80"},/*#__PURE__*/e.createElement("div",{className:"p-3 border-b border-gray-100 bg-gray-50 flex justify-between items-center"},/*#__PURE__*/e.createElement("h3",{className:"text-sm font-medium text-gray-700"},"Select member to mention"),/*#__PURE__*/e.createElement("div",{onClick:function(){return Ke(!1)}},/*#__PURE__*/e.createElement(u,{size:16}))),/*#__PURE__*/e.createElement("div",{className:" max-h-60 overflow-y-auto "},$e.length>0?$e.map(function(t){var r,n,a;return t.userId._id!=lt&&/*#__PURE__*/e.createElement("div",{key:t.id,onClick:function(){return Qe(t)},className:"flex items-center gap-3 p-3 hover:bg-gray-200 cursor-pointer transition-colors"},/*#__PURE__*/e.createElement("div",{className:"w-10 h-10 flex items-center justify-center rounded-full bg-gray-300 overflow-hidden border"},null!=t&&null!=(r=t.userId)&&r.profileImage?/*#__PURE__*/e.createElement("img",{src:t.userId.profileImage,alt:null==(n=t.userId.name)?void 0:n.charAt(0),className:"w-full h-full object-cover"}):/*#__PURE__*/e.createElement("span",{className:"text-sm font-medium text-black"},null==(a=t.userId.name)?void 0:a.charAt(0))),/*#__PURE__*/e.createElement("div",{className:"flex-1"},/*#__PURE__*/e.createElement("p",{className:"font-medium text-gray-900 text-sm"},t.userId.name)))}):/*#__PURE__*/e.createElement("div",{className:"p-4 text-center text-gray-500"},/*#__PURE__*/e.createElement("p",{className:"text-sm"},"No contacts found")))),We&&/*#__PURE__*/e.createElement("div",{className:"px-4 py-2 bg-gray-100 border-b border-gray-200 flex items-start sm:items-center "},/*#__PURE__*/e.createElement("div",{className:"w-1 h-12 rounded-full mr-3 flex-shrink-0",style:{backgroundColor:A||"#000"}}),/*#__PURE__*/e.createElement("div",{className:"flex-1 min-w-0"}," ",/*#__PURE__*/e.createElement("div",{className:"flex items-center justify-between gap-2"},/*#__PURE__*/e.createElement("span",{className:"text-xs font-medium text-gray-600 whitespace-nowrap"},"Replying to ","reciver"===We.sender?We.user.name:"You"),/*#__PURE__*/e.createElement("button",{onClick:function(){return Ye("")},className:"text-gray-400 hover:text-gray-600 transition-colors flex-shrink-0"},/*#__PURE__*/e.createElement(u,{className:"w-4 h-4"}))),/*#__PURE__*/e.createElement("p",{className:"text-sm text-gray-800 mt-1 w-full line-clamp-2"},null==We?void 0:We.text))),/*#__PURE__*/e.createElement("div",{className:"p-2 border-t"},/*#__PURE__*/e.createElement("div",{className:"flex items-center"},/*#__PURE__*/e.createElement("button",{className:"mr-2 p-1 rounded-full bg-blue-500 text-white ",style:{backgroundColor:A||"#000"},onClick:function(){return be(t)}},/*#__PURE__*/e.createElement(N,{size:16})),/*#__PURE__*/e.createElement("input",{type:"file",ref:we,onChange:Ee,className:"hidden"}),/*#__PURE__*/e.createElement("textarea",{ref:function(e){qe.current=e,Pe.current[t]=e},className:"flex-1 border rounded-lg py-1 max-h-60 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500 resize-none px-2 overflow-auto no-scrollbar",placeholder:"Type a message...",autoFocus:!0,value:re[t]||"",onChange:function(e){le(t,e.target.value),Xe(t)},onKeyDown:function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),Le(t))},rows:1}),/*#__PURE__*/e.createElement("button",{className:"ml-2 p-1 rounded-full bg-blue-500 text-white ",style:{backgroundColor:A||"#000"},onClick:function(){return Le(t)}},/*#__PURE__*/e.createElement(m,{size:16}))))),"bot"===l.type&&/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[].concat(o).map(function(t,r){/*#__PURE__*/return e.createElement("div",{key:r},/*#__PURE__*/e.createElement("div",{className:"text-xs bg-primary/20 text-primary px-2 py-1 mx-auto my-4 backdrop-blur-sm border-b w-full flex items-center justify-center border-gray-500"},null==t?void 0:t.date),[].concat(t.chats).reverse().map(function(t,r){var a="me"===t.sender;/*#__PURE__*/return e.createElement("div",{key:r,className:"mb-2 flex "+(a?"justify-end":"justify-start")},/*#__PURE__*/e.createElement("div",{className:"flex flex-col max-w-[80%]"},"reciver"===t.sender&&/*#__PURE__*/e.createElement("span",{className:"text-xs font-semibold mb-1",style:{color:ft(null==t?void 0:t.name)}},null==t?void 0:t.name),/*#__PURE__*/e.createElement("div",{className:"p-2 rounded-lg shadow-md break-words whitespace-pre-wrap "+(a?"bg-blue-500 text-white rounded-br-none":"bg-gray-200 text-gray-800 rounded-bl-none"),style:{backgroundColor:a?i:T,color:a?c:S}},"image"===ot(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex justify-center items-center mb-1"},/*