UNPKG

amworkchat

Version:

Customizable React chat component for workplace communication

3 lines 53.1 kB
import e,{useState as t,useRef as a,useCallback as r,useEffect as l,createContext as s,useContext as n,Fragment as o}from"react";import{Pause as c,Play as i,X as d,File as m,Send as u,Users as g,Expand as p,Shrink as f,Maximize as h,Minimize as y,Upload as x,Reply as b,Trash2 as v,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 _}from"react-syntax-highlighter";import{docco as R}from"react-syntax-highlighter/dist/esm/styles/hljs";function z(){return z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)({}).hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e},z.apply(null,arguments)}const j=T,L=T.create({baseURL:"https://chatapi.nte.ai/v3",headers:{"Content-Type":"application/json"}});L.interceptors.request.use(e=>{const t=localStorage.getItem("authToken");return console.log("tokentoken",t),t&&(e.headers.Authorization=t),e},e=>Promise.reject(e));const $=/*#__PURE__*/s(),F=({children:s})=>{const[n,o]=t([]),[c,i]=t({});t({});const[d,m]=t([]),[u,g]=t(!0),[p,f]=t({}),[h,y]=t(""),[x,b]=t(""),v=a({}),w=a({}),[E,N]=t("chat"),[C,k]=t(3),[I,D]=t([]),[U,M]=t([]),[T,_]=t([]),[R,j]=t([]),[F,O]=t([]),[P,B]=t([]);t("");const[G,W]=t(""),[Y,H]=t({}),[J,V]=t(""),[K,q]=t(null),[Q,X]=t(!1),[Z,ee]=t(!1),[te,ae]=t(!1),[re,le]=t(!1),se=a(n),ne=a(I),oe=a(Q),[ce,ie]=t(null),[de,me]=t(!1),ue=a(null),ge=a(null),[pe,fe]=t(""),[he,ye]=t(!1),[xe,be]=t(""),[ve,we]=t(""),[Ee,Ne]=t(""),[Ce,ke]=t(""),Ie=a(null),[De,Ue]=t(""),Me=a(null),Te=a(null),[Se,Ae]=t(!1),[_e,Re]=t({top:0,left:0,width:0}),[ze,je]=t(""),[Le,$e]=t([]),Fe=F.filter(e=>e.userId.name.toLowerCase().includes(ze.toLowerCase())),Oe=()=>{ie(null),me(!1),ue.current.value="",f(e=>z({},e,{[J]:""}))},Pe=r(e=>{e.preventDefault(),e.stopPropagation(),ye(!0)},[]),Be=r(e=>{e.preventDefault(),e.stopPropagation(),ye(!0)},[]),Ge=r(e=>{e.preventDefault(),e.stopPropagation(),ye(!1)},[]),We=r(e=>{e.preventDefault(),e.stopPropagation(),ye(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0&&(ie(e.dataTransfer.files[0]),me(!0))},[]);l(()=>{se.current=n},[n]),l(()=>{ne.current=I,I.length>0&&localStorage.setItem("userListStore",JSON.stringify(I))},[I]),l(()=>{oe.current=Q},[Q]);const Ye=async()=>{try{const e=await L.get("chatUser/userList");"success"===e.data.status&&(D(e.data.response),j(e.data.response))}catch(e){console.error("fetchChatUserList error:",e)}};function He(e,t,a){if(!Array.isArray(e))return console.error("Expected an array, but got:",e),[];const r=e.findIndex(e=>e._id==t);if(-1===r)return e;const l=e.splice(r,1)[0];return e.splice(a,0,l),e}l(()=>{const e=localStorage.getItem("authUser");if(""===J)return;n.includes(J);const t=n.find(e=>e===J)||J,a=P.map(t=>{var a,r,l;const s=((null==(a=t.fromUserId)?void 0:a._id)||(null==t||null==(r=t.userId)?void 0:r._id))===e,n=(null==(l=t.toUserId)?void 0:l._id)!==e?t.toUserId:t.fromUserId;return"user"===Ee.type?{_id:t._id,sender:s?"me":"reciver",text:t.messageContent,isRead:t.isRead,user:n,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"===ve.type?{_id:t._id,sender:s?"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:s?"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==(o=t.userId)?void 0:o.name,isForwarded:t.isForwarded,isDeleted:t.isDeleted,isStared:t.isStared,replyMessageId:t.replyMessageId||""};var o});console.log("modifychat",a);const r={};a.forEach(e=>{const t=S(e.createdAt).format("YYYY-MM-DD");r[t]||(r[t]=[]),r[t].push(e)});const l=Object.keys(r).sort((e,t)=>S(t).diff(S(e))).map(e=>{const t=S(e);return{date:t.isSame(S(),"day")?"Today":t.isSame(S().subtract(1,"day"),"day")?"Yesterday":t.format("DD MMM YYYY"),chats:r[e],chatUserId:c[J]}});if(n.length>=C){if(!n.includes(t)){const e=[...n];e.shift(),e.push(t),o(e)}H(e=>z({},e,{[t]:l}))}else o(e=>e.includes(t)?e:[...e,t]),H(e=>z({},e,{[t]:l}));setTimeout(()=>{const e=document.getElementById(`chat-input-${t}`);e&&e.focus()},100)},[P,ve,Ee]),l(()=>{const e=localStorage.getItem("authToken");if(localStorage.getItem("authUser"),!e)return;const t="https://chatapi.nte.ai/chat";console.log("apiUrl",t);const a=A(t,{transports:["websocket"],auth:{token:e}});return a.on("connect",()=>{console.log("Connected to socket server with ID:",a.id)}),a.on("disconnect",e=>{console.log("Socket disconnected:",e)}),a.on("receiveMessage",e=>{if(localStorage.getItem("authUser"),console.log("Received message:",e),se.current.includes(e.fromUserId._id)||ee(!0),Array.isArray(ne.current)){const t=He([...ne.current],e.fromUserId._id,0).map(t=>t._id==e.fromUserId._id?z({},t,{isDeleted:!1,messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,msg:"New",unReadCount:se.current.includes(e.fromUserId._id)?0:t.unReadCount<0?1:t.unReadCount+1}):t);ne.current=t,D(t)}else console.error("userChatRef.current is not an array:",ne.current);X(!1),se.current.includes(e.fromUserId._id)&&(oe.current=!0,X(!0),B(t=>[e,...t]),a.emit("readMessage",{user_id:e.fromUserId._id}))}),a.on("redMessage",e=>{B(t=>t.map(t=>se.current.includes(e)?z({},t,{isRead:!0}):t))}),a.on("ownMessage",e=>{if(console.log("ownMessage",e),Array.isArray(ne.current)){const t=He([...ne.current],e.toUserId._id,0).map(t=>t._id==e.toUserId._id?z({},t,{messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,msg:"Read",isDeleted:!1}):t);ne.current=t,D(t)}else console.error("userChatRef.current is not an array:",ne.current);se.current.includes(e.toUserId._id)&&B(t=>[e,...t])}),a.on("deletedMessage",e=>{console.log("deletedMessage response:",e,e.fromUserId,se.current._id),D(t=>t.map(t=>t.chatUserId===e.chatUserId&&e._id===t.messageId?z({},t,{isDeleted:!0}):t)),se.current.includes(e.fromUserId)&&B(t=>t.map(t=>t._id===e._id?z({},t,{isDeleted:!0}):t))}),a.on("receiveGroupMessage",e=>{if(Array.isArray(ne.current)){const t=He([...ne.current],e.groupId,0).map(t=>t.chatUserId==e.groupId?z({},t,{messageContent:e.messageContent,messageId:e.messageId,createdAt:e.createdAt,isDeleted:!1}):t);ne.current=t,D(t)}else console.error("newDatanewDatanewData.current is not an array:",ne.current);se.current.includes(e.groupId)&&B(t=>[e,...t])}),a.on("deleteGroupMessage",e=>{if(console.log("deleteGroupMessage",e),B(t=>t.map(t=>t._id===e.messageId?z({},t,{isDeleted:!0}):t)),Array.isArray(ne.current)){const t=He([...ne.current],e.groupId,0).map(t=>t.chatUserId==e.groupId&&t.messageId===e.messageId?z({},t,{createdAt:new Date,isDeleted:!0}):t);ne.current=t,D(t)}else console.error("newDatanewDatanewData.current is not an array:",ne.current)}),a.on("deleteGroupMessage",e=>{if(console.log("deleteGroupMessage",e),B(t=>t.map(t=>t._id===e.messageId?z({},t,{isDeleted:!0}):t)),Array.isArray(ne.current)){const t=He([...ne.current],e.groupId,0);console.log("newDatanewDatanewDataarr",t);const a=t.map(t=>t.chatUserId==e.groupId?z({},t,{createdAt:new Date,isDeleted:!0}):t);console.log("newDatanewDatanewsadasData",a),ne.current=a,D(a)}else console.error("newDatanewDatanewData.current is not an array:",ne.current)}),a.on("botMessage",e=>{if(console.log("botMessage response:",e),Array.isArray(ne.current)){const t=He([...ne.current],e.toUser,0);console.log("newDatanewDatanewDataarr",t);const a=t.map(t=>t._id==e.toUser?z({},t,{messageContent:e.messageContent,createdAt:e.createdAt}):t);console.log("newDatanewDatanewData",a),ne.current=a,D(a)}else console.error("newDatanewDatanewData.current is not an array:",ne.current);se.current.includes(e.toUser)&&B(t=>[e,...t])}),a.on("initiateBot",e=>{if(console.log("botMessageinitiateBot response:",e),Array.isArray(ne.current)){const t=He([...ne.current],e.toUser,0);console.log("newDatanewDatanewDataarr",t);const a=t.map(t=>t._id==e.toUser?z({},t):t);console.log("newDatanewDatanewData",a),ne.current=a,D(a)}else console.error("newDatanewDatanewData.current is not an array:",ne.current)}),q(a),()=>{a&&a.disconnect()}},[]),l(()=>{const e=JSON.parse(localStorage.getItem("userListStore")||"[]");0==I.length&&re&&(D(e),setTimeout(()=>{le(!1)},200))},[re]),l(()=>{"undefined"!=typeof window&&(localStorage.setItem("activeChats",JSON.stringify(n)),localStorage.setItem("minimizedChats",JSON.stringify(d)),localStorage.setItem("newMessage",JSON.stringify(Y)))},[n,d,Y]),l(()=>{if("undefined"!=typeof window){const e=localStorage.getItem("activeChats"),t=localStorage.getItem("minimizedChats"),a=localStorage.getItem("newMessage");e&&o(JSON.parse(e)),t&&m(JSON.parse(t)),a&&f(JSON.parse(a))}},[]);const Je=e=>{const t=v.current[e];t&&(t.style.height="auto",t.style.height=`${t.scrollHeight}px`)},Ve=()=>{if(Me.current){const e=Me.current.getBoundingClientRect();Re({top:e.top-250,left:e.left,width:e.width}),Ae(!0)}},Ke=async(e,t)=>{const a=c[e]||[];0===a.length?await(async(e,t)=>{try{let a={toUser:e};const r=await L.post("chatUser/addChatUser",a);"success"===r.data.status&&(i(t=>{const a=t[e]||[];return a.includes(r.data.chatUserId)?t:z({},t,{[e]:[...a,r.data.chatUserId]})}),Qe(e,r.data.chatUserId,t))}catch(e){console.log("d",e)}})(e,t):Qe(e,a[0],t)},qe=async(e,t)=>{Xe(e,t)},Qe=(e,t,a)=>{var r;if(localStorage.getItem("authUser"),null!=(r=p[e])&&r.trim()){K.emit("sendMessage",{user_id:e,messageType:ce?"F":"M",message:p[e],chatUserId:t,fileType:ce?ce.type:"",fileUrl:a||"",replyMessageId:Ce._id||""}),f(t=>z({},t,{[e]:""})),fe(""),Oe(),ke("");const r=v.current[e];r&&(r.style.height="auto")}},Xe=async(e,t)=>{var a;if(null!=(a=p[e])&&a.trim()){const a={groupId:null==xe?void 0:xe.chatUserId,messageType:ce?"F":"M",message:p[e],fileType:ce?ce.type:"",fileUrl:t||"",replyMessageId:Ce._id||"",mentionedUsers:Le.map(e=>{var t;return null==e||null==(t=e.userId)?void 0:t._id})};K.emit("sendGroupMessage",a),f(e=>z({},e,{[null==xe?void 0:xe.chatUserId]:""})),fe(""),ke(""),Oe(),$e([])}};return l(()=>{n.forEach(e=>{w.current[e]&&!d.includes(e)&&w.current[e].scrollIntoView({behavior:"smooth"})})},[n,d,P]),l(()=>{""!==pe&&("group"===xe.type?qe(J,pe):Ke(J,pe))},[pe]),/*#__PURE__*/e.createElement($.Provider,{value:{activeChats:n,minimizedChats:d,newMessage:p,messageEndRef:w,handleUserClick:e=>{V(null==e?void 0:e._id),Ae(!1),$e([]),"group"===(null==e?void 0:e.type)?(Ne(""),(async e=>{try{const t=await L.get(`/group/history/${e.chatUserId}`);"success"===t.data.status&&(i(e.chatUserId),B(t.data.chatHistory))}catch(e){console.log("fetchGroupChatHistory",e)}})(e),be(e),(async e=>{try{const t=await L.get(`/group/groupInfo/${e}`);console.log("fetchChatGroupInfo",t.data),O("success"===t.data.status?t.data.groupInfo.userList:[])}catch(e){console.log("fetchChatGroupInfo",e)}})(null==e?void 0:e.chatUserId)):"bot"===(null==e?void 0:e.type)?((async e=>{try{const t=await L.get(`/bot/chatHistory/${e.chatUserId}`);console.log("fetchBotChatHistory",t.data),"success"===t.data.status&&B(t.data.chatList)}catch(e){console.log("fetchBotChatHistory",e)}})(e),we(e)):(be(""),(async e=>{try{let t={toUser:e};const a=await L.post("chatUser/chatHistory",t);console.log("fetchChatHistory",a.data),"success"===a.data.status&&(B(a.data.chatHistory),""!=a.data.chatUserId&&i(t=>{const r=t[e]||[];return r.includes(a.data.chatUserId)?t:z({},t,{[e]:[...r,a.data.chatUserId]})}))}catch(e){console.log("fetchChatHistory",e)}})(null==e?void 0:e._id),Ne(e)),K.emit("readMessage",{user_id:null==e?void 0:e._id});const t=ne.current.map(t=>t._id==(null==e?void 0:e._id)?z({},t,{msg:"Read",unReadCount:0}):t),a=JSON.stringify(I)===JSON.stringify(t);ne.current=t,a||D(t)},toggleMinimize:e=>{m(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},closeChat:e=>{o(t=>t.filter(t=>t!==e)),m(t=>t.filter(t=>t!==e))},handleMessageChange:(e,t)=>{if(V(e),f(a=>z({},a,{[e]:t})),"group"!==xe.type)return;const a=t.lastIndexOf("@");if(console.log("valueatIndex",t,a),-1!==a){const e=t.substring(a+1);""===e?(je(""),Ve()):e.includes(" ")?Ae(!1):(je(e),Se||Ve())}else Ae(!1);$e(e=>e.filter(e=>t.includes(`@${e.userId.name}`)))},sendMessage:Ke,handleKeyDown:(e,t)=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),Ke(e))},minimizedContact:u,setMinimizedContact:g,activeTab:E,setActiveTab:N,handleSwitchTab:e=>{N(e),"contact"===e?(async()=>{try{const e=await L.get("chatUser/contactList");console.log("fetchContacts",e.data),"success"===e.data.status&&(M(e.data.userData),_(e.data.userData))}catch(e){console.log("fetchContacts",e)}})():Ye()},fetchChatUserList:Ye,userList:I,contactList:U,maxChat:C,setMaxChat:k,messages:P,setMessages:B,chats:Y,setChats:H,messageAlert:Q,setMessageAlert:X,setToUser:V,handleAttachmentClick:e=>{V(e),ue.current.click()},fileInputRef:ue,handleFileSelect:e=>{e.target.files.length>0&&(ie(e.target.files[0]),me(!0))},showPreviewDialog:de,isImageFile:e=>e&&e.type.startsWith("image/"),handleCancelFileUpload:Oe,formatFileSize:e=>e<1024?e+" B":e<1048576?(e/1024).toFixed(1)+" KB":(e/1048576).toFixed(1)+" MB",fileToUpload:ce,fetchUploadFileApi:async e=>{try{var t=new FormData;t.append("files",ce);const e=await L.post("chatFile/fileUpload",t,{headers:{"Content-Type":"multipart/form-data"}});"success"===e.data.status&&(console.log("fetchUploadFileApi",e.data),fe(e.data.url),f(e=>z({},e,{[J]:ce.name})))}catch(e){}},isDragging:he,handleDragOver:Pe,handleDragEnter:Be,handleDragLeave:Ge,handleDrop:We,dropAreaRef:ge,textareaRef:v,messageWorkchatAlert:Z,setMessageWorkchatAlert:ee,messageWorkchatUserAlert:te,setMessageWorkchatUserAlert:ae,fetchChatUserList:Ye,handleSendGroupMessage:qe,searchContactVal:h,handleContactSearch:e=>{const t=e.target.value.trim();y(t);const a=t?T.filter(({name:e})=>e.toLowerCase().includes(t.toLowerCase())):T;M(a)},searchVal:x,handleSearchUser:e=>{b(e.target.value);const t=e.target.value.trim(),a=t?R.filter(({name:e})=>e.toLowerCase().includes(t.toLowerCase())):R;D(a)},replyMessageData:Ce,setReplyMessageData:ke,handleReplyMessage:e=>{ke(e)},showModal:Se,modalRef:Te,setShowModal:Ae,groupInputRef:Me,filteredMentionGroupMembers:Fe,handleMentionUserSelect:e=>{const t=p[J]||"",a=t.lastIndexOf("@");if(-1!==a){const r=t.substring(0,a),l=t.substring(a+1),s=`@${e.userId.name} `,n=l.split(" ").slice(1).join(" "),o=`${r}${s}${n?" "+n:""}`;f(e=>z({},e,{[J]:o})),$e(t=>t.some(t=>t.userId._id===e.userId._id)?t:[...t,e]),Ae(!1),requestAnimationFrame(()=>{var e;null==(e=Me.current)||e.focus(),Je(J)})}},autoResizeTextarea:Je,messagesContainerRef:Ie,scrollToMessage:e=>{const t=document.getElementById(`message-${e}`);console.log("messageElement",t),t&&Ie.current&&(t.scrollIntoView({behavior:"smooth",block:"center"}),Ue(e),setTimeout(()=>{Ue("")},2e3))},setHighlightReply:Ue,highlightReply:De,handleDeleteMessage:e=>{try{let t={id:e._id};console.log("handleDelete",G),K.emit("deleteMessage",t),B(t=>t.map(t=>t._id===e._id?z({},t,{isDeleted:!0}):t));const a=I.map(t=>t.messageId===e._id?z({},t,{isDeleted:!0}):t);console.log("newData",a),ne.current=a,D(a)}catch(e){console.log("handleDelete",e)}},handleDeleteGroupMessage:e=>{try{let t={id:null==e?void 0:e._id,groupId:null==e?void 0:e.groupId};console.log("handleDelete",t,P[0]),K.emit("deleteGroupMessage",t),B(t=>t.map(t=>t._id===e._id?z({},t,{isDeleted:!0}):t))}catch(e){console.log("handleDelete",e)}}}},s)},O=/*#__PURE__*/s(),P=({children:t})=>/*#__PURE__*/e.createElement(O.Provider,{value:{handleCognitoVerification:async(e,t)=>{const a={cognitoUserId:e,email:t};try{const e=await j.post("https://chatapi.nte.ai/v3/user/verifyCognito",a);"success"===e.data.status?(localStorage.setItem("authToken",e.data.token),localStorage.setItem("authUser",e.data._id)):console.error("Something went worng")}catch(e){console.error("Cognito Verification Error:",e)}}}},t),B=({src:r})=>{const l=a(null),[s,n]=t(!1),[o,d]=t(0),[m,u]=t(0);/*#__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:l,src:r,onTimeUpdate:()=>{const e=l.current;d(e.currentTime/e.duration*100)},onLoadedMetadata:()=>{u(l.current.duration)},onEnded:()=>n(!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:()=>{const e=l.current;e.paused?(e.play(),n(!0)):(e.pause(),n(!1))}},/*#__PURE__*/e.createElement(s?c:i,{size:20,style:{color:"red"}})),/*#__PURE__*/e.createElement("input",{type:"range",value:o,onChange:e=>{const t=parseFloat(e.target.value);l.current.currentTime=t/100*l.current.duration,d(t)},className:"w-full accent-blue-500 h-1"}),/*#__PURE__*/e.createElement("span",{className:"text-xs text-gray-600 w-12 text-right"},(e=>{const t=Math.floor(e/60),a=Math.floor(e%60);return`${t}:${a<10?"0":""}${a}`})(m))))},G=({src:r})=>{const l=a(null),[s,n]=t(!1),[o,d]=t(0),[m,u]=t(0);/*#__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:()=>{const e=l.current;e.paused?(e.play(),n(!0)):(e.pause(),n(!1))}},/*#__PURE__*/e.createElement(s?c:i,{size:20,className:"text-primary"})),/*#__PURE__*/e.createElement("input",{type:"range",value:o,onChange:e=>{const t=l.current,a=parseFloat(e.target.value);t.currentTime=a/100*t.duration,d(a)},className:"w-full accent-blue-500 h-1"}),/*#__PURE__*/e.createElement("span",{className:"text-xs text-gray-600 w-10 text-right"},(e=>{const t=Math.floor(e/60),a=Math.floor(e%60);return`${t}:${a<10?"0":""}${a}`})(m)),/*#__PURE__*/e.createElement("audio",{ref:l,src:r,onTimeUpdate:()=>{const e=l.current;d(e.currentTime/e.duration*100)},onLoadedMetadata:()=>{u(l.current.duration)},onEnded:()=>n(!1)}))},W=({text:t,color:a})=>{const r=null==t?void 0:t.replace(/(https?:\/\/)/g," $1").trim(),l=/https?:\/\/[^\s]+/g,s=null==r?void 0:r.split(/(https?:\/\/[^\s]+)/g);/*#__PURE__*/return e.createElement(o,null,s.map((t,r)=>l.test(t)?/*#__PURE__*/e.createElement("a",{key:r,href:t,target:"_blank",rel:"noopener noreferrer",className:"underline italic",style:{color:a}},t):/*#__PURE__*/e.createElement("span",{key:r},t)))},Y=({code:a})=>{const[r,l]=t(!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:async()=>{try{if(navigator.clipboard)await navigator.clipboard.writeText(a);else{const e=document.createElement("textarea");e.value=a,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}l(!0),setTimeout(()=>l(!1),2e3)}catch(e){console.error("Copy failed:",e)}},className:"absolute top-2 right-2 px-2 py-1 text-sm bg-gray-200 hover:bg-gray-300 rounded text-gray-700"},r?"Copied!":"Copy"),/*#__PURE__*/e.createElement(_,{language:null,style:R,showLineNumbers:!0},a))},H=({showPreviewDialog:t,fileToUpload:a,handleCancelFileUpload:r,fetchUploadFileApi:l,color:s="#000"})=>{return t?/*#__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:r,style:{color:"#6b7280",cursor:"pointer"}},/*#__PURE__*/e.createElement(d,{size:24}))),/*#__PURE__*/e.createElement("div",{style:{padding:"1rem"}},a&&/*#__PURE__*/e.createElement(o,null,(null==(n=a)||null==(c=n.type)?void 0:c.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(m,{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"}},(e=>{if(!e)return"0 B";const 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:r,style:{padding:"0.5rem 1rem",color:"#374151",marginRight:"0.5rem",borderRadius:"0.375rem",backgroundColor:"transparent",cursor:"pointer"},onMouseOver:e=>e.currentTarget.style.backgroundColor="#f3f4f6",onMouseOut:e=>e.currentTarget.style.backgroundColor="transparent"},"Cancel"),/*#__PURE__*/e.createElement("button",{onClick:l,style:{padding:"0.5rem 1rem",color:"#fff",borderRadius:"0.375rem",display:"flex",alignItems:"center",backgroundColor:s,cursor:"pointer"}},/*#__PURE__*/e.createElement(u,{size:18,style:{marginRight:"0.25rem"}}),"Send")))):null;var n,c},J=({data:t})=>{let a=JSON.parse(t);console.log("mapDetails",a);const r=`https://maps.google.com/maps?q=${null==a?void 0:a.latitude},${null==a?void 0:a.longitude}&z=15&output=embed&markers=color:red%7C${null==a?void 0:a.latitude},${null==a?void 0:a.longitude}`;return console.log("mapUrl",r),/*#__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:r,style:{border:0},referrerPolicy:"no-referrer-when-downgrade"})))},V=a=>{const{color:r,noOfChat:s,senderContainerColor:c,senderTextColor:i,receiverContainerColor:T,receiverTextColor:S,sendButtonColor:A,chatWidth:_,chatHeight:R,cognitoUserId:z,email:j,senderDateTextColor:L,receiverDateTextColor:F,senderLinkTextColor:P,receiverLinkTextColor:V,groupUserNameColors:K,ctaButtonColor:q,ctaButtonText:Q,headerTextColor:X}=a,{activeChats:Z,minimizedChats:ee,newMessage:te,toggleMinimize:ae,closeChat:re,handleMessageChange:le,sendMessage:se,handleKeyDown:ne,handleUserClick:oe,minimizedContact:ce,setMinimizedContact:ie,activeTab:de,handleSwitchTab:me,fetchChatUserList:ue,userList:ge,contactList:pe,setMaxChat:fe,chats:he,messageAlert:ye,setMessageAlert:xe,handleAttachmentClick:be,fileInputRef:ve,handleFileSelect:we,showPreviewDialog:Ee,handleCancelFileUpload:Ne,fileToUpload:Ce,fetchUploadFileApi:ke,isDragging:Ie,handleDragOver:De,handleDragEnter:Ue,handleDragLeave:Me,handleDrop:Te,dropAreaRef:Se,textareaRef:Ae,messageWorkchatAlert:_e,setMessageWorkchatAlert:Re,messageWorkchatUserAlert:ze,setMessageWorkchatUserAlert:je,handleSendGroupMessage:Le,searchContactVal:$e,handleContactSearch:Fe,searchVal:Oe,handleSearchUser:Pe,replyMessageData:Be,setReplyMessageData:Ge,handleReplyMessage:We,showModal:Ye,modalRef:He,setShowModal:Je,groupInputRef:Ve,filteredMentionGroupMembers:Ke,handleMentionUserSelect:qe,autoResizeTextarea:Qe,messagesContainerRef:Xe,scrollToMessage:Ze,highlightReply:et,handleDeleteMessage:tt,handleDeleteGroupMessage:at}=n($),{handleCognitoVerification:rt}=n(O),lt=localStorage.getItem("authUser"),st=e=>e.split("/")[0],nt=e=>`.${e.split(".").at(-1)}`;l(()=>{ue()},[]),l(()=>{s&&fe(s)},[]),l(()=>{rt(z,j)},[z,j]);const ot=e=>{const t=window.open(e,"_blank","noopener,noreferrer");t&&(t.opener=null)},[ct,it]=t(!1),dt=e=>[/<[\w\d]+\s?.*?>/,/\bfunction\b|\bconst\b/,/\bdef\b|\bimport\b/,/=\s*{.*?}/,/<\/[\w\d]+>/].some(t=>t.test(e)),mt=e=>{const t=(null==e?void 0:e.charCodeAt(0))%K.length;return K[t]};return l(()=>{Be&&Ye&&it(!0)},[Be,Ye]),/*#__PURE__*/e.createElement("div",{className:"fixed bottom-0 right-0 flex gap-4 z-50 "},Z.map(t=>{var a;const l=JSON.parse(localStorage.getItem("userListStore")||"[]"),s=ge.find(e=>e._id===t)||pe.find(e=>e._id===t)||l.find(e=>e._id===t)||ge.find(e=>e.userId._id===t),n=he[t]||[],C=ee.includes(t);return je(C),console.log("useruseruser",s,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":ct?"550px":R,width:ct?"500px":_},ref:Se,onDragOver:De,onDragEnter:Ue,onDragLeave:Me,onDrop:Te},/*#__PURE__*/e.createElement("div",{className:"px-3 py-2 border-b flex items-center justify-between rounded-t-lg",style:{backgroundColor:r||"#000"}},/*#__PURE__*/e.createElement("div",{className:"flex items-center cursor-pointer flex-1",onClick:e=>{e.stopPropagation(),ae(t),xe(!1)}},/*#__PURE__*/e.createElement("div",{className:"relative"},null!=s&&s.profileImage?/*#__PURE__*/e.createElement("img",{src:null==s?void 0:s.profileImage,alt:s.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==s?void 0:s.type)?/*#__PURE__*/e.createElement(g,null):null==s||null==(a=s.name)?void 0:a.charAt(0)),"available"===(null==s?void 0:s.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==s?void 0:s.name)||""),"bot"===s.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(ct?f:p,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation(),it(!ct)}})),C?/*#__PURE__*/e.createElement(h,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation(),ae(t),xe(!1)}}):/*#__PURE__*/e.createElement(y,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation(),ae(t)}}),/*#__PURE__*/e.createElement(d,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation(),re(t),je(!1)}}))),Ie?/*#__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(x,{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(o,null,"user"===s.type&&/*#__PURE__*/e.createElement(o,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[...n].map((t,a)=>/*#__PURE__*/e.createElement("div",{ref:Xe,key:a},/*#__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),[...t.chats].reverse().map((t,a)=>{var l,s;/*#__PURE__*/return e.createElement("div",{id:`message-${t._id}`,key:a,className:`mb-2 flex flex-col ${"me"===t.sender?"items-end":"items-start"} ${et==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?c:T,color:"me"===t.sender?i: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?c:T,color:"me"===t.sender?i: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:e=>{e.stopPropagation(),Ze(t.replyMessageId._id)},style:{}},/*#__PURE__*/e.createElement("div",{className:"text-xs font-medium mb-1 text-black text-primary"},(null==t||null==(l=t.replyMessageId)||null==(l=l.fromUserId)?void 0:l._id)===lt?"You":null==t||null==(s=t.replyMessageId)||null==(s=s.fromUserId)?void 0:s.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-700 truncate"},null==t?void 0:t.replyMessageId.messageContent)),"image"===st(t.fileType)&&/*#__PURE__*/e.createElement("img",{src:t.link,alt:"Preview",className:"max-h-32 rounded cursor-pointer mx-auto",onClick:()=>ot(t.link)}),"video"===st(t.fileType)&&/*#__PURE__*/e.createElement(B,{src:t.link,color:r}),"audio"===st(t.fileType)&&/*#__PURE__*/e.createElement(G,{src:t.link,color:r}),"application"===st(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex items-center bg-gray-200 p-2 rounded cursor-pointer",onClick:()=>ot(t.link)},/*#__PURE__*/e.createElement(m,{size:20,className:"text-black mr-2"}),/*#__PURE__*/e.createElement("p",{className:"text-sm font-medium text-black"},"Document",nt(t.link))),!dt(t.text)&&"image"!==st(t.fileType)&&""!==t.text&&"L"!==t.type&&/*#__PURE__*/e.createElement("div",{className:"text-sm mt-1"},/*#__PURE__*/e.createElement(W,{text:(null==t?void 0:t.text)||"",color:"me"===t.sender?P:V})),dt(t.text)&&/*#__PURE__*/e.createElement(Y,{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(b,{onClick:()=>{We(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18}),"me"===t.sender&&/*#__PURE__*/e.createElement(v,{onClick:()=>{tt(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?L:F}},"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}))))})))),Be&&/*#__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"===Be.sender?null==Be?void 0:Be.user.name:"You"),/*#__PURE__*/e.createElement("button",{onClick:()=>Ge(""),className:"text-gray-400 hover:text-gray-600 transition-colors flex-shrink-0"},/*#__PURE__*/e.createElement(d,{className:"w-4 h-4"}))),/*#__PURE__*/e.createElement("p",{className:"text-sm text-gray-800 mt-1 w-full line-clamp-2"},null==Be?void 0:Be.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:()=>be(t)},/*#__PURE__*/e.createElement(N,{size:16})),/*#__PURE__*/e.createElement("input",{type:"file",ref:ve,onChange:we,className:"hidden"}),/*#__PURE__*/e.createElement("textarea",{ref:e=>Ae.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:te[t]||"",onChange:e=>{le(t,e.target.value),Qe(t)},onKeyDown:e=>ne(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:()=>se(t)},/*#__PURE__*/e.createElement(u,{size:16}))))),"group"===s.type&&/*#__PURE__*/e.createElement(o,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[...n].map((t,a)=>/*#__PURE__*/e.createElement("div",{ref:Xe,key:a},/*#__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),[...t.chats].reverse().map((t,a)=>{var l,n;const o="me"===t.sender,d="reciver"===t.sender;return console.log("message",t),"E"!==t.type?/*#__PURE__*/e.createElement("div",{id:`message-${t._id}`,key:a,className:`mb-2 flex ${o?"justify-end":"justify-start"} ${et==t._id?"transition-colors duration-1000 bg-yellow-100 rounded-xl":""}`},!o&&(s.profileImage?/*#__PURE__*/e.createElement("img",{src:s.profileImage,alt:s.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"},s.name.charAt(0))),/*#__PURE__*/e.createElement("div",{className:"flex flex-col max-w-[80%] relative group"},d&&/*#__PURE__*/e.createElement("span",{className:"text-xs font-semibold mb-1",style:{color:mt(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?c:T,color:"me"===t.sender?i: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 "+(o?"bg-blue-500 text-white rounded-br-none":"bg-gray-200 text-gray-800 rounded-bl-none"),style:{backgroundColor:o?c:T,color:o?i: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:e=>{e.stopPropagation(),Ze(t.replyMessageId._id)}},/*#__PURE__*/e.createElement("div",{className:"text-xs  font-medium mb-1 text-black"},(null==t||null==(l=t.replyMessageId)||null==(l=l.userId)?void 0:l._id)===lt?"You":null==t||null==(n=t.replyMessageId)||null==(n=n.userId)?void 0:n.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-700 truncate"},null==t?void 0:t.replyMessageId.messageContent)),"image"===st(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex justify-center items-center mb-1"},/*#__PURE__*/e.createElement("img",{onClick:()=>ot(t.link),src:t.link,alt:"Preview",className:"max-h-28 rounded cursor-pointer"})),"video"===st(t.fileType)&&/*#__PURE__*/e.createElement(B,{src:t.link,color:r}),"audio"===st(t.fileType)&&/*#__PURE__*/e.createElement(G,{src:t.link,color:r}),"application"===st(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex items-center bg-gray-100 p-2 rounded cursor-pointer mb-1",onClick:()=>ot(t.link)},/*#__PURE__*/e.createElement(m,{size:20,className:"text-black mr-2"}),/*#__PURE__*/e.createElement("p",{className:"text-sm text-black"},"Document",nt(t.link))),"L"===t.type&&/*#__PURE__*/e.createElement(J,{data:t.text}),/*#__PURE__*/e.createElement("div",{className:"text-sm"},!dt(t.text)&&"image"!=st(t.fileType)&&""!==t.text&&"L"!==t.type&&/*#__PURE__*/e.createElement(W,{text:t.text,color:o?P:V}),dt(t.text)&&/*#__PURE__*/e.createElement(Y,{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(b,{onClick:()=>{We(t)},className:"text-gray-400 hover:text-primary cursor-pointer",size:18}),"me"===t.sender&&/*#__PURE__*/e.createElement(v,{onClick:()=>{at(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?L:F}},"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:r,color:X}},t.text)})))),Ye&&/*#__PURE__*/e.createElement("div",{ref:He,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:()=>Je(!1)},/*#__PURE__*/e.createElement(d,{size:16}))),/*#__PURE__*/e.createElement("div",{className:" max-h-60 overflow-y-auto "},Ke.length>0?Ke.map(t=>{var a,r,l;return t.userId._id!=lt&&/*#__PURE__*/e.createElement("div",{key:t.id,onClick:()=>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!=(a=t.userId)&&a.profileImage?/*#__PURE__*/e.createElement("img",{src:t.userId.profileImage,alt:null==(r=t.userId.name)?void 0:r.charAt(0),className:"w-full h-full object-cover"}):/*#__PURE__*/e.createElement("span",{className:"text-sm font-medium text-black"},null==(l=t.userId.name)?void 0:l.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")))),Be&&/*#__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"===Be.sender?Be.user.name:"You"),/*#__PURE__*/e.createElement("button",{onClick:()=>Ge(""),className:"text-gray-400 hover:text-gray-600 transition-colors flex-shrink-0"},/*#__PURE__*/e.createElement(d,{className:"w-4 h-4"}))),/*#__PURE__*/e.createElement("p",{className:"text-sm text-gray-800 mt-1 w-full line-clamp-2"},null==Be?void 0:Be.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:()=>be(t)},/*#__PURE__*/e.createElement(N,{size:16})),/*#__PURE__*/e.createElement("input",{type:"file",ref:ve,onChange:we,className:"hidden"}),/*#__PURE__*/e.createElement("textarea",{ref:e=>{Ve.current=e,Ae.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:te[t]||"",onChange:e=>{le(t,e.target.value),Qe(t)},onKeyDown: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:()=>Le(t)},/*#__PURE__*/e.createElement(u,{size:16}))))),"bot"===s.type&&/*#__PURE__*/e.createElement(o,null,/*#__PURE__*/e.createElement("div",{className:"flex-1 p-3 overflow-y-auto flex flex-col-reverse"},[...n].map((t,a)=>/*#__PURE__*/e.createElement("div",{key:a},/*#__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),[...t.chats].reverse().map((t,a)=>{const l="me"===t.sender;/*#__PURE__*/return e.createElement("div",{key:a,className:"mb-2 flex "+(l?"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:mt(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 "+(l?"bg-blue-500 text-white rounded-br-none":"bg-gray-200 text-gray-800 rounded-bl-none"),style:{backgroundColor:l?c:T,color:l?i:S}},"image"===st(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex justify-center items-center mb-1"},/*#__PURE__*/e.createElement("img",{onClick:()=>ot(t.link),src:t.link,alt:"Preview",className:"max-h-28 rounded cursor-pointer"})),"video"===st(t.fileType)&&/*#__PURE__*/e.createElement(B,{src:t.link,color:r}),"audio"===st(t.fileType)&&/*#__PURE__*/e.createElement(G,{src:t.link,color:r}),"application"===st(t.fileType)&&/*#__PURE__*/e.createElement("div",{className:"flex items-center bg-gray-100 p-2 rounded cursor-pointer mb-1",onClick:()=>ot(t.link)},/*#__PURE__*/e.createElement(m,{size:20,className:"text-black mr-2"}),/*#__PURE__*/e.createElement("p",{className:"text-sm text-black"},"Document",nt(t.link))),/*#__PURE__*/e.createElement("div",{className:"text-sm"},/*#__PURE__*/e.createElement(W,{text:t.text,color:"me"===t.sender?"#fff":"Blue"}),dt(t.text)&&/*#__PURE__*/e.createElement(Y,{code:t.text})),"cta"===(null==t?void 0:t.type)&&t.ctaData.map(t=>/*#__PURE__*/e.createElement("span",{className:"px-3 py-1 text-xs w-full justify-center mt-2  text-white rounded-md hover:bg-primary flex items-center disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer",style:{backgroundColor:q||"#000",color:Q||"#fff"},onClick:()=>window.open(null==t?void 0:t.url,"_blank","noopener,noreferrer")},t.label))),/*#__PURE__*/e.createElement("span",{className:"text-xs mt-1 self-start",style:{color:l?L:F}},t.time)))})))))))}),/*#__PURE__*/e.createElement("div",{className:"w-72 bg-white rounded-t-lg shadow-lg flex flex-col ",style:{height:ce?"36px":"550px",alignSelf:ce?"end":""}},/*#__PURE__*/e.createElement("div",{className:"px-3 py-2 border-b flex items-center justify-between rounded-t-lg",style:{backgroundColor:r||"#000"}},/*#__PURE__*/e.createElement("div",{className:"flex items-center cursor-pointer flex-1",onClick:e=>{e.stopPropagation(),ae(0),ie(!ce),ue(),Re(!1)}},/*#__PURE__*/e.createElement("div",{className:"ml-2 flex gap-1 items-center justify-center"},/*#__PURE__*/e.createElement("div",{className:"font-medium text-white text-sm"},"Workchat  "),/*#__PURE__*/e.createElement("a",{href:"https://chat.nte.ai/app",target:"_blank",rel:"noopener noreferrer"},/*#__PURE__*/e.createElement(C,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation()}})),/*#__PURE__*/e.createElement("span",{className:`text-xs ${!ze&&ce&&_e&&"bg-white"} text-black rounded-xl px-2 py-1 ${_e?"animate-blink":""}`},!ze&&ce&&_e&&"New Message"),"                   ")),/*#__PURE__*/e.createElement("div",{className:"flex space-x-2"},/*#__PURE__*/e.createElement(k,{size:16,className:"text-white cursor-pointer",onClick:e=>{e.stopPropagation(),ie(!ce),Re(!1)}}))),!ce&&/*#__PURE__*/e.createElement("div",{className:"flex-1 overflow-y-auto no-scrollbar"},/*#__PURE__*/e.createElement("div",{className:"  w-full bg-white border-l border-gray-200 overflow-y-auto "},/*#__PURE__*/e.createElement("div",{className:"w-full max-w-sm mx-auto "},/*#__PURE__*/e.createElement("div",{className:"flex border-b justify-between "},/*#__PURE__*/e.createElement("button",{onClick:()=>me("chat"),className:"flex items-center px-4 py-2 text-sm font-medium border-b-2 justify-center w-full "+("chat"===de?"border-blue-500 text-blue-600  ":"border-transparent text-gray-500 hover:text-blue-600 ")},/*#__PURE__*/e.createElement(I,{className:"w-4 h-4 mr-2"}),"Chats"),/*#__PURE__*/e.createElement("button",{onClick:()=>me("contact"),className:"flex items-center px-4 py-2 text-sm font-medium border-b-2 w-full "+("contact"===de?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-blue-600")},/*#__PURE__*/e.createElement(D,{className:"w-4 h-4 mr-2"}),"Contacts"))),"chat"===de?/*#__PURE__*/e.createElement("div",{className:"divide-y divide-gray-200"},/*#__PURE__*/e.createElement("div",{className:"relative m-1"},/*#__PURE__*/e.createElement(U,{className:"absolute left-3 top-2.5 text-gray-500",size:12}),/*#__PURE__*/e.createElement("input",{type:"text",placeholder:"Search",className:"w-full bg-gray-200 py-2 pl-10 pr-4 rounded-xl text-sm text-black focus:outline-none shadow ",value:Oe,onChange:Pe})),ge.map(t=>{var a,r;/*#__PURE__*/return e.createElement("div",{key:t.id,className:"p-3 flex items-center hover:bg-gray-50 cursor-pointer",onClick:()=>oe(t)},/*#__PURE__*/e.createElement("div",{className:"relative",style:{width:"20%"}},null!=t&&t.profileImage?/*#__PURE__*/e.createElement("img",{src:null==t?void 0:t.profileImage,alt:null==(a=t.name)?void 0:a.charAt(0),className:"w-10 h-10 rounded-full items-center justify-center flex border"}):"group"===t.type?/*#__PURE__*/e.createElement("span",{className:"w-10 h-10 rounded-full items-center justify-center flex border"},/*#__PURE__*/e.createElement(g,null)," "):/*#__PURE__*/e.createElement("span",{className:"w-10 h-10 rounded-full items-center justify-center flex border"},null==(r=t.name)?void 0:r.charAt(0)),"available"===t.status&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 bg-green-500 rounded-full border-2 border-white"}),"Do not Disturb"===t.status&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 bg-yellow-500 rounded-full border-2 border-white"}),"offline"===t.status&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 bg-gray-500 rounded-full border-2 border-white"}),"bot"==t.type&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 "},"  ",/*#__PURE__*/e.createElement(M,{size:14,style:{color:"#008293"}}))),/*#__PURE__*/e.createElement("div",{className:"ml-3 w-full"},/*#__PURE__*/e.createElement("div",{className:"flex items-center justify-between"},/*#__PURE__*/e.createElement("div",{className:"font-medium text-gray-900 truncate max-w-[8rem]"},t.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-400 whitespace-nowrap"},(e=>{const t=new Date(e),a=new Date;return t.toDateString()===a.toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):`${String(t.getDate()).padStart(2,"0")}-${String(t.getMonth()+1).padStart(2,"0")}-${t.getFullYear()}`})(null==t?void 0:t.createdAt))),/*#__PURE__*/e.createElement("div",{className:"flex items-center max-w-[13rem] truncate "+("New"===t.msg?"text-sm font-bold text-black":"text-xs text-gray-500")},t.isDeleted?/*#__PURE__*/e.createElement("span",{className:"flex-1 truncate max-w-[10rem] italic"},"This message was deleted"):/*#__PURE__*/e.createElement("span",{className:"flex-1 truncate max-w-[10rem]"},t.messageContent),t.unReadCount>0&&/*#__PURE__*/e.createElement("span",{className:"ml-2 text-xs text-white bg-red-500 rounded-full px-2 py-0.5 shrink-0 items-end"},t.unReadCount))))})):/*#__PURE__*/e.createElement("div",{className:"divide-y divide-gray-200"},/*#__PURE__*/e.createElement("div",{className:"relative m-1"},/*#__PURE__*/e.createElement(U,{className:"absolute left-3 top-2.5 text-gray-500",size:12}),/*#__PURE__*/e.createElement("input",{type:"text",placeholder:"Contact Search",className:"w-full bg-gray-200 py-2 pl-10 pr-4 rounded-xl text-sm text-black focus:outline-none shadow ",value:$e,onChange:Fe})),pe.map(t=>/*#__PURE__*/e.createElement("div",{key:t.id,className:"p-3 flex items-center hover:bg-gray-50 cursor-pointer",onClick:()=>oe(t)},/*#__PURE__*/e.createElement("div",{className:"relative"},null!=t&&t.profileImage?/*#__PURE__*/e.createElement("img",{src:null==t?void 0:t.profileImage,alt:t.name.charAt(0),className:"w-10 h-10 rounded-full items-center justify-center flex border"}):/*#__PURE__*/e.createElement("span",{className:"w-10 h-10 rounded-full items-center justify-center flex border"},t.name.charAt(0)),"available"===t.status&&/*#__PURE__*/e.createElement("div",{className:"absolute bottom-0 right-0 w-3 h-3 bg-green-500 rounded-full border-2 border-white"})),/*#__PURE__*/e.createElement("div",{className:"ml-3"},/*#__PURE__*/e.createElement("div",{className:"font-medium text-gray-900"},t.name),/*#__PURE__*/e.createElement("div",{className:"text-xs text-gray-500"},t.lastSeen)))))))),Ee&&/*#__PURE__*/e.createElement(H,{showPreviewDialog:Ee,fileToUpload:Ce,handleCancelFileUpload:Ne,fetchUploadFileApi:ke,color:r}))};function K(t){/*#__PURE__*/return e.createElement("div",{className:"workchat"},/*#__PURE__*/e.createElement(P,null,/*#__PURE__*/e.createElement(F,null,/*#__PURE__*/e.createElement(V,t))))}T.defaults.chaturl="https://chatapi.nte.ai",global.$axios=T,global.uri=T.defaults.chaturl;export{K as Workchat};
//# sourceMappingURL=index.modern.mjs.map