@amirnapster/chat 1.7.0 → 1.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4,34 +4,34 @@ var material = require('@mui/material');
4
4
  var react = require('react');
5
5
  var reactQuery = require('react-query');
6
6
  var zustand = require('zustand');
7
- var ar = require('axios');
7
+ var ao = require('axios');
8
8
  var me = require('react-hot-toast');
9
9
  var shallow = require('zustand/react/shallow');
10
10
  var socket_ioClient = require('socket.io-client');
11
11
  var be = require('dayjs');
12
- var ur = require('jalaliday');
13
- var mr = require('dayjs/plugin/isToday.js');
14
- var pr = require('dayjs/plugin/isYesterday.js');
12
+ var mo = require('jalaliday');
13
+ var po = require('dayjs/plugin/isToday.js');
14
+ var ho = require('dayjs/plugin/isYesterday.js');
15
15
  var jsxRuntime = require('react/jsx-runtime');
16
16
  var reactLottiePlayer = require('@lottiefiles/react-lottie-player');
17
17
  var iconsMaterial = require('@mui/icons-material');
18
18
  var reactVirtual = require('@tanstack/react-virtual');
19
- var qr = require('react-markdown');
20
- var Vr = require('remark-gfm');
19
+ var Vo = require('react-markdown');
20
+ var Jo = require('remark-gfm');
21
21
 
22
22
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
23
 
24
- var ar__default = /*#__PURE__*/_interopDefault(ar);
24
+ var ao__default = /*#__PURE__*/_interopDefault(ao);
25
25
  var me__default = /*#__PURE__*/_interopDefault(me);
26
26
  var be__default = /*#__PURE__*/_interopDefault(be);
27
- var ur__default = /*#__PURE__*/_interopDefault(ur);
28
- var mr__default = /*#__PURE__*/_interopDefault(mr);
29
- var pr__default = /*#__PURE__*/_interopDefault(pr);
30
- var qr__default = /*#__PURE__*/_interopDefault(qr);
31
- var Vr__default = /*#__PURE__*/_interopDefault(Vr);
27
+ var mo__default = /*#__PURE__*/_interopDefault(mo);
28
+ var po__default = /*#__PURE__*/_interopDefault(po);
29
+ var ho__default = /*#__PURE__*/_interopDefault(ho);
30
+ var Vo__default = /*#__PURE__*/_interopDefault(Vo);
31
+ var Jo__default = /*#__PURE__*/_interopDefault(Jo);
32
32
 
33
- var B=zustand.create((t,o)=>({accounts:[],chats:[],statusTooltip:true,isMy:false,broadcastState:null,addPreviewChat:n=>{let r=`preview_chat_${n.receiverId}`;if(o().chats.find(e=>e._id===r)){o().setCurrentChat(r);return}t(e=>({chats:[{_id:r,avatar:n.avatar,messages:[],isActive:true,unReadCount:0,status:n.status,title:n.displayName,receiverId:n.receiverId,isPreview:true,isBot:false,lastSeen:n.lastActive},...e.chats.map(s=>({...s,isActive:false}))]}));},updateChatStatus:(n,r)=>{t(c=>({accounts:c.accounts.map(e=>e._id===n?{...e,status:r}:e)}));},setActiveAccount:n=>{let{accounts:r}=o();if(!r.find(s=>s._id===n)){console.warn("[setActiveAccount] Account not found:",n);return}let e=r.map(s=>({...s,isActive:s._id===n}));t({accounts:e}),o().refreshBroadcastPermissions();},setAccounts:n=>{t({accounts:n});},setChats:n=>t(()=>{let r=o().getActiveAccount(),c=o().broadcastState,s=o().chats.filter(i=>i.isPreview&&!n.some(x=>x._id===i._id)),f=n.map(i=>{let x=!!(i?.type==="Broadcast"||i?.isDefaultBroadcast),S=i?.isBot===true,F=i?.ownerId||(typeof i?.owner=="object"?i?.owner?._id:void 0)||c?.ownerId||void 0,M=x&&F?F===(r?._id??""):true,E=S?false:x?M:i?.canSendMessages??true,b=i?.composerHint||(S?"\u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u062A\u0648\u0633\u0637 \u0631\u0628\u0627\u062A \u0645\u062F\u06CC\u0631\u06CC\u062A \u0645\u06CC\u200C\u0634\u0648\u062F \u0648 \u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":E?void 0:"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.");return {...i,ownerId:F,isTyping:false,canSendMessages:E,composerHint:b,isBot:S}}).sort((i,x)=>{let S=!!(i.type==="Broadcast"||i.isDefaultBroadcast),C=!!(x.type==="Broadcast"||x.isDefaultBroadcast);return S&&!C?-1:C&&!S?1:0}),h=[...s,...f],d=f.find(i=>i.type==="Broadcast"||i.isDefaultBroadcast);return {chats:h,broadcastState:d?{chatId:d._id,ownerId:d.ownerId,isDefault:!!d.isDefaultBroadcast}:null}}),getActiveAccount:()=>{let{accounts:n}=o();return n.find(r=>r.isActive)},setCurrentChat:n=>{t(r=>({accounts:r.accounts.map(e=>({...e,unreadChatsCount:e.isActive&&e.unreadChatsCount&&e.unreadChatsCount>0?e.unreadChatsCount-1:e.unreadChatsCount})),chats:r.chats.map(e=>({...e,isActive:e._id===n,unReadCount:e._id===n?0:e.unReadCount,messages:e._id===n?e.messages.map(s=>({...s,hasSeen:true})):e.messages}))}));},getCurrentChat:()=>{let{chats:n}=o();return n.find(r=>r.isActive)??null},addMessageToChat:(n,r)=>{t(c=>{let e=c.chats.findIndex(m=>m._id===n),s=[...c.chats];if(e!==-1){let m=s[e];if(m.messages.some(d=>d.id===r.id)){if(r.id.startsWith("temp-")===false&&m.messages.some(i=>i.id.startsWith("temp-"))){let i=m.messages.map(S=>S.id.startsWith("temp-")&&S.content===r.content&&Math.abs(S.createdAt-r.createdAt)<5e3?r:S),x={...m,lastMessage:r,messages:i};return s.splice(e,1),s.unshift(x),{chats:s}}return c}let h={...s[e],lastMessage:r,messages:[...s[e].messages,r]};return s.splice(e,1),s.unshift(h),{chats:s}}else {let m=c.chats.findIndex(f=>f.isPreview&&f.receiverId===r.senderId);if(m!==-1){let f=s[m],h={...f,_id:n,isPreview:false,lastMessage:r,messages:[...f.messages,r]};return s.splice(m,1),s.unshift(h),{chats:s}}else return {chats:[{_id:n,lastMessage:r,messages:[r],avatar:r.avatar,isActive:false,title:r.senderName,receiverId:r.senderId,unReadCount:0,lastSeen:new Date().toISOString()},...c.chats]}}});},updateMessageInChat:(n,r,c)=>{t(e=>{let s=e.chats.findIndex(x=>x._id===n);if(s===-1)return e;let m=[...e.chats],f=m[s],h=f.messages.findIndex(x=>x.id===r);if(h===-1)return e;let d=[...f.messages];d[h]={...d[h],...c};let i={...f,messages:d,lastMessage:h===d.length-1?d[h]:f.lastMessage};return m[s]=i,{chats:m}});},setMessagesForChat:(n,r)=>{t(c=>{let e=c.chats.findIndex(s=>s._id===n);if(e!==-1){let s=[...c.chats];return s[e].messages=r,r.length>0&&(s[e].lastMessage=r[r.length-1]),{chats:s}}else return console.warn(`Chat with ID ${n} not found. Messages not set.`),{}});},setTypingStatus:(n,r)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,isTyping:r}:e)})),setStatusTooltip:n=>t({statusTooltip:n}),blockUser:n=>{t(r=>({chats:r.chats.map(c=>c._id===n?{...c,isBlockedByMe:true}:c)}));},unblockUser:n=>{t(r=>({chats:r.chats.map(c=>c._id===n?{...c,isBlockedByMe:false}:c)}));},updateChatBlockStatus:(n,r,c)=>{t(e=>({chats:e.chats.map(s=>s._id===n?{...s,isBlockedByMe:r,isBlockedByTarget:c}:s)}));},setIsMy:n=>t({isMy:n}),setBroadcastState:n=>t({broadcastState:n}),refreshBroadcastPermissions:()=>{let{broadcastState:n}=o();if(!n)return;let r=o().getActiveAccount();t(c=>({chats:c.chats.map(e=>{if(e._id!==n.chatId)return e;let s=n.ownerId?n.ownerId===(r?._id??""):false;return {...e,canSendMessages:s,composerHint:s?void 0:e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."}})}));},updateChatPermissions:(n,r)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,...r,composerHint:r.canSendMessages===false?r.composerHint||e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":r.composerHint}:e)}))}));var Y=zustand.create(t=>({socket:null,socketConnect:o=>t({socket:o}),socketDisconnect:()=>t({socket:null})}));var fe=zustand.create(t=>({token:"",setToken:o=>t({token:o})}));var nr={serviceApi:"https://gwdev.rasmio.com/api/chat/",socketUrl:"wss://devsocket.rasmio.com/chat",baseApi:"https://gwdev.rasmio.com/api/"},ye={...nr},Fe=new Set,K=()=>ye,Je=t=>(ye={...ye,...Object.fromEntries(Object.entries(t).filter(([,o])=>o!==void 0))},Fe.forEach(o=>o(ye)),ye);var Qe=t=>(Fe.add(t),()=>Fe.delete(t));var{serviceApi:ir}=K(),ce=ar__default.default.create({adapter:"fetch",baseURL:ir,timeout:2e4});Qe(t=>{ce.defaults.baseURL=t.serviceApi;});var cr=({children:t,token:o})=>{let n=fe(r=>r.setToken);return react.useEffect(()=>{o&&(n(o),ce.defaults.headers.common.Authorization=`Bearer ${o}`);},[o]),o?t:null},Ze=cr;var et=(t,o)=>{let{current:n}=react.useRef(socket_ioClient.io(t,o));return n};be__default.default.extend(ur__default.default);be__default.default.extend(mr__default.default);be__default.default.extend(pr__default.default);var de=t=>{let o=be__default.default(t).calendar("jalali").locale("fa"),n=be__default.default().calendar("jalali").locale("fa");return o.isSame(n,"day")?"\u0627\u0645\u0631\u0648\u0632":o.isSame(n.subtract(1,"day"),"day")?"\u062F\u06CC\u0631\u0648\u0632":o.year()===n.year()?o.format("D MMMM"):o.format("D MMMM YYYY")};var gr=({children:t,socketUrl:o})=>{let n=fe(a=>a.token),r=react.useMemo(()=>o||"wss://devsocket.rasmio.com/chat",[o]),{socketConnect:c}=Y(shallow.useShallow(a=>({socketConnect:a.socketConnect}))),e=et(r,{transports:["websocket"],reconnectionAttempts:3,reconnectionDelay:3e3,withCredentials:false,autoConnect:false,upgrade:false,auth:{token:`Bearer ${n}`}}),{setAccounts:s,setChats:m,addMessageToChat:f,setMessagesForChat:h,setActiveAccount:d,currentChat:i,setCurrentChat:x,addPreviewChat:S,accounts:C,updateChatStatus:F,updateChatBlockStatus:M,setIsMy:E,refreshBroadcastPermissions:b,updateChatPermissions:k}=B(shallow.useShallow(a=>({setAccounts:a.setAccounts,setChats:a.setChats,addMessageToChat:a.addMessageToChat,setMessagesForChat:a.setMessagesForChat,setActiveAccount:a.setActiveAccount,currentChat:a.getCurrentChat(),setCurrentChat:a.setCurrentChat,addPreviewChat:a.addPreviewChat,accounts:a.accounts,updateChatStatus:a.updateChatStatus,updateChatBlockStatus:a.updateChatBlockStatus,setIsMy:a.setIsMy,refreshBroadcastPermissions:a.refreshBroadcastPermissions,updateChatPermissions:a.updateChatPermissions}))),A=react.useRef(false),T=react.useRef(new Set);react.useEffect(()=>{let y=K().companyId;if(!y||!e||C.length===0||!e.connected)return;let O=C.find(w=>String(w.rasmioId)===String(y));!O||C.find(w=>w.isActive)?._id===O._id||e.emit("USER_JOINED",{accountId:O._id});},[e,C]);let D=react.useCallback(a=>{let y=B.getState().getActiveAccount(),O={id:a._id,senderId:a.sender._id,senderName:a.sender.displayName,avatar:a.sender.avatar,content:a.content,time:new Date(a.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(a.createdAt),createdAt:new Date(a.createdAt).getTime(),hasSeen:a.hasSeen,attachments:a.attachments?a.attachments.map(u=>({id:u._id||u.id,url:u.url,thumbnailUrl:u.thumbnailUrl,signedUrl:u.signedUrl,thumbnailSignedUrl:u.thumbnailSignedUrl,mimeType:u.mimeType,size:u.size,originalName:u.originalName,sha256:u.sha256,width:u.width,height:u.height,durationSec:u.durationSec})):[],buttons:a.buttons||[]};if(a.sender._id===y?._id){let u=B.getState(),w=u.chats.find(H=>H._id===a.chatId);if(w){let H=w.messages.find(q=>q.id===a._id||q.id.startsWith("temp-")&&q.content===a.content);if(H){u.updateMessageInChat(a.chatId,H.id,O);return}}}f(a.chatId,O);},[f]),G=react.useCallback(a=>{let O=K().companyId,u=new URL(window.location.href),w=a.find(P=>P.__t==="User"),H=u.searchParams.has("cmp"),q=u.searchParams.get("my")==="true",Z=a.find(P=>P.__t==="Company"),p=u.searchParams.get("cmp");E(q);let L=O||p,z=L?a.find(P=>String(P?.rasmioId)===String(L)):void 0;if(L&&z&&!A.current)e.emit("USER_JOINED",{accountId:z._id}),A.current=true,p&&(u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString()));else if(w&&!A.current&&!H&&!q&&!L){e.emit("USER_JOINED",{accountId:w._id}),A.current=true;let P=u.searchParams.get("targetCompanyId");P&&!T.current.has(P)&&(T.current.add(P),e.emit("ACCOUNT_INFO",{id:P}),setTimeout(()=>{let he=new URL(window.location.href);he.searchParams.get("targetCompanyId")===P&&(he.searchParams.delete("targetCompanyId"),window.history.replaceState({},document.title,he.toString()),me__default.default.error("\u0627\u0645\u06A9\u0627\u0646 \u0628\u0627\u0632 \u06A9\u0631\u062F\u0646 \u06AF\u0641\u062A\u06AF\u0648 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F"));},5e3));}else if(!A.current){let P=Z;e.emit("USER_JOINED",{accountId:P?._id}),A.current=true,u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString());}u.searchParams.has("my")&&(u.searchParams.delete("my"),window.history.replaceState({},document.title,u.toString())),s(a);},[e,s,E]),U=react.useCallback(a=>{let y=a.map(w=>({...w,messages:w.messages||[],unReadCount:w.unReadCount||0}));m(y),b();let u=new URL(window.location.href).searchParams.get("chatId");u&&y.find(H=>H._id===u)&&!B.getState().getCurrentChat()&&(x(u),e&&e.emit("GET_MESSAGES",{chatId:u}));},[m,b,x,e]),g=react.useCallback(a=>{d(a);},[d]),j=react.useCallback(a=>{let y=a?.message||a?.payload?.message||a?.payload?.reason||a?.data?.message||"\u062E\u0637\u0627\u06CC \u0646\u0627\u0645\u0634\u062E\u0635 \u0631\u062E \u062F\u0627\u062F\u0647 \u0627\u0633\u062A";me__default.default.error(y);let O=a?.chatId||a?.payload?.chatId||a?.data?.chatId||a?.meta?.chatId;!O||!(a?.code&&["BROADCAST_READ_ONLY","CHAT_PERMISSION_DENIED"].includes(a.code)||y.toLowerCase().includes("broadcast")||y.toLowerCase().includes("\u0627\u062C\u0627\u0632\u0647"))||k(O,{canSendMessages:false,composerHint:y});},[k]),J=react.useCallback(a=>{let O=a.map(u=>({id:u._id,senderId:u.sender._id,senderName:u.sender.displayName,avatar:u.sender.avatar,content:u.content,time:new Date(u.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(u.createdAt),createdAt:new Date(u.createdAt).getTime(),hasSeen:u.hasSeen,attachments:u.attachments?u.attachments.map(w=>({id:w._id||w.id,url:w.url,thumbnailUrl:w.thumbnailUrl,signedUrl:w.signedUrl,thumbnailSignedUrl:w.thumbnailSignedUrl,mimeType:w.mimeType,size:w.size,originalName:w.originalName,sha256:w.sha256,width:w.width,height:w.height,durationSec:w.durationSec})):[],buttons:u.buttons||[]})).sort((u,w)=>u.createdAt-w.createdAt);i&&h(i._id,O);},[i,h]),ne=react.useCallback(a=>{let y=B.getState(),O=y.chats.find(H=>H._id===a.chatId);if(a.receiverId){let H=`preview_chat_${a.receiverId}`;y.chats.find(Z=>Z._id===H)&&B.setState(Z=>({chats:Z.chats.filter(p=>p._id!==H)}));}if(O)x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId});else {let H=setInterval(()=>{B.getState().chats.find(Z=>Z._id===a.chatId)&&(clearInterval(H),x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId}));},100);setTimeout(()=>clearInterval(H),3e3);}let u=new URL(window.location.href),w=false;u.searchParams.has("targetCompanyId")&&(u.searchParams.delete("targetCompanyId"),w=true),(w||!u.searchParams.has("chatId"))&&(u.searchParams.set("chatId",a.chatId),window.history.replaceState({},document.title,u.toString()));},[x,e]),l=react.useCallback(a=>{S(a);let y=new URL(window.location.href);y.searchParams.has("targetCompanyId")&&(y.searchParams.delete("targetCompanyId"),true);let u=`preview_chat_${a.receiverId}`;y.searchParams.set("chatId",u),window.history.replaceState({},document.title,y.toString());},[S]),I=react.useCallback(a=>{M(a.chatId,a.isBlockedByMe,a.isBlockedByTarget);},[M]);return react.useEffect(()=>(e.connected||(e.connect(),c(e)),e.on("USER_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,true);}),e.on("USER_FINISH_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,false);}),e.on("NEW_MESSAGE",D),e.on("CHAT_MESSAGES",J),e.on("ACCOUNT_LIST",G),e.on("CHAT_LIST",U),e.on("ACCOUNT_SWITCHED",g),e.on("ERROR_OCCURED",j),e.on("OPEN_CHAT",ne),e.on("PREVIEW_CHAT",l),e.on("BLOCK_STATUS_UPDATED",I),e.on("connect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"online");}),e.on("disconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"disconnected");}),e.on("reconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"reconnecting");}),()=>{e.off("NEW_MESSAGE",D),e.off("CHAT_MESSAGES",J),e.off("ACCOUNT_LIST",G),e.off("CHAT_LIST",U),e.off("ACCOUNT_SWITCHED",g),e.off("ERROR_OCCURED",j),e.off("USER_TYPING"),e.off("USER_FINISH_TYPING"),e.off("OPEN_CHAT",ne),e.off("PREVIEW_CHAT",l),e.off("BLOCK_STATUS_UPDATED",I),e?.off("connect"),e?.off("disconnect"),e?.off("reconnect");}),[e,c,D,J,G,U,g,j,ne,l,I,C,F]),e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:t}):null},at=gr;var yr=()=>jsxRuntime.jsx(material.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",background:"#E3E3E3",borderRadius:"16px",height:"100vh"},children:jsxRuntime.jsx(reactLottiePlayer.Player,{src:"/lottie/waiting.json",autoplay:true,loop:true,style:{width:"5rem",height:"5rem"}})}),st=yr;var ct={challenge:"challenge"};var Ir=async t=>(await ce.post("/authentication/challenge",t)).data,dt=()=>reactQuery.useMutation({mutationFn:Ir,mutationKey:[ct.challenge]});var vr=({children:t})=>{let[o,n]=react.useState(true),[r,c]=react.useState(false),{mutate:e}=dt(),s=()=>{fe.setState({token:""}),Y.setState({socket:null}),B.setState({accounts:[],chats:[],statusTooltip:true});};return react.useEffect(()=>{s();let m=window.location.search,h=new URLSearchParams(m).get("targetCompanyId");e(h?{targetCompanyId:h}:{},{onSuccess:d=>{d.data?n(false):c(true);},onError:d=>{c(true);}});},[]),r?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Error"}):o?jsxRuntime.jsx(st,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})},mt=vr;var pt=new reactQuery.QueryClient({});var Pr=()=>{let t=B(U=>U.getCurrentChat()),o=B(U=>U.setCurrentChat),{setStatusTooltip:n,blockUser:r,unblockUser:c}=B(),e=Y(U=>U.socket),[s,m]=react.useState(null),[f,h]=react.useState(false),[d,i]=react.useState(false),x=()=>{if(o(""),n(true),window.history){let U=new URL(window.location.href);U.searchParams.delete("chatId"),window.history.pushState({},"",U.toString());}},S=U=>{m(U.currentTarget);},C=()=>{m(null);},F=()=>{C(),h(true);},M=()=>{C(),i(true);},E=()=>{h(false);},b=()=>{i(false);},k=()=>{t&&e&&(e.emit("USER_BLOCK",{accountId:t.receiverId}),r(t._id)),h(false);},A=()=>{t&&e&&(e.emit("USER_UNBLOCK",{accountId:t.receiverId}),c(t._id)),i(false);};if(!t)return jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,width:"100%",children:[jsxRuntime.jsx(material.Skeleton,{variant:"circular",width:48,height:48}),jsxRuntime.jsxs(material.Stack,{flex:1,spacing:.5,children:[jsxRuntime.jsx(material.Skeleton,{variant:"text",width:"40%",height:16}),jsxRuntime.jsx(material.Skeleton,{variant:"text",width:"20%",height:12})]})]});let T=t?.title?.trim()||"\u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u062C\u062F\u06CC\u062F",D=t?.isBot===true?"":t?.status==="online"?"\u0622\u0646\u0644\u0627\u06CC\u0646":t?.lastSeen?`\u0622\u062E\u0631\u06CC\u0646 \u0628\u0627\u0632\u062F\u06CC\u062F : ${de(new Date(t.lastSeen).toISOString())}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(material.Stack,{alignItems:"center",justifyContent:"flex-start",flexDirection:"row",width:"100%",children:[jsxRuntime.jsx(material.Stack,{display:{xs:"flex",md:"none"},children:jsxRuntime.jsx(material.IconButton,{sx:{color:"#1B1B1B"},onClick:x,children:jsxRuntime.jsx(iconsMaterial.ArrowForward,{})})}),t?.avatar?jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px",objectFit:"cover"},alt:T,src:t.avatar}):jsxRuntime.jsx(material.Avatar,{sx:{width:48,height:48,bgcolor:"#0058CB",fontWeight:600},children:T.charAt(0)||"\u061F"}),jsxRuntime.jsxs(material.Stack,{marginLeft:"0.5rem",flex:1,children:[jsxRuntime.jsx(material.Typography,{variant:"body1",color:"#1B1B1B",children:T}),D&&jsxRuntime.jsx(material.Typography,{variant:"body2",color:t?.status==="online"?"#006D3F":"textSecondary",children:D})]}),jsxRuntime.jsx(material.Stack,{flex:1,alignItems:"flex-end",children:jsxRuntime.jsx(material.IconButton,{sx:{color:"#1B1B1B"},onClick:S,children:jsxRuntime.jsx(iconsMaterial.MoreVert,{})})})]}),jsxRuntime.jsx(material.Menu,{anchorEl:s,open:!!s,onClose:C,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:t?.isBlockedByMe?jsxRuntime.jsxs(material.MenuItem,{onClick:M,children:[jsxRuntime.jsx(material.ListItemIcon,{sx:{color:"green"},children:jsxRuntime.jsx(iconsMaterial.BlockOutlined,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{primary:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A",sx:{color:"green"}})]}):jsxRuntime.jsxs(material.MenuItem,{onClick:F,children:[jsxRuntime.jsx(material.ListItemIcon,{sx:{color:"red"},children:jsxRuntime.jsx(iconsMaterial.BlockOutlined,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{primary:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646",sx:{color:"red"}})]})}),jsxRuntime.jsxs(material.Dialog,{open:f,onClose:E,maxWidth:"xs",PaperProps:{sx:{borderRadius:"16px"}},"aria-labelledby":"block-dialog-title",children:[jsxRuntime.jsxs(material.DialogTitle,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px"},children:[jsxRuntime.jsx(material.Typography,{variant:"h6",children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"}),jsxRuntime.jsx(material.IconButton,{onClick:E,children:jsxRuntime.jsx(iconsMaterial.Close,{})})]}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Typography,{variant:"body1",gutterBottom:true,children:["\u062F\u0631\u0635\u0648\u0631\u062A \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646\u060C \u06A9\u0627\u0631\u0628\u0631 \u0645\u0648\u0631\u062F\u0646\u0638\u0631 \u0646\u0645\u06CC\u200C\u062A\u0648\u0627\u0646\u062F \u0628\u0647 \u0634\u0645\u0627 \u067E\u06CC\u0627\u0645 \u0628\u062F\u0647\u062F. \u0622\u06CC\u0627 \u0627\u0632 \u0627\u06CC\u0646 \u06A9\u0627\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"," "]})}),jsxRuntime.jsxs(material.DialogActions,{sx:{gap:"1rem"},children:[jsxRuntime.jsx(material.Button,{onClick:E,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsxRuntime.jsx(material.Button,{onClick:k,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem",background:"#BD1300",color:"#fff","&:hover":{background:"#BD1300",color:"#fff"}},children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"})]})]}),jsxRuntime.jsxs(material.Dialog,{open:d,onClose:b,maxWidth:"xs","aria-labelledby":"unblock-dialog-title",PaperProps:{sx:{borderRadius:"16px"}},children:[jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsx(material.Typography,{variant:"body1",gutterBottom:true,children:"\u0622\u06CC\u0627 \u0627\u0632 \u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A \u0627\u06CC\u0646 \u06A9\u0627\u0631\u0628\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:b,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsxRuntime.jsx(material.Button,{onClick:A,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]})]})]})},bt=Pr;var Or=({date:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",marginY:"16px"},children:[jsxRuntime.jsx(material.Divider,{sx:{flexGrow:1}}),jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{marginX:"8px",padding:"0.25rem 0.75rem",background:"#F4F4F4",borderRadius:"1rem"},children:t}),jsxRuntime.jsx(material.Divider,{sx:{flexGrow:1}})]}),wt=react.memo(Or);var Yr=({attachment:t,isMe:o})=>{let[n,r]=react.useState(false),c=t.isProductPreview||t.mimeType==="product/preview",e=t.mimeType?.startsWith("image/")||false,s=t.signedUrl||t.url,m=t.thumbnailSignedUrl||s,f=i=>!i||i<1024?(i||0)+" B":i<1024*1024?(i/1024).toFixed(1)+" KB":(i/(1024*1024)).toFixed(1)+" MB",h=()=>t.mimeType?.startsWith("image/")?jsxRuntime.jsx(iconsMaterial.Image,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("video/")?jsxRuntime.jsx(iconsMaterial.VideoLibrary,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("audio/")?jsxRuntime.jsx(iconsMaterial.AudioFile,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType==="application/pdf"?jsxRuntime.jsx(iconsMaterial.PictureAsPdf,{sx:{width:24,height:24,color:"#1B1B1B"}}):jsxRuntime.jsx(iconsMaterial.AttachmentOutlined,{sx:{width:24,height:24,color:"#1B1B1B"}}),d=()=>{let i=document.createElement("a");i.href=s,i.download=t.originalName,i.target="_blank",document.body.appendChild(i),i.click(),document.body.removeChild(i);};return c?jsxRuntime.jsxs(material.Box,{component:"a",href:t.productUrl||t.url,target:"_blank",rel:"noopener noreferrer",sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"0.75rem",padding:"0.75rem",borderRadius:"0.5rem",border:`1px solid ${o?"rgba(255,255,255,0.2)":"#E0E0E0"}`,background:o?"rgba(255,255,255,0.1)":"#F4F4F4",textDecoration:"none",maxWidth:"350px",cursor:"pointer",transition:"all 0.2s ease","&:hover":{background:o?"rgba(255,255,255,0.15)":"#EEEEEE"}},children:[t.productImage&&jsxRuntime.jsx(material.Box,{component:"img",src:t.productImage,alt:t.productTitle||"Product",sx:{width:60,height:60,borderRadius:"0.375rem",objectFit:"cover",flexShrink:0}}),jsxRuntime.jsx(material.Stack,{flex:1,minWidth:0,children:jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:600,color:o?"white":"#1B1B1B",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"0.25rem"},children:t.productTitle||t.originalName})})]}):e?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(material.Box,{sx:{position:"relative",maxWidth:"300px",cursor:"pointer",borderRadius:"8px",overflow:"hidden"},onClick:()=>r(true),children:[jsxRuntime.jsx(material.Box,{component:"img",src:m,alt:t.originalName,sx:{width:"100%",height:"auto",maxHeight:"300px",objectFit:"cover",display:"block"}}),t.width&&t.height&&jsxRuntime.jsxs(material.Box,{sx:{position:"absolute",bottom:4,right:4,background:"rgba(0,0,0,0.5)",color:"white",padding:"2px 6px",borderRadius:"4px",fontSize:"10px"},children:[t.width," \xD7 ",t.height]})]}),n&&jsxRuntime.jsxs(material.Box,{sx:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.9)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:2},onClick:()=>r(false),children:[jsxRuntime.jsx(material.IconButton,{sx:{position:"absolute",top:16,right:16,color:"white"},onClick:()=>r(false),children:jsxRuntime.jsx(iconsMaterial.Close,{})}),jsxRuntime.jsx(material.IconButton,{sx:{position:"absolute",top:16,left:16,color:"white"},onClick:i=>{i.stopPropagation(),d();},children:jsxRuntime.jsx(iconsMaterial.Download,{})}),jsxRuntime.jsx(material.Box,{component:"img",src:s,alt:t.originalName,sx:{maxWidth:"90%",maxHeight:"90%",objectFit:"contain"},onClick:i=>i.stopPropagation()})]})]}):jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:o?"rgba(255,255,255,0.1)":"#F4F4F4",borderRadius:"0.5rem",padding:"0.75rem",gap:"0.5rem",maxWidth:"300px",cursor:"pointer",border:o?"1px solid rgba(255,255,255,0.2)":"1px solid #E0E0E0"},onClick:d,children:[jsxRuntime.jsx(material.Box,{sx:{width:40,height:40,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:o?"#E3E3E3":"##E3E3E3",color:o?"white":"inherit"},children:h()}),jsxRuntime.jsxs(material.Stack,{flex:1,minWidth:0,children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500,color:o?"white":"inherit"},children:t.originalName}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:o?"rgba(255,255,255,0.7)":"textSecondary"},children:f(t.size)})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:o?"white":"inherit"},children:jsxRuntime.jsx(iconsMaterial.Download,{sx:{width:20,height:20}})})]})},Ge=Yr;var Qr=({content:t,isMe:o,hasOpenGraph:n=false})=>{let r=t.replace(/\n/g,`
34
- `);return jsxRuntime.jsx(material.Box,{sx:{"& p":{margin:0,marginBottom:"0.5em","&:last-child":{marginBottom:0}},"& a":{color:o?"#FFFFFF":"#1976d2",textDecoration:"underline !important","&:hover":{textDecoration:"underline !important"}},"& code":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.2em 0.4em",borderRadius:"3px",fontSize:"0.9em",fontFamily:"monospace"},"& pre":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.75em",borderRadius:"4px",overflow:"auto",margin:"0.5em 0","& code":{backgroundColor:"transparent",padding:0}},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& ul, & ol":{margin:"0.5em 0",paddingLeft:"1.5em"},"& li":{marginBottom:"0.25em"},"& blockquote":{borderLeft:`3px solid ${o?"rgba(255, 255, 255, 0.3)":"rgba(0, 0, 0, 0.2)"}`,paddingLeft:"1em",marginLeft:0,marginRight:0,fontStyle:"italic",opacity:.9},"& h1, & h2, & h3, & h4, & h5, & h6":{margin:"0.5em 0 0.3em 0",fontWeight:600},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& hr":{border:"none",borderTop:`1px solid ${o?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,margin:"0.75em 0"},"& table":{borderCollapse:"collapse",width:"100%",margin:"0.5em 0"},"& th, & td":{border:`1px solid ${o?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,padding:"0.5em",textAlign:"left"},"& th":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",fontWeight:600},direction:"auto"},children:jsxRuntime.jsx(qr__default.default,{remarkPlugins:[Vr__default.default],components:{a:({node:c,...e})=>jsxRuntime.jsx("a",{...e,target:"_blank",rel:"noopener noreferrer"})},children:r})})},kt=react.memo(Qr);var so=({message:t,activeUserId:o,othersAvatar:n})=>{let r=Y(C=>C.socket),c=B(C=>C.getCurrentChat()),e=t.senderId===o,{baseApi:s}=K(),m=material.useTheme(),f=material.useMediaQuery(m.breakpoints.down("sm")),h=n,[d,i]=react.useState(null),[x,S]=react.useState(null);return react.useEffect(()=>{!e&&r&&c?._id&&r?.emit("SEEN_CHAT",{chatId:c._id});},[e,r,c?._id]),react.useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(!M||M.length===0){S(null);return}let E=M[0],b=null;try{let A=new URL(E).searchParams.get("productId");if(A)b=Number(A);else if(E.includes("/product/")){let T=E.match(/\/product\/(\d+)/);T&&(b=Number(T[1]));}}catch{S(null);return}if(!b||Number.isNaN(b)){S(null);return}try{let k=await fetch(`${s}Catalog/Products/${b}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!k.ok)throw new Error("Failed to load product");let A=await k.json(),T=A?.value||A,D=T?.name||T?.titleFa||String(b),G=(T?.images||[]).find(g=>g?.isMain)?.url||T?.images?.[0]?.url,U=`https://rasmio.com/product/${b}`;S({id:`product-${b}`,url:U,thumbnailUrl:G,signedUrl:U,thumbnailSignedUrl:G,mimeType:"product/preview",size:0,originalName:D,isProductPreview:!0,productTitle:D,productImage:G,productUrl:U});}catch(k){console.error("Error fetching product data:",k),S(null);}})(),()=>{S(null);}),[t.content,t.id]),react.useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(M&&M.length>0){let E=M[0];if(E.includes("productId=")||E.includes("/product/")){i(null);return}try{let A=await(await fetch(`${s}v3/OpenGraph/GetOpenGraph?url=${encodeURIComponent(E)}`)).json();A&&(A.title||A.description||A.image)?i({title:A.title,description:A.description,image:A.image,url:E}):i(null);}catch(k){console.error("Error fetching OpenGraph data:",k),i(null);}}else i(null);})(),()=>{i(null);}),[t.content,t.id,s]),jsxRuntime.jsx(material.Box,{display:"flex",justifyContent:e?"flex-start":"flex-end",marginY:f?"16px":"8px",paddingX:"8px",children:jsxRuntime.jsxs(material.Box,{display:"flex",flexDirection:e?"row":"row-reverse",alignItems:"flex-start",maxWidth:f?"100%":"70%",children:[!e&&jsxRuntime.jsx("img",{src:h,alt:e?"You":t.senderName,style:{width:40,height:40,borderRadius:"4px"}}),jsxRuntime.jsxs(material.Box,{display:"flex",flexDirection:"column",alignItems:e?"flex-start":"flex-end",marginX:"8px",children:[jsxRuntime.jsxs(material.Box,{sx:{backgroundColor:e?"#0058CB":"#FFFFFF",color:e?"#FFFFFF":"#000000",padding:"0.75rem 1rem",borderRadius:e?"0 0.5rem 0.5rem 0.5rem":"0.5rem 0 0.5rem 0.5rem",wordBreak:"break-word"},children:[t?.attachments&&t?.attachments?.length>0&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:t?.attachments?.map(C=>jsxRuntime.jsx(Ge,{attachment:C,isMe:e},C.id))}),x&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:jsxRuntime.jsx(Ge,{attachment:x,isMe:e})}),t?.content&&jsxRuntime.jsx(material.Box,{sx:{direction:"auto"},children:jsxRuntime.jsx(kt,{content:t.content,isMe:e,hasOpenGraph:!!d})}),d&&jsxRuntime.jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"0.25rem 0.5rem 0 0.25rem",display:"flex",textDecoration:"underline !important",width:"100%",alignItems:"flex-start",borderRight:"3px solid #C7C7C7",gap:"0.5rem",marginTop:"0.5rem"},children:[d.image&&jsxRuntime.jsx("img",{src:d.image,alt:d.title,style:{width:"3rem",height:"3rem",borderRadius:"4px",marginBottom:1,marginLeft:1}}),jsxRuntime.jsxs(material.Stack,{direction:"column",gap:.5,flex:1,children:[jsxRuntime.jsx(material.Typography,{sx:{fontWeight:"bold",direction:"auto"},children:d.title}),d.description&&jsxRuntime.jsxs(material.Typography,{sx:{display:"block",opacity:.8,direction:"auto"},children:[d.description.substring(0,100),"..."]})]})]})]}),t?.buttons&&t.buttons.length>0&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginTop:"8px",width:"100%"},children:t.buttons.map((C,F)=>jsxRuntime.jsx(material.Button,{variant:"contained",fullWidth:true,href:C.link,target:"_blank",rel:"noopener noreferrer",sx:{textTransform:"none",padding:"8px 16px",fontSize:"0.875rem",fontWeight:500},children:C.text},F))}),jsxRuntime.jsxs(material.Box,{sx:{marginTop:"4px",display:"flex",alignItems:"center",justifyContent:"center",gap:"0.38rem"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"textSecondary",sx:{direction:"auto"},children:t.time}),e&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!t.hasSeen&&jsxRuntime.jsx(iconsMaterial.Check,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.hasSeen&&jsxRuntime.jsx(iconsMaterial.DoneAll,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.status==="sending"&&jsxRuntime.jsx(iconsMaterial.AccessTime,{style:{color:"#FFA500",width:"1rem",height:"1rem"}}),t.status==="failed"&&jsxRuntime.jsx(iconsMaterial.ErrorOutline,{style:{color:"#FF0000",width:"1rem",height:"1rem"}})]})]})]})]})})},Bt=react.memo(so);var _t=t=>{if(!t)return "";let o=t.trim(),n=new Date;if(n.setHours(0,0,0,0),o==="\u0627\u0645\u0631\u0648\u0632"||o.toLowerCase()==="today")return n.toDateString();if(o==="\u062F\u06CC\u0631\u0648\u0632"||o.toLowerCase()==="yesterday"){let c=new Date(n);return c.setDate(c.getDate()-1),c.toDateString()}let r=new Date(o);return Number.isNaN(r.getTime())?o:(r.setHours(0,0,0,0),r.toDateString())},ho=(t,o)=>t?o?_t(t.date)!==_t(o.date):true:false,go=({messagesEndRef:t,productAttachment:o})=>{let{currentChat:n}=B(b=>({currentChat:b.getCurrentChat()})),r=B.getState().getActiveAccount(),[c,e]=react.useState(false),[s,m]=react.useState(false),f=react.useRef(null),h=react.useRef(n?.messages.length??0),d=n?.messages??[],i=d.length,x=i>0?d[i-1]:void 0,S=reactVirtual.useVirtualizer({count:i,getScrollElement:()=>f.current,estimateSize:()=>80,overscan:5}),C=react.useCallback((b="smooth")=>{let k=f.current;k&&(k.scrollTo({top:k.scrollHeight,behavior:b}),e(false),m(false));},[]),F=react.useCallback(()=>{let b=f.current;if(!b)return;let{scrollTop:k,scrollHeight:A,clientHeight:T}=b,D=A-(k+T)<=50;m(!D),D&&e(false);},[]);react.useEffect(()=>{let b=h.current;if(i===0){h.current=0;return}if(!f.current){h.current=i;return}if(i>b){let k=f.current,{scrollTop:A,scrollHeight:T,clientHeight:D}=k;T-(A+D)<=50||x?.senderId===r?._id?C("smooth"):e(true);}else i<b&&C("auto");h.current=i;},[i,x?.id,x?.senderId,r?._id,C]),react.useEffect(()=>{e(false),m(false),h.current=n?.messages.length??0,C("auto");},[n?._id,C]);let M=i>0,E=S.getVirtualItems();return jsxRuntime.jsxs(material.Box,{position:"relative",flex:1,children:[jsxRuntime.jsxs(material.Box,{ref:f,onScroll:F,sx:{position:"relative",height:"100%",overflowY:"auto",padding:{xs:"1rem 0.75rem",md:"1.5rem"}},children:[M?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(material.Box,{sx:{height:`${S.getTotalSize()}px`,position:"relative"},children:E.map(b=>{let k=d[b.index],A=b.index>0?d[b.index-1]:void 0,T=ho(k,A);return jsxRuntime.jsxs(material.Box,{ref:S.measureElement,"data-index":b.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${b.start}px)`},children:[T&&k?.date&&jsxRuntime.jsx(wt,{date:k.date}),k&&jsxRuntime.jsx(Bt,{message:k,activeUserId:r?._id,activeUserAvatar:r?.avatar,othersAvatar:n?.avatar})]},k?.id??b.key)})})}):jsxRuntime.jsx(material.Stack,{justifyContent:"center",alignItems:"center",sx:{minHeight:"100%",textAlign:"center",color:"#5E5E5E",gap:"1rem",padding:"1rem"},children:jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.Typography,{variant:"body1",children:"\u0647\u0646\u0648\u0632 \u067E\u06CC\u0627\u0645\u06CC \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647 \u0627\u0633\u062A."}),jsxRuntime.jsx(material.Typography,{variant:"body2",children:"\u0627\u0648\u0644\u06CC\u0646 \u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06A9\u0646\u06CC\u062F."})]})}),jsxRuntime.jsx("div",{ref:t})]}),c&&s&&jsxRuntime.jsxs(material.Button,{variant:"contained",onClick:()=>C("smooth"),sx:{position:"fixed",bottom:{xs:"126px",sm:"100px"},left:"50%",transform:"translateX(-50%)",backgroundColor:"#D9E2FF",color:"#001945",borderRadius:"3rem",boxShadow:"0 2px 8px rgba(0,0,0,0.1)","&:hover":{backgroundColor:"#BBDEFB"},zIndex:1e3,direction:"rtl",gap:"4px",padding:{xs:"8px 16px",sm:"10px 20px"},fontSize:{xs:"0.875rem",sm:"1rem"},whiteSpace:"nowrap",minWidth:{xs:"auto",sm:"200px"}},children:["\u067E\u06CC\u0627\u0645 \u062C\u062F\u06CC\u062F \u062F\u0627\u0631\u06CC\u062F",jsxRuntime.jsx(iconsMaterial.ArrowDownwardOutlined,{sx:{fontSize:{xs:"1.2rem",sm:"1.5rem"}}})]})]})},Ft=go;var Dt={uploadFile:"/uploads/upload"};var xo=async t=>{let o=new FormData;return o.append("file",t.file),(await ce.post(Dt.uploadFile,o,{headers:{"Content-Type":"multipart/form-data"}})).data},Ut=()=>reactQuery.useMutation({mutationFn:xo});var Ao=({attachment:t,onRemove:o,showPreview:n=true})=>{let r=t instanceof File,c=r?t.type:t.mimeType,e=r?t.name:t.originalName,s=t.size,m=r?void 0:t.signedUrl||t.url,f=r?void 0:t.thumbnailSignedUrl||t.signedUrl||t.url,h=S=>S<1024?S+" B":S<1024*1024?(S/1024).toFixed(1)+" KB":(S/(1024*1024)).toFixed(1)+" MB",d=()=>c.startsWith("image/")?jsxRuntime.jsx(iconsMaterial.Image,{sx:{width:24,height:24}}):c.startsWith("video/")?jsxRuntime.jsx(iconsMaterial.VideoLibrary,{sx:{width:24,height:24}}):c.startsWith("audio/")?jsxRuntime.jsx(iconsMaterial.AudioFile,{sx:{width:24,height:24}}):jsxRuntime.jsx(iconsMaterial.InsertDriveFile,{sx:{width:24,height:24}}),i=r?URL.createObjectURL(t):f||m;c.startsWith("image/")&&n&&i;return jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",gap:"0.5rem",overflow:"hidden",border:"1px solid #E0E0E0"},children:[jsxRuntime.jsx(material.Box,{sx:{width:48,height:48,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#E0E0E0"},children:d()}),jsxRuntime.jsxs(material.Stack,{flex:1,minWidth:0,children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500},children:e}),jsxRuntime.jsx(material.Typography,{variant:"caption",color:"textSecondary",children:h(s)})]}),o&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:o,sx:{padding:"4px"},children:jsxRuntime.jsx(iconsMaterial.Close,{sx:{width:20,height:20}})})]})},Ke=Ao;var Fo=({onBack:t})=>{let o=react.useRef(null),n=react.useRef(null),[r,c]=react.useState(""),[e,s]=react.useState(null),[m,f]=react.useState([]),[h,d]=react.useState(null),[i,x]=react.useState(null),S=20*1024*1024,C=Ut(),F=react.useRef(null),M=react.useRef(),E=react.useRef(false),{accounts:b,getActiveAccount:k,getCurrentChat:A,addMessageToChat:T,updateMessageInChat:D,setMessagesForChat:G,chats:U}=B(p=>({accounts:p.accounts,getActiveAccount:p.getActiveAccount,getCurrentChat:p.getCurrentChat,addMessageToChat:p.addMessageToChat,updateMessageInChat:p.updateMessageInChat,setMessagesForChat:p.setMessagesForChat,chats:p.chats})),g=A(),j=k(),J=j?._id||"",ne=j?.avatar,l=Y(p=>p.socket),I=react.useMemo(()=>g?g.canSendMessages===false||g.isBot===true:false,[g]),a=react.useMemo(()=>I?g?.isBot?"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F":g?.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":"",[g?.composerHint,g?.isBot,I]);react.useEffect(()=>{g&&o.current&&!I&&o.current.focus();},[g,I]),react.useEffect(()=>{c(""),f([]),s(null),d(null),new URL(window.location.href).searchParams.has("productId")||x(null);},[g?._id]),react.useEffect(()=>{if(l)return l.on("CHAT_SEEN",({chatId:p})=>{g&&g._id===p&&G(p,g.messages.map(L=>({...L,hasSeen:true})));}),()=>{l.off("CHAT_SEEN");}},[l,g,G]);let y=react.useCallback(p=>{!l||!g?._id||!g?.receiverId||E.current!==p&&(E.current=p,l.emit(p?"START_TYPING":"FINISH_TYPING",{targetId:g.receiverId}));},[l,g]),O=react.useCallback(p=>{if(I){me__default.default.error(a);return}let L=p.target.value;c(L),M.current&&clearTimeout(M.current),L.length>0&&y(true),M.current=setTimeout(()=>{y(false);},1e3);},[y,I,a]);react.useEffect(()=>()=>{M.current&&clearTimeout(M.current),y(false);},[y,g?._id]),react.useEffect(()=>{if(!g?._id){x(null);return}let L=new URL(window.location.href).searchParams.get("productId");if(!L){x(null);return}let z=Number(L);if(!z||Number.isNaN(z)){x(null);return}let P=K().baseApi;(async()=>{try{let ge=await fetch(`${P}Catalog/Products/${z}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!ge.ok)throw new Error("Failed to load product");let Re=await ge.json(),$=Re?.value||Re,Jt=$?.name||$?.titleFa||String(z),Qt=($?.images||[]).find(er=>er?.isMain)?.url||$?.images?.[0]?.url,Zt=`https://rasmio.com/product/${z}`;x({id:z,title:Jt,image:Qt,url:Zt});}catch(ge){console.error("Error fetching product attachment:",ge),x({id:z,title:String(z),image:void 0,url:`https://rasmio.com/product/${z}`});}})();},[g?._id]);let u=react.useCallback(async p=>{if(I){me__default.default.error(a),p.target&&(p.target.value="");return}let L=p.target.files?.[0];if(L){if(d(null),L.size>S){d(`\u062D\u062C\u0645 \u0641\u0627\u06CC\u0644 \u0646\u0628\u0627\u06CC\u062F \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 ${S/(1024*1024)} \u0645\u06AF\u0627\u0628\u0627\u06CC\u062A \u0628\u0627\u0634\u062F`);return}s(L);try{let P=(await C.mutateAsync({file:L}))?.data?.attachments;P&&P.length>0?(f(P),s(null)):(d("\u067E\u0627\u0633\u062E \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0632 \u0633\u0631\u0648\u0631"),s(null));}catch{d("\u062E\u0637\u0627 \u062F\u0631 \u0622\u067E\u0644\u0648\u062F \u0641\u0627\u06CC\u0644. \u0644\u0637\u0641\u0627 \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F."),s(null);}p.target&&(p.target.value="");}},[C,S,I,a]),w=react.useCallback(()=>{s(null),f([]),d(null);},[]),H=react.useCallback(()=>{if(I){me__default.default.error(a);return}n.current?.click();},[I,a]),q=react.useCallback(()=>{if(I){me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.");return}let p=r.trim(),L=p.length>0||m.length>0,z=i?.url?p?`${p}
35
- ${i.url}`:`${i.url}`:p;if(L&&j&&l&&g){y(false),M.current&&clearTimeout(M.current);let P=`temp-${Date.now()}`,he={id:P,senderId:J,senderName:"You",content:z,time:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:"\u0627\u0645\u0631\u0648\u0632",createdAt:Date.now(),status:"sending",avatar:ne||""},ge=m.length>0,Re=m.map($=>$.id);if(T(g?._id,he),c(""),f([]),d(null),i){x(null);let $=new URL(window.location.href);$.searchParams.delete("productId"),window.history.replaceState({},"",$.toString());}ge?l.emit("SEND_ATTACHMENT",{targetId:g?.receiverId,text:p||void 0,attachments:Re},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});}):l.emit("SEND_MESSAGE",{targetId:g?.receiverId,content:z,isChatId:g?.type==="Broadcast"},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});});}},[r,j,l,J,T,D,g,y,m,i,I,a]),Z=react.useCallback(p=>{if(I){me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."),p.preventDefault();return}p.key==="Enter"&&!p.shiftKey&&(q(),p.preventDefault());},[q,I,a]);return g&&jsxRuntime.jsxs(material.Stack,{flexDirection:"column",bgcolor:"#E3E3E3",borderRadius:{xs:0,md:2},position:"relative",flex:1,children:[jsxRuntime.jsx(material.Stack,{bgcolor:"#F4F4F4",borderBottom:"1px solid #ccc",px:2,flexBasis:"64px",sx:{borderTopRightRadius:{md:"0.75rem"}},justifyContent:"center",alignItems:"flex-start",boxSizing:"content-box",children:jsxRuntime.jsx(bt,{onBack:t})}),jsxRuntime.jsx(material.Stack,{flex:"1 0 0",position:"relative",overflow:"auto",children:jsxRuntime.jsx(Ft,{messagesEndRef:F,productAttachment:i})}),jsxRuntime.jsxs(material.Stack,{sx:{padding:"16px"},position:"relative",onDragOver:p=>{I&&(p.preventDefault(),p.stopPropagation(),me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},onDrop:p=>{I&&(p.preventDefault(),p.stopPropagation(),me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},children:[jsxRuntime.jsxs(material.Stack,{children:[i&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",marginBottom:"8px",width:"100%",gap:"1rem",overflow:"hidden"},children:[i.image&&jsxRuntime.jsx("img",{src:i.image,alt:i.title||"product",style:{width:48,height:48,borderRadius:4,objectFit:"contain",background:"#F4F4F4"}}),jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i.title||i.id}),jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>{x(null);let p=new URL(window.location.href);p.searchParams.delete("productId"),window.history.replaceState({},"",p.toString());},children:jsxRuntime.jsx("span",{style:{fontSize:20,lineHeight:1},children:"\xD7"})})]}),(e||m.length>0)&&jsxRuntime.jsxs(material.Stack,{sx:{marginBottom:"8px",maxWidth:"100%",width:{xs:"91%",md:"100%"}},children:[e&&jsxRuntime.jsx(Ke,{attachment:e,onRemove:w}),m.map(p=>jsxRuntime.jsx(Ke,{attachment:p,onRemove:w},p.id))]}),h&&jsxRuntime.jsx(material.Alert,{severity:"error",onClose:()=>d(null),sx:{marginBottom:"8px"},children:h})]}),g?.isBlockedByMe?jsxRuntime.jsxs(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px"},direction:"row",justifyContent:"center",alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0634\u0645\u0627 \u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0631\u0627 \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0647\u200C\u0627\u06CC\u062F"}),jsxRuntime.jsx(material.Button,{variant:"outlined",onClick:()=>{l&&g&&(l.emit("USER_UNBLOCK",{accountId:g.receiverId}),B.getState().unblockUser(g._id));},sx:{borderColor:"#777",color:"#0058CB"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]}):g?.isBlockedByTarget?jsxRuntime.jsx(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center"},children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0627\u0632 \u0637\u0631\u0641 \u06A9\u0627\u0631\u0628\u0631 \u0645\u0642\u0627\u0628\u0644 \u0645\u0633\u062F\u0648\u062F \u0634\u062F\u0647 \u0627\u0633\u062A"})}):I?jsxRuntime.jsxs(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px",flexDirection:"row"},justifyContent:"center",alignItems:"center",children:[jsxRuntime.jsx(iconsMaterial.NotificationsActive,{sx:{color:"#FF9800"}}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",children:a||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."})]}):jsxRuntime.jsx(material.TextField,{fullWidth:true,placeholder:"\u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u06CC\u0646\u062C\u0627 \u0628\u0646\u0648\u06CC\u0633\u06CC\u062F",value:r,multiline:true,maxRows:4,inputRef:o,onChange:O,onKeyDown:Z,sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",fontFamily:"RASMIO","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"},"& textarea":{fontFamily:"RASMIO",overflowY:"auto",maxHeight:"96px",resize:"none",lineHeight:"24px",paddingRight:"40px",paddingLeft:"40px","&::-webkit-scrollbar":{width:"8px"},"&::-webkit-scrollbar-track":{background:"#f1f1f1",borderRadius:"4px"},"&::-webkit-scrollbar-thumb":{background:"#888",borderRadius:"4px"},"&::-webkit-scrollbar-thumb:hover":{background:"#555"}},"& textarea::placeholder":{fontFamily:"RASMIO"}},InputProps:{endAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"end",children:r.length>0||m.length>0||C.isLoading?jsxRuntime.jsx(material.IconButton,{onClick:q,disabled:C.isLoading||m.length===0&&r.trim().length===0,children:jsxRuntime.jsx(iconsMaterial.Send,{sx:{transform:"rotate(180deg)",color:C.isLoading||m.length===0&&r.trim().length===0?"#999":"#0058CB"}})}):jsxRuntime.jsx(material.IconButton,{onClick:H,children:jsxRuntime.jsx(iconsMaterial.AttachFile,{sx:{color:"#777"}})})})}}),jsxRuntime.jsx("input",{ref:n,type:"file",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",style:{display:"none"},onChange:u})]}),jsxRuntime.jsx("div",{ref:F})]})},zt=Fo;var Wt=(t,o)=>react.useCallback(r=>{let c=o();r!==c?._id&&t?.emit("USER_JOINED",{accountId:r});},[t,o]);var Gt=(t,o,n,r)=>react.useCallback(e=>{t&&t.emit("GET_MESSAGES",{chatId:e}),o(e),window.history&&window.history.pushState({},"",`?chatId=${e}`),n&&n(),r&&r(false);},[t,o,n,r]);var $t=(t,o,n)=>react.useMemo(()=>{let r=K(),c=t||[];if(r.companyId){if(!n)return [];let e=Number(r.companyId);if(Number(n.rasmioId)!==e)return []}if(o){let e=String(o).toLowerCase();c.length;c=c.filter(m=>String(m?.title||"").toLowerCase().includes(e));}return c},[t,o,n]);var qt=material.styled(({className:t,...o})=>jsxRuntime.jsx(material.Tooltip,{...o,classes:{popper:t}}))(({theme:t})=>({"& .MuiTooltip-tooltip":{borderRadius:"0.25rem",background:"#1B1B1B",display:"flex",minHeight:"1.5rem",padding:"0.25rem 0.5rem",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"0.625rem",color:"#fff",fontSize:"0.875rem"}})),en=({onChatSelect:t})=>{let[o,n]=react.useState(null),[r,c]=react.useState(""),s=!!K().companyId,{accounts:m,chats:f,getActiveAccount:h,setCurrentChat:d,isMy:i}=B(l=>({accounts:l.accounts,chats:l.chats,getActiveAccount:l.getActiveAccount,setCurrentChat:l.setCurrentChat,isMy:l.isMy})),{statusTooltip:x,setStatusTooltip:S}=B(),C=Y(l=>l.socket),F=material.useTheme(),M=material.useMediaQuery(F.breakpoints.down("sm")),E=m.some(l=>l?.unreadChatsCount>0),b=Wt(C,h),k=Gt(C,d,t,S),A=m.find(l=>l.isActive),T=$t(f,r,A),D=react.useRef(null),G=reactVirtual.useVirtualizer({count:T?.length||0,getScrollElement:()=>D.current,estimateSize:react.useCallback(()=>80,[]),overscan:10}),U=react.useRef(null),g=l=>{if(!(s||m.length<=1||i))if(m.length>1&&!i)n(U.current);else return},j=()=>{n(null);},J=l=>{switch(l){case "online":return "#006D3F";case "disconnected":return "#BD1300";case "reconnecting":return "#ff9800";default:return "#006D3F"}},ne=l=>{switch(l){case "online":return "\u0622\u0646\u0644\u0627\u06CC\u0646";case "disconnected":return "\u0622\u0641\u0644\u0627\u06CC\u0646";case "reconnecting":return "\u062F\u0631 \u062D\u0627\u0644 \u0627\u062A\u0635\u0627\u0644";default:return "\u0622\u0646\u0644\u0627\u06CC\u0646"}};return jsxRuntime.jsxs(material.Stack,{sx:{width:M?"100%":"20rem",display:"flex",flexDirection:"column",borderRight:M?"none":"1px solid #ccc",height:"100%",background:"#F4F4F4",borderTopLeftRadius:M?0:"16px",borderBottomLeftRadius:M?0:"16px"},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 0.75rem",width:"100%",gap:"0.5rem",flexBasis:"64px"},children:[M?x&&jsxRuntime.jsx(qt,{title:ne(h()?.status),children:jsxRuntime.jsx(material.Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsxRuntime.jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}):jsxRuntime.jsx(qt,{title:ne(h()?.status),children:jsxRuntime.jsx(material.Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsxRuntime.jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}),m.length>1&&!i&&!s&&(E?jsxRuntime.jsx(material.Badge,{variant:"dot",color:"error",sx:{ml:1,"& .MuiBadge-badge":{right:"auto",left:0,top:"20%",transform:"translateY(-50%)"}},children:jsxRuntime.jsx(material.Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer"},onClick:g,children:jsxRuntime.jsx(iconsMaterial.ExpandMore,{})})}):jsxRuntime.jsx(material.Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer",marginInlineEnd:"0.75rem",marginInlineStart:"0.25rem"},onClick:g,children:jsxRuntime.jsx(iconsMaterial.ExpandMore,{})})),M?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(material.Drawer,{anchor:"bottom",open:!!o,onClose:j,PaperProps:{sx:{maxHeight:"50%",width:"100%",borderTopLeftRadius:"16px",borderTopRightRadius:"16px",padding:"0.5rem"}},children:[jsxRuntime.jsxs(material.Stack,{flexDirection:"row",alignItems:"center",justifyContent:"space-between",children:[jsxRuntime.jsx(material.Typography,{sx:{fontSize:"1rem",fontWeight:700,padding:"0.5rem 1rem",color:"#1B1B1B"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),jsxRuntime.jsx(material.IconButton,{onClick:j,children:jsxRuntime.jsx(iconsMaterial.CloseOutlined,{style:{color:"#1B1B1B"}})})]}),m.map(l=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondary:l?.__t==="User"?"":l?.rasmioId}),(l?.unreadChatsCount??0)>0&&jsxRuntime.jsx(material.Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{ml:1,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]})}):jsxRuntime.jsxs(material.Menu,{anchorEl:o,open:!!o,onClose:j,PaperProps:{sx:{boxShadow:"0px 4px 24px 0px rgba(0, 0, 0, 0.12)",width:"20rem",marginInlineEnd:"4.6rem",marginTop:"1.2rem",padding:"1rem 1rem",borderRadius:"0.75rem"}},anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[jsxRuntime.jsx(material.Typography,{variant:"body1",sx:{fontSize:"0.875rem",fontWeight:400,color:"#5E5E5E"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),m.map(l=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem 0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600,marginInlineStart:"0.5rem"},secondary:l?.__t==="User"?"":l?.rasmioId,secondaryTypographyProps:{marginInlineStart:"0.5rem"}}),(l?.unreadChatsCount??0)>0&&jsxRuntime.jsx(material.Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{mt:2,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]}),jsxRuntime.jsx(material.TextField,{value:r,onChange:l=>c(l.target.value),variant:"outlined",size:"small",placeholder:"\u062C\u0633\u062A\u062C\u0648",sx:{flexGrow:1,borderRadius:"0.5rem",background:"#F4F4F4",border:"0.5px solid #777","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},InputProps:{endAdornment:r&&jsxRuntime.jsx(iconsMaterial.Close,{sx:{cursor:"pointer",width:"1.125rem",height:"1.125rem",marginInlineEnd:"0.75rem"},onClick:()=>c("")})}})]}),jsxRuntime.jsx(material.Divider,{sx:{marginBottom:"0.75rem"},orientation:"horizontal",flexItem:true}),jsxRuntime.jsxs(material.Typography,{sx:{color:"#5E5E5E",fontSize:"0.875rem",fontWeight:"400",padding:"0.75rem"},children:["\u06AF\u0641\u062A \u0648 \u06AF\u0648\u0647\u0627\u06CC ",h()?.displayName]}),jsxRuntime.jsxs(material.Stack,{ref:D,sx:{height:`${G.getTotalSize()}px`,flex:1,overflowY:"auto",scrollbarWidth:"none",width:"100%",position:"relative","&::-webkit-scrollbar":{display:"none"},msOverflowStyle:"none"},children:[f.length<1&&jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"flex-start",alignItems:"center",height:"100%",marginBlockStart:"8rem",width:"100%",fontFamily:"RASMIO",gap:"0.5rem"},children:[jsxRuntime.jsx(iconsMaterial.CommentsDisabledOutlined,{sx:{fontSize:48,color:"#1B1B1B"}}),jsxRuntime.jsx(material.Typography,{color:"#1B1B1B",sx:{mb:2},children:"\u0634\u0645\u0627 \u0647\u06CC\u0686 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0641\u0639\u0627\u0644\u06CC \u0646\u062F\u0627\u0631\u06CC\u062F"})]}),jsxRuntime.jsx(material.Stack,{sx:{width:"100%",position:"relative"},children:G.getVirtualItems().map(l=>{let I=T[l.index];return jsxRuntime.jsx(material.Stack,{"data-index":l.index,ref:G.measureElement,sx:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${l.start}px)`},children:jsxRuntime.jsxs(material.ListItem,{onClick:()=>k(I._id),button:true,sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"0.75rem",gap:"0.25rem",backgroundColor:I?.isActive?"#DADADA":"transparent","&:hover":{backgroundColor:"#e0e0e0"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:I?.title,src:I?.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:I?.title,secondary:I?.isTyping?"\u062F\u0631 \u062D\u0627\u0644 \u0646\u0648\u0634\u062A\u0646 ...":I?.lastMessage?.content||"",primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondaryTypographyProps:{noWrap:true,color:I?.isTyping?"#006D3F":"#555",fontSize:"0.875rem",fontWeight:400},sx:{marginRight:"1rem"}}),jsxRuntime.jsxs(material.Stack,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"1rem",marginLeft:"auto",minWidth:"50px"},children:[I.lastMessage?.createdAt&&jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:"#999",fontSize:"0.75rem"},children:new Date(I.lastMessage.createdAt).toLocaleDateString("fa-IR")===new Date().toLocaleDateString("fa-IR")?new Date(I.lastMessage.createdAt).toLocaleTimeString("fa-IR",{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:"Asia/Tehran"}):de(new Date(I.lastMessage.createdAt).toISOString())}),!I.isActive&&I?.unReadCount>0&&jsxRuntime.jsx(material.Badge,{badgeContent:I.unReadCount,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff",fontSize:"0.75rem",height:"1.25rem",minWidth:"1.25rem"}}})]})]})},l.key)})})]})]})},Vt=en;var nn=react.memo(({token:t,serviceApi:o,socketUrl:n,baseApi:r,companyId:c})=>{react.useEffect(()=>{let d={};o&&(d.serviceApi=o),c&&(d.companyId=c),n&&(d.socketUrl=n),r&&(d.baseApi=r),Object.keys(d).length>0&&Je(d);},[o,n,r,c]);let e=B(d=>d.getCurrentChat()),s=B(d=>d.setCurrentChat),m=B(d=>d.chats),f=B(d=>d.refreshBroadcastPermissions),h=Y(d=>d.socket);return react.useEffect(()=>{let d=new URL(window.location.href),i=d.searchParams.get("chatId");if(!d.searchParams.get("targetCompanyId")&&i&&m.length>0&&h){let S=m.find(C=>C._id===i);S?(!e||e._id!==i)&&(s(i),S.isPreview||h.emit("GET_MESSAGES",{chatId:i})):i.startsWith("preview_chat_")||(d.searchParams.delete("chatId"),window.history.replaceState({},"",d.toString()));}},[m,s,e,h]),react.useEffect(()=>{let d=i=>{if(i.key==="Escape"&&(s(""),window.history)){let x=new URL(window.location.href);x.searchParams.delete("chatId"),window.history.pushState({},"",x.toString());}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),react.useEffect(()=>{f();},[f,e?._id]),jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:pt,children:jsxRuntime.jsx(Ze,{token:t,children:jsxRuntime.jsx(mt,{children:jsxRuntime.jsx(at,{socketUrl:n,children:jsxRuntime.jsxs(material.Grid,{flexDirection:"row",bgcolor:"#E3E3E3",borderRadius:"16px",width:"100%",marginBlockStart:"1rem",flex:1,container:true,position:"relative",sx:{overflow:"hidden",minHeight:"500px"},children:[jsxRuntime.jsx(material.Grid,{item:true,width:{xs:"100%",sm:"unset"},sx:{display:e?{xs:"none",sm:"block"}:"block"},children:jsxRuntime.jsx(Vt,{})}),jsxRuntime.jsx(material.Grid,{item:true,flex:1,position:{xs:"absolute",sm:"relative"},display:e?"flex":"none",sx:{inset:0,zIndex:e?10:-1,visibility:e?"visible":"hidden"},children:jsxRuntime.jsx(zt,{})})]})})})})})},(t,o)=>t.token===o.token&&t.serviceApi===o.serviceApi&&t.socketUrl===o.socketUrl);
33
+ var B=zustand.create((t,r)=>({accounts:[],chats:[],statusTooltip:true,isMy:false,broadcastState:null,addPreviewChat:n=>{let o=`preview_chat_${n.receiverId}`;if(r().chats.find(e=>e._id===o)){r().setCurrentChat(o);return}t(e=>({chats:[{_id:o,avatar:n.avatar,messages:[],isActive:true,unReadCount:0,status:n.status,title:n.displayName,receiverId:n.receiverId,isPreview:true,isBot:false,lastSeen:n.lastActive},...e.chats.map(s=>({...s,isActive:false}))]}));},updateChatStatus:(n,o)=>{t(c=>({accounts:c.accounts.map(e=>e._id===n?{...e,status:o}:e)}));},setActiveAccount:n=>{let{accounts:o}=r();if(!o.find(s=>s._id===n)){console.warn("[setActiveAccount] Account not found:",n);return}let e=o.map(s=>({...s,isActive:s._id===n}));t({accounts:e}),r().refreshBroadcastPermissions();},setAccounts:n=>{t({accounts:n});},setChats:n=>t(()=>{let o=r().getActiveAccount(),c=r().broadcastState,s=r().chats.filter(i=>i.isPreview&&!n.some(x=>x._id===i._id)),f=n.map(i=>{let x=!!(i?.type==="Broadcast"||i?.isDefaultBroadcast),S=i?.isBot===true,F=i?.ownerId||(typeof i?.owner=="object"?i?.owner?._id:void 0)||c?.ownerId||void 0,M=x&&F?F===(o?._id??""):true,E=S?false:x?M:i?.canSendMessages??true,b=i?.composerHint||(S?"\u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u062A\u0648\u0633\u0637 \u0631\u0628\u0627\u062A \u0645\u062F\u06CC\u0631\u06CC\u062A \u0645\u06CC\u200C\u0634\u0648\u062F \u0648 \u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":E?void 0:"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.");return {...i,ownerId:F,isTyping:false,canSendMessages:E,composerHint:b,isBot:S}}).sort((i,x)=>{let S=!!(i.type==="Broadcast"||i.isDefaultBroadcast),C=!!(x.type==="Broadcast"||x.isDefaultBroadcast);return S&&!C?-1:C&&!S?1:0}),h=[...s,...f],d=f.find(i=>i.type==="Broadcast"||i.isDefaultBroadcast);return {chats:h,broadcastState:d?{chatId:d._id,ownerId:d.ownerId,isDefault:!!d.isDefaultBroadcast}:null}}),getActiveAccount:()=>{let{accounts:n}=r();return n.find(o=>o.isActive)},setCurrentChat:n=>{t(o=>({accounts:o.accounts.map(e=>({...e,unreadChatsCount:e.isActive&&e.unreadChatsCount&&e.unreadChatsCount>0?e.unreadChatsCount-1:e.unreadChatsCount})),chats:o.chats.map(e=>({...e,isActive:e._id===n,unReadCount:e._id===n?0:e.unReadCount,messages:e._id===n?e.messages.map(s=>({...s,hasSeen:true})):e.messages}))}));},getCurrentChat:()=>{let{chats:n}=r();return n.find(o=>o.isActive)??null},addMessageToChat:(n,o)=>{t(c=>{let e=c.chats.findIndex(m=>m._id===n),s=[...c.chats];if(e!==-1){let m=s[e];if(m.messages.some(d=>d.id===o.id)){if(o.id.startsWith("temp-")===false&&m.messages.some(i=>i.id.startsWith("temp-"))){let i=m.messages.map(S=>S.id.startsWith("temp-")&&S.content===o.content&&Math.abs(S.createdAt-o.createdAt)<5e3?o:S),x={...m,lastMessage:o,messages:i};return s.splice(e,1),s.unshift(x),{chats:s}}return c}let h={...s[e],lastMessage:o,messages:[...s[e].messages,o]};return s.splice(e,1),s.unshift(h),{chats:s}}else {let m=c.chats.findIndex(f=>f.isPreview&&f.receiverId===o.senderId);if(m!==-1){let f=s[m],h={...f,_id:n,isPreview:false,lastMessage:o,messages:[...f.messages,o]};return s.splice(m,1),s.unshift(h),{chats:s}}else return {chats:[{_id:n,lastMessage:o,messages:[o],avatar:o.avatar,isActive:false,title:o.senderName,receiverId:o.senderId,unReadCount:0,lastSeen:new Date().toISOString()},...c.chats]}}});},updateMessageInChat:(n,o,c)=>{t(e=>{let s=e.chats.findIndex(x=>x._id===n);if(s===-1)return e;let m=[...e.chats],f=m[s],h=f.messages.findIndex(x=>x.id===o);if(h===-1)return e;let d=[...f.messages];d[h]={...d[h],...c};let i={...f,messages:d,lastMessage:h===d.length-1?d[h]:f.lastMessage};return m[s]=i,{chats:m}});},setMessagesForChat:(n,o)=>{t(c=>{let e=c.chats.findIndex(s=>s._id===n);if(e!==-1){let s=[...c.chats];return s[e].messages=o,o.length>0&&(s[e].lastMessage=o[o.length-1]),{chats:s}}else return console.warn(`Chat with ID ${n} not found. Messages not set.`),{}});},setTypingStatus:(n,o)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,isTyping:o}:e)})),setStatusTooltip:n=>t({statusTooltip:n}),blockUser:n=>{t(o=>({chats:o.chats.map(c=>c._id===n?{...c,isBlockedByMe:true}:c)}));},unblockUser:n=>{t(o=>({chats:o.chats.map(c=>c._id===n?{...c,isBlockedByMe:false}:c)}));},updateChatBlockStatus:(n,o,c)=>{t(e=>({chats:e.chats.map(s=>s._id===n?{...s,isBlockedByMe:o,isBlockedByTarget:c}:s)}));},setIsMy:n=>t({isMy:n}),setBroadcastState:n=>t({broadcastState:n}),refreshBroadcastPermissions:()=>{let{broadcastState:n}=r();if(!n)return;let o=r().getActiveAccount();t(c=>({chats:c.chats.map(e=>{if(e._id!==n.chatId)return e;let s=n.ownerId?n.ownerId===(o?._id??""):false;return {...e,canSendMessages:s,composerHint:s?void 0:e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."}})}));},updateChatPermissions:(n,o)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,...o,composerHint:o.canSendMessages===false?o.composerHint||e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":o.composerHint}:e)}))}));var Y=zustand.create(t=>({socket:null,socketConnect:r=>t({socket:r}),socketDisconnect:()=>t({socket:null})}));var fe=zustand.create(t=>({token:"",setToken:r=>t({token:r})}));var no={serviceApi:"https://gwdev.rasmio.com/api/chat/",socketUrl:"wss://devsocket.rasmio.com/chat",baseApi:"https://gwdev.rasmio.com/api/"},ye={...no},Fe=new Set,K=()=>ye,Je=t=>(ye={...ye,...Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0))},Fe.forEach(r=>r(ye)),ye);var Qe=t=>(Fe.add(t),()=>Fe.delete(t));var{serviceApi:io}=K(),ce=ao__default.default.create({adapter:"fetch",baseURL:io,timeout:2e4});Qe(t=>{ce.defaults.baseURL=t.serviceApi;});var co=({children:t,token:r})=>{let n=fe(o=>o.setToken);return react.useEffect(()=>{r&&(n(r),ce.defaults.headers.common.Authorization=`Bearer ${r}`);},[r]),r?t:null},Ze=co;var et=(t,r)=>{let{current:n}=react.useRef(socket_ioClient.io(t,r));return n};be__default.default.extend(mo__default.default);be__default.default.extend(po__default.default);be__default.default.extend(ho__default.default);var de=t=>{let r=be__default.default(t).calendar("jalali").locale("fa"),n=be__default.default().calendar("jalali").locale("fa");return r.isSame(n,"day")?"\u0627\u0645\u0631\u0648\u0632":r.isSame(n.subtract(1,"day"),"day")?"\u062F\u06CC\u0631\u0648\u0632":r.year()===n.year()?r.format("D MMMM"):r.format("D MMMM YYYY")};var fo=({children:t,socketUrl:r})=>{let n=fe(a=>a.token),o=react.useMemo(()=>r||"wss://devsocket.rasmio.com/chat",[r]),{socketConnect:c}=Y(shallow.useShallow(a=>({socketConnect:a.socketConnect}))),e=et(o,{transports:["websocket"],reconnectionAttempts:3,reconnectionDelay:3e3,withCredentials:false,autoConnect:false,upgrade:false,auth:{token:`Bearer ${n}`}}),{setAccounts:s,setChats:m,addMessageToChat:f,setMessagesForChat:h,setActiveAccount:d,currentChat:i,setCurrentChat:x,addPreviewChat:S,accounts:C,updateChatStatus:F,updateChatBlockStatus:M,setIsMy:E,refreshBroadcastPermissions:b,updateChatPermissions:k}=B(shallow.useShallow(a=>({setAccounts:a.setAccounts,setChats:a.setChats,addMessageToChat:a.addMessageToChat,setMessagesForChat:a.setMessagesForChat,setActiveAccount:a.setActiveAccount,currentChat:a.getCurrentChat(),setCurrentChat:a.setCurrentChat,addPreviewChat:a.addPreviewChat,accounts:a.accounts,updateChatStatus:a.updateChatStatus,updateChatBlockStatus:a.updateChatBlockStatus,setIsMy:a.setIsMy,refreshBroadcastPermissions:a.refreshBroadcastPermissions,updateChatPermissions:a.updateChatPermissions}))),A=react.useRef(false),T=react.useRef(new Set);react.useEffect(()=>{let y=K().companyId;if(!y||!e||C.length===0||!e.connected)return;let O=C.find(w=>String(w.rasmioId)===String(y));!O||C.find(w=>w.isActive)?._id===O._id||e.emit("USER_JOINED",{accountId:O._id});},[e,C]);let D=react.useCallback(a=>{let y=B.getState().getActiveAccount(),O={id:a._id,senderId:a.sender._id,senderName:a.sender.displayName,avatar:a.sender.avatar,content:a.content,time:new Date(a.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(a.createdAt),createdAt:new Date(a.createdAt).getTime(),hasSeen:a.hasSeen,attachments:a.attachments?a.attachments.map(u=>({id:u._id||u.id,url:u.url,thumbnailUrl:u.thumbnailUrl,signedUrl:u.signedUrl,thumbnailSignedUrl:u.thumbnailSignedUrl,mimeType:u.mimeType,size:u.size,originalName:u.originalName,sha256:u.sha256,width:u.width,height:u.height,durationSec:u.durationSec})):[],buttons:a.buttons||[]};if(a.sender._id===y?._id){let u=B.getState(),w=u.chats.find(H=>H._id===a.chatId);if(w){let H=w.messages.find(q=>q.id===a._id||q.id.startsWith("temp-")&&q.content===a.content);if(H){u.updateMessageInChat(a.chatId,H.id,O);return}}}f(a.chatId,O);},[f]),G=react.useCallback(a=>{let O=K().companyId,u=new URL(window.location.href),w=a.find(P=>P.__t==="User"),H=u.searchParams.has("cmp"),q=u.searchParams.get("my")==="true",Z=a.find(P=>P.__t==="Company"),p=u.searchParams.get("cmp");E(q);let L=O||p,z=L?a.find(P=>String(P?.rasmioId)===String(L)):void 0;if(L&&z&&!A.current)e.emit("USER_JOINED",{accountId:z._id}),A.current=true,p&&(u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString()));else if(w&&!A.current&&!H&&!q&&!L){e.emit("USER_JOINED",{accountId:w._id}),A.current=true;let P=u.searchParams.get("targetCompanyId");P&&!T.current.has(P)&&(T.current.add(P),e.emit("ACCOUNT_INFO",{id:P}),setTimeout(()=>{let he=new URL(window.location.href);he.searchParams.get("targetCompanyId")===P&&(he.searchParams.delete("targetCompanyId"),window.history.replaceState({},document.title,he.toString()),me__default.default.error("\u0627\u0645\u06A9\u0627\u0646 \u0628\u0627\u0632 \u06A9\u0631\u062F\u0646 \u06AF\u0641\u062A\u06AF\u0648 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F"));},5e3));}else if(!A.current){let P=Z;e.emit("USER_JOINED",{accountId:P?._id}),A.current=true,u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString());}u.searchParams.has("my")&&(u.searchParams.delete("my"),window.history.replaceState({},document.title,u.toString())),s(a);},[e,s,E]),U=react.useCallback(a=>{let y=a.map(w=>({...w,messages:w.messages||[],unReadCount:w.unReadCount||0}));m(y),b();let u=new URL(window.location.href).searchParams.get("chatId");u&&y.find(H=>H._id===u)&&!B.getState().getCurrentChat()&&(x(u),e&&e.emit("GET_MESSAGES",{chatId:u}));},[m,b,x,e]),g=react.useCallback(a=>{d(a);},[d]),j=react.useCallback(a=>{let y=a?.message||a?.payload?.message||a?.payload?.reason||a?.data?.message||"\u062E\u0637\u0627\u06CC \u0646\u0627\u0645\u0634\u062E\u0635 \u0631\u062E \u062F\u0627\u062F\u0647 \u0627\u0633\u062A";me__default.default.error(y);let O=a?.chatId||a?.payload?.chatId||a?.data?.chatId||a?.meta?.chatId;!O||!(a?.code&&["BROADCAST_READ_ONLY","CHAT_PERMISSION_DENIED"].includes(a.code)||y.toLowerCase().includes("broadcast")||y.toLowerCase().includes("\u0627\u062C\u0627\u0632\u0647"))||k(O,{canSendMessages:false,composerHint:y});},[k]),J=react.useCallback(a=>{let O=a.map(u=>({id:u._id,senderId:u.sender._id,senderName:u.sender.displayName,avatar:u.sender.avatar,content:u.content,time:new Date(u.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(u.createdAt),createdAt:new Date(u.createdAt).getTime(),hasSeen:u.hasSeen,attachments:u.attachments?u.attachments.map(w=>({id:w._id||w.id,url:w.url,thumbnailUrl:w.thumbnailUrl,signedUrl:w.signedUrl,thumbnailSignedUrl:w.thumbnailSignedUrl,mimeType:w.mimeType,size:w.size,originalName:w.originalName,sha256:w.sha256,width:w.width,height:w.height,durationSec:w.durationSec})):[],buttons:u.buttons||[]})).sort((u,w)=>u.createdAt-w.createdAt);i&&h(i._id,O);},[i,h]),ne=react.useCallback(a=>{let y=B.getState(),O=y.chats.find(H=>H._id===a.chatId);if(a.receiverId){let H=`preview_chat_${a.receiverId}`;y.chats.find(Z=>Z._id===H)&&B.setState(Z=>({chats:Z.chats.filter(p=>p._id!==H)}));}if(O)x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId});else {let H=setInterval(()=>{B.getState().chats.find(Z=>Z._id===a.chatId)&&(clearInterval(H),x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId}));},100);setTimeout(()=>clearInterval(H),3e3);}let u=new URL(window.location.href),w=false;u.searchParams.has("targetCompanyId")&&(u.searchParams.delete("targetCompanyId"),w=true),(w||!u.searchParams.has("chatId"))&&(u.searchParams.set("chatId",a.chatId),window.history.replaceState({},document.title,u.toString()));},[x,e]),l=react.useCallback(a=>{S(a);let y=new URL(window.location.href);y.searchParams.has("targetCompanyId")&&(y.searchParams.delete("targetCompanyId"),true);let u=`preview_chat_${a.receiverId}`;y.searchParams.set("chatId",u),window.history.replaceState({},document.title,y.toString());},[S]),I=react.useCallback(a=>{M(a.chatId,a.isBlockedByMe,a.isBlockedByTarget);},[M]);return react.useEffect(()=>(e.connected||(e.connect(),c(e)),e.on("USER_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,true);}),e.on("USER_FINISH_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,false);}),e.on("NEW_MESSAGE",D),e.on("CHAT_MESSAGES",J),e.on("ACCOUNT_LIST",G),e.on("CHAT_LIST",U),e.on("ACCOUNT_SWITCHED",g),e.on("ERROR_OCCURED",j),e.on("OPEN_CHAT",ne),e.on("PREVIEW_CHAT",l),e.on("BLOCK_STATUS_UPDATED",I),e.on("connect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"online");}),e.on("disconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"disconnected");}),e.on("reconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"reconnecting");}),()=>{e.off("NEW_MESSAGE",D),e.off("CHAT_MESSAGES",J),e.off("ACCOUNT_LIST",G),e.off("CHAT_LIST",U),e.off("ACCOUNT_SWITCHED",g),e.off("ERROR_OCCURED",j),e.off("USER_TYPING"),e.off("USER_FINISH_TYPING"),e.off("OPEN_CHAT",ne),e.off("PREVIEW_CHAT",l),e.off("BLOCK_STATUS_UPDATED",I),e?.off("connect"),e?.off("disconnect"),e?.off("reconnect");}),[e,c,D,J,G,U,g,j,ne,l,I,C,F]),e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:t}):null},at=fo;var bo=()=>jsxRuntime.jsx(material.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",background:"#E3E3E3",borderRadius:"16px",height:"100vh"},children:jsxRuntime.jsx(reactLottiePlayer.Player,{src:"/lottie/waiting.json",autoplay:true,loop:true,style:{width:"5rem",height:"5rem"}})}),st=bo;var ct={challenge:"challenge"};var wo=async t=>(await ce.post("/authentication/challenge",t)).data,dt=()=>reactQuery.useMutation({mutationFn:wo,mutationKey:[ct.challenge]});var ko=({children:t})=>{let[r,n]=react.useState(true),[o,c]=react.useState(false),{mutate:e}=dt(),s=()=>{fe.setState({token:""}),Y.setState({socket:null}),B.setState({accounts:[],chats:[],statusTooltip:true});};return react.useEffect(()=>{s();let m=window.location.search,h=new URLSearchParams(m).get("targetCompanyId");e(h?{targetCompanyId:h}:{},{onSuccess:d=>{d.data?n(false):c(true);},onError:d=>{c(true);}});},[]),o?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Error"}):r?jsxRuntime.jsx(st,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})},mt=ko;var pt=new reactQuery.QueryClient({});var _o=()=>{let t=B(U=>U.getCurrentChat()),r=B(U=>U.setCurrentChat),{setStatusTooltip:n,blockUser:o,unblockUser:c}=B(),e=Y(U=>U.socket),[s,m]=react.useState(null),[f,h]=react.useState(false),[d,i]=react.useState(false),x=()=>{if(r(""),n(true),window.history){let U=new URL(window.location.href);U.searchParams.delete("chatId"),window.history.pushState({},"",U.toString());}},S=U=>{m(U.currentTarget);},C=()=>{m(null);},F=()=>{C(),h(true);},M=()=>{C(),i(true);},E=()=>{h(false);},b=()=>{i(false);},k=()=>{t&&e&&(e.emit("USER_BLOCK",{accountId:t.receiverId}),o(t._id)),h(false);},A=()=>{t&&e&&(e.emit("USER_UNBLOCK",{accountId:t.receiverId}),c(t._id)),i(false);};if(!t)return jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,width:"100%",children:[jsxRuntime.jsx(material.Skeleton,{variant:"circular",width:48,height:48}),jsxRuntime.jsxs(material.Stack,{flex:1,spacing:.5,children:[jsxRuntime.jsx(material.Skeleton,{variant:"text",width:"40%",height:16}),jsxRuntime.jsx(material.Skeleton,{variant:"text",width:"20%",height:12})]})]});let T=t?.title?.trim()||"\u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u062C\u062F\u06CC\u062F",D=t?.isBot===true?"":t?.status==="online"?"\u0622\u0646\u0644\u0627\u06CC\u0646":t?.lastSeen?`\u0622\u062E\u0631\u06CC\u0646 \u0628\u0627\u0632\u062F\u06CC\u062F : ${de(new Date(t.lastSeen).toISOString())}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(material.Stack,{alignItems:"center",justifyContent:"flex-start",flexDirection:"row",width:"100%",children:[jsxRuntime.jsx(material.Stack,{display:{xs:"flex",md:"none"},children:jsxRuntime.jsx(material.IconButton,{sx:{color:"#1B1B1B"},onClick:x,children:jsxRuntime.jsx(iconsMaterial.ArrowForward,{})})}),t?.avatar?jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px",objectFit:"cover"},alt:T,src:t.avatar}):jsxRuntime.jsx(material.Avatar,{sx:{width:48,height:48,bgcolor:"#0058CB",fontWeight:600},children:T.charAt(0)||"\u061F"}),jsxRuntime.jsxs(material.Stack,{marginLeft:"0.5rem",flex:1,children:[jsxRuntime.jsx(material.Typography,{variant:"body1",color:"#1B1B1B",children:T}),D&&jsxRuntime.jsx(material.Typography,{variant:"body2",color:t?.status==="online"?"#006D3F":"textSecondary",children:D})]}),jsxRuntime.jsx(material.Stack,{flex:1,alignItems:"flex-end",children:jsxRuntime.jsx(material.IconButton,{sx:{color:"#1B1B1B"},onClick:S,children:jsxRuntime.jsx(iconsMaterial.MoreVert,{})})})]}),jsxRuntime.jsx(material.Menu,{anchorEl:s,open:!!s,onClose:C,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:t?.isBlockedByMe?jsxRuntime.jsxs(material.MenuItem,{onClick:M,children:[jsxRuntime.jsx(material.ListItemIcon,{sx:{color:"green"},children:jsxRuntime.jsx(iconsMaterial.BlockOutlined,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{primary:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A",sx:{color:"green"}})]}):jsxRuntime.jsxs(material.MenuItem,{onClick:F,children:[jsxRuntime.jsx(material.ListItemIcon,{sx:{color:"red"},children:jsxRuntime.jsx(iconsMaterial.BlockOutlined,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{primary:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646",sx:{color:"red"}})]})}),jsxRuntime.jsxs(material.Dialog,{open:f,onClose:E,maxWidth:"xs",PaperProps:{sx:{borderRadius:"16px"}},"aria-labelledby":"block-dialog-title",children:[jsxRuntime.jsxs(material.DialogTitle,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px"},children:[jsxRuntime.jsx(material.Typography,{variant:"h6",children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"}),jsxRuntime.jsx(material.IconButton,{onClick:E,children:jsxRuntime.jsx(iconsMaterial.Close,{})})]}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Typography,{variant:"body1",gutterBottom:true,children:["\u062F\u0631\u0635\u0648\u0631\u062A \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646\u060C \u06A9\u0627\u0631\u0628\u0631 \u0645\u0648\u0631\u062F\u0646\u0638\u0631 \u0646\u0645\u06CC\u200C\u062A\u0648\u0627\u0646\u062F \u0628\u0647 \u0634\u0645\u0627 \u067E\u06CC\u0627\u0645 \u0628\u062F\u0647\u062F. \u0622\u06CC\u0627 \u0627\u0632 \u0627\u06CC\u0646 \u06A9\u0627\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"," "]})}),jsxRuntime.jsxs(material.DialogActions,{sx:{gap:"1rem"},children:[jsxRuntime.jsx(material.Button,{onClick:E,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsxRuntime.jsx(material.Button,{onClick:k,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem",background:"#BD1300",color:"#fff","&:hover":{background:"#BD1300",color:"#fff"}},children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"})]})]}),jsxRuntime.jsxs(material.Dialog,{open:d,onClose:b,maxWidth:"xs","aria-labelledby":"unblock-dialog-title",PaperProps:{sx:{borderRadius:"16px"}},children:[jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsx(material.Typography,{variant:"body1",gutterBottom:true,children:"\u0622\u06CC\u0627 \u0627\u0632 \u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A \u0627\u06CC\u0646 \u06A9\u0627\u0631\u0628\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:b,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsxRuntime.jsx(material.Button,{onClick:A,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]})]})]})},bt=_o;var Lo=({date:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",marginY:"16px"},children:[jsxRuntime.jsx(material.Divider,{sx:{flexGrow:1}}),jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{marginX:"8px",padding:"0.25rem 0.75rem",background:"#F4F4F4",borderRadius:"1rem"},children:t}),jsxRuntime.jsx(material.Divider,{sx:{flexGrow:1}})]}),wt=react.memo(Lo);var Ko=({attachment:t,isMe:r})=>{let[n,o]=react.useState(false),c=t.isProductPreview||t.mimeType==="product/preview",e=t.mimeType?.startsWith("image/")||false,s=t.signedUrl||t.url,m=t.thumbnailSignedUrl||s,f=i=>!i||i<1024?(i||0)+" B":i<1024*1024?(i/1024).toFixed(1)+" KB":(i/(1024*1024)).toFixed(1)+" MB",h=()=>t.mimeType?.startsWith("image/")?jsxRuntime.jsx(iconsMaterial.Image,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("video/")?jsxRuntime.jsx(iconsMaterial.VideoLibrary,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("audio/")?jsxRuntime.jsx(iconsMaterial.AudioFile,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType==="application/pdf"?jsxRuntime.jsx(iconsMaterial.PictureAsPdf,{sx:{width:24,height:24,color:"#1B1B1B"}}):jsxRuntime.jsx(iconsMaterial.AttachmentOutlined,{sx:{width:24,height:24,color:"#1B1B1B"}}),d=()=>{let i=document.createElement("a");i.href=s,i.download=t.originalName,i.target="_blank",document.body.appendChild(i),i.click(),document.body.removeChild(i);};return c?jsxRuntime.jsxs(material.Box,{component:"a",href:t.productUrl||t.url,target:"_blank",rel:"noopener noreferrer",sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"0.75rem",padding:"0.75rem",borderRadius:"0.5rem",border:`1px solid ${r?"rgba(255,255,255,0.2)":"#E0E0E0"}`,background:r?"rgba(255,255,255,0.1)":"#F4F4F4",textDecoration:"none",maxWidth:"350px",cursor:"pointer",transition:"all 0.2s ease","&:hover":{background:r?"rgba(255,255,255,0.15)":"#EEEEEE"}},children:[t.productImage&&jsxRuntime.jsx(material.Box,{component:"img",src:t.productImage,alt:t.productTitle||"Product",sx:{width:60,height:60,borderRadius:"0.375rem",objectFit:"cover",flexShrink:0}}),jsxRuntime.jsx(material.Stack,{flex:1,minWidth:0,children:jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:600,color:r?"white":"#1B1B1B",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"0.25rem"},children:t.productTitle||t.originalName})})]}):e?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(material.Box,{sx:{position:"relative",maxWidth:"300px",cursor:"pointer",borderRadius:"8px",overflow:"hidden"},onClick:()=>o(true),children:[jsxRuntime.jsx(material.Box,{component:"img",src:m,alt:t.originalName,sx:{width:"100%",height:"auto",maxHeight:"300px",objectFit:"cover",display:"block"}}),t.width&&t.height&&jsxRuntime.jsxs(material.Box,{sx:{position:"absolute",bottom:4,right:4,background:"rgba(0,0,0,0.5)",color:"white",padding:"2px 6px",borderRadius:"4px",fontSize:"10px"},children:[t.width," \xD7 ",t.height]})]}),n&&jsxRuntime.jsxs(material.Box,{sx:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.9)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:2},onClick:()=>o(false),children:[jsxRuntime.jsx(material.IconButton,{sx:{position:"absolute",top:16,right:16,color:"white"},onClick:()=>o(false),children:jsxRuntime.jsx(iconsMaterial.Close,{})}),jsxRuntime.jsx(material.IconButton,{sx:{position:"absolute",top:16,left:16,color:"white"},onClick:i=>{i.stopPropagation(),d();},children:jsxRuntime.jsx(iconsMaterial.Download,{})}),jsxRuntime.jsx(material.Box,{component:"img",src:s,alt:t.originalName,sx:{maxWidth:"90%",maxHeight:"90%",objectFit:"contain"},onClick:i=>i.stopPropagation()})]})]}):jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:r?"rgba(255,255,255,0.1)":"#F4F4F4",borderRadius:"0.5rem",padding:"0.75rem",gap:"0.5rem",maxWidth:"300px",cursor:"pointer",border:r?"1px solid rgba(255,255,255,0.2)":"1px solid #E0E0E0"},onClick:d,children:[jsxRuntime.jsx(material.Box,{sx:{width:40,height:40,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:r?"#E3E3E3":"##E3E3E3",color:r?"white":"inherit"},children:h()}),jsxRuntime.jsxs(material.Stack,{flex:1,minWidth:0,children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500,color:r?"white":"inherit"},children:t.originalName}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:r?"rgba(255,255,255,0.7)":"textSecondary"},children:f(t.size)})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:r?"white":"inherit"},children:jsxRuntime.jsx(iconsMaterial.Download,{sx:{width:20,height:20}})})]})},Ge=Ko;var Zo=({content:t,isMe:r,hasOpenGraph:n=false})=>{let o=t.replace(/\n/g,`
34
+ `);return jsxRuntime.jsx(material.Box,{sx:{"& p":{margin:0,marginBottom:"0.5em","&:last-child":{marginBottom:0}},"& a":{color:r?"#FFFFFF":"#1976d2",textDecoration:"underline !important","&:hover":{textDecoration:"underline !important"}},"& code":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.2em 0.4em",borderRadius:"3px",fontSize:"0.9em",fontFamily:"monospace"},"& pre":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.75em",borderRadius:"4px",overflow:"auto",margin:"0.5em 0","& code":{backgroundColor:"transparent",padding:0}},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& ul, & ol":{margin:"0.5em 0",paddingLeft:"1.5em"},"& li":{marginBottom:"0.25em"},"& blockquote":{borderLeft:`3px solid ${r?"rgba(255, 255, 255, 0.3)":"rgba(0, 0, 0, 0.2)"}`,paddingLeft:"1em",marginLeft:0,marginRight:0,fontStyle:"italic",opacity:.9},"& h1, & h2, & h3, & h4, & h5, & h6":{margin:"0.5em 0 0.3em 0",fontWeight:600},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& hr":{border:"none",borderTop:`1px solid ${r?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,margin:"0.75em 0"},"& table":{borderCollapse:"collapse",width:"100%",margin:"0.5em 0"},"& th, & td":{border:`1px solid ${r?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,padding:"0.5em",textAlign:"left"},"& th":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",fontWeight:600},direction:"auto"},children:jsxRuntime.jsx(Vo__default.default,{remarkPlugins:[Jo__default.default],components:{a:({node:c,...e})=>jsxRuntime.jsx("a",{...e,target:"_blank",rel:"noopener noreferrer"})},children:o})})},kt=react.memo(Zo);var cr=({message:t,activeUserId:r,othersAvatar:n})=>{let o=Y(C=>C.socket),c=B(C=>C.getCurrentChat()),e=t.senderId===r,{baseApi:s}=K(),m=material.useTheme(),f=material.useMediaQuery(m.breakpoints.down("sm")),h=n,[d,i]=react.useState(null),[x,S]=react.useState(null);return react.useEffect(()=>{!e&&o&&c?._id&&o?.emit("SEEN_CHAT",{chatId:c._id});},[e,o,c?._id]),react.useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(!M||M.length===0){S(null);return}let E=M[0],b=null;try{let A=new URL(E).searchParams.get("productId");if(A)b=Number(A);else if(E.includes("/product/")){let T=E.match(/\/product\/(\d+)/);T&&(b=Number(T[1]));}}catch{S(null);return}if(!b||Number.isNaN(b)){S(null);return}try{let k=await fetch(`${s}Catalog/Products/${b}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!k.ok)throw new Error("Failed to load product");let A=await k.json(),T=A?.value||A,D=T?.name||T?.titleFa||String(b),G=(T?.images||[]).find(g=>g?.isMain)?.url||T?.images?.[0]?.url,U=`https://rasmio.com/product/${b}`;S({id:`product-${b}`,url:U,thumbnailUrl:G,signedUrl:U,thumbnailSignedUrl:G,mimeType:"product/preview",size:0,originalName:D,isProductPreview:!0,productTitle:D,productImage:G,productUrl:U});}catch(k){console.error("Error fetching product data:",k),S(null);}})(),()=>{S(null);}),[t.content,t.id]),react.useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(M&&M.length>0){let E=M[0];if(E.includes("productId=")||E.includes("/product/")){i(null);return}try{let A=await(await fetch(`${s}v3/OpenGraph/GetOpenGraph?url=${encodeURIComponent(E)}`)).json();A&&(A.title||A.description||A.image)?i({title:A.title,description:A.description,image:A.image,url:E}):i(null);}catch(k){console.error("Error fetching OpenGraph data:",k),i(null);}}else i(null);})(),()=>{i(null);}),[t.content,t.id,s]),jsxRuntime.jsx(material.Box,{display:"flex",justifyContent:e?"flex-start":"flex-end",marginY:f?"16px":"8px",paddingX:"8px",children:jsxRuntime.jsxs(material.Box,{display:"flex",flexDirection:e?"row":"row-reverse",alignItems:"flex-start",maxWidth:f?"100%":"70%",children:[!e&&jsxRuntime.jsx("img",{src:h,alt:e?"You":t.senderName,style:{width:40,height:40,borderRadius:"4px"}}),jsxRuntime.jsxs(material.Box,{display:"flex",flexDirection:"column",alignItems:e?"flex-start":"flex-end",marginX:"8px",children:[jsxRuntime.jsxs(material.Box,{sx:{backgroundColor:e?"#0058CB":"#FFFFFF",color:e?"#FFFFFF":"#000000",padding:"0.75rem 1rem",borderRadius:e?"0 0.5rem 0.5rem 0.5rem":"0.5rem 0 0.5rem 0.5rem",wordBreak:"break-word"},children:[t?.attachments&&t?.attachments?.length>0&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:t?.attachments?.map(C=>jsxRuntime.jsx(Ge,{attachment:C,isMe:e},C.id))}),x&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:jsxRuntime.jsx(Ge,{attachment:x,isMe:e})}),t?.content&&jsxRuntime.jsx(material.Box,{sx:{direction:"auto"},children:jsxRuntime.jsx(kt,{content:t.content,isMe:e,hasOpenGraph:!!d})}),d&&jsxRuntime.jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"0.25rem 0.5rem 0 0.25rem",display:"flex",textDecoration:"underline !important",width:"100%",alignItems:"flex-start",borderRight:"3px solid #C7C7C7",gap:"0.5rem",marginTop:"0.5rem"},children:[d.image&&jsxRuntime.jsx("img",{src:d.image,alt:d.title,style:{width:"3rem",height:"3rem",borderRadius:"4px",marginBottom:1,marginLeft:1}}),jsxRuntime.jsxs(material.Stack,{direction:"column",gap:.5,flex:1,children:[jsxRuntime.jsx(material.Typography,{sx:{fontWeight:"bold",direction:"auto"},children:d.title}),d.description&&jsxRuntime.jsxs(material.Typography,{sx:{display:"block",opacity:.8,direction:"auto"},children:[d.description.substring(0,100),"..."]})]})]})]}),t?.buttons&&t.buttons.length>0&&jsxRuntime.jsx(material.Stack,{spacing:1,sx:{marginTop:"8px",width:"100%"},children:t.buttons.map((C,F)=>jsxRuntime.jsx(material.Button,{variant:"contained",fullWidth:true,href:C.link,target:"_blank",rel:"noopener noreferrer",sx:{textTransform:"none",padding:"8px 16px",fontSize:"0.875rem",fontWeight:500},children:C.text},F))}),jsxRuntime.jsxs(material.Box,{sx:{marginTop:"4px",display:"flex",alignItems:"center",justifyContent:"center",gap:"0.38rem"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"textSecondary",sx:{direction:"auto"},children:t.time}),e&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!t.hasSeen&&jsxRuntime.jsx(iconsMaterial.Check,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.hasSeen&&jsxRuntime.jsx(iconsMaterial.DoneAll,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.status==="sending"&&jsxRuntime.jsx(iconsMaterial.AccessTime,{style:{color:"#FFA500",width:"1rem",height:"1rem"}}),t.status==="failed"&&jsxRuntime.jsx(iconsMaterial.ErrorOutline,{style:{color:"#FF0000",width:"1rem",height:"1rem"}})]})]})]})]})})},Bt=react.memo(cr);var _t=t=>{if(!t)return "";let r=t.trim(),n=new Date;if(n.setHours(0,0,0,0),r==="\u0627\u0645\u0631\u0648\u0632"||r.toLowerCase()==="today")return n.toDateString();if(r==="\u062F\u06CC\u0631\u0648\u0632"||r.toLowerCase()==="yesterday"){let c=new Date(n);return c.setDate(c.getDate()-1),c.toDateString()}let o=new Date(r);return Number.isNaN(o.getTime())?r:(o.setHours(0,0,0,0),o.toDateString())},hr=(t,r)=>t?r?_t(t.date)!==_t(r.date):true:false,gr=({messagesEndRef:t,productAttachment:r})=>{let{currentChat:n}=B(b=>({currentChat:b.getCurrentChat()})),o=B.getState().getActiveAccount(),[c,e]=react.useState(false),[s,m]=react.useState(false),f=react.useRef(null),h=react.useRef(n?.messages.length??0),d=n?.messages??[],i=d.length,x=i>0?d[i-1]:void 0,S=reactVirtual.useVirtualizer({count:i,getScrollElement:()=>f.current,estimateSize:()=>80,overscan:5}),C=react.useCallback((b="smooth")=>{let k=f.current;k&&(k.scrollTo({top:k.scrollHeight,behavior:b}),e(false),m(false));},[]),F=react.useCallback(()=>{let b=f.current;if(!b)return;let{scrollTop:k,scrollHeight:A,clientHeight:T}=b,D=A-(k+T)<=50;m(!D),D&&e(false);},[]);react.useEffect(()=>{let b=h.current;if(i===0){h.current=0;return}if(!f.current){h.current=i;return}if(i>b){let k=f.current,{scrollTop:A,scrollHeight:T,clientHeight:D}=k;T-(A+D)<=50||x?.senderId===o?._id?C("smooth"):e(true);}else i<b&&C("auto");h.current=i;},[i,x?.id,x?.senderId,o?._id,C]),react.useEffect(()=>{e(false),m(false),h.current=n?.messages.length??0,C("auto");},[n?._id,C]);let M=i>0,E=S.getVirtualItems();return jsxRuntime.jsxs(material.Box,{position:"relative",flex:1,children:[jsxRuntime.jsxs(material.Box,{ref:f,onScroll:F,sx:{position:"relative",height:"100%",overflowY:"auto",padding:{xs:"1rem 0.75rem",md:"1.5rem"}},children:[M?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(material.Box,{sx:{height:`${S.getTotalSize()}px`,position:"relative"},children:E.map(b=>{let k=d[b.index],A=b.index>0?d[b.index-1]:void 0,T=hr(k,A);return jsxRuntime.jsxs(material.Box,{ref:S.measureElement,"data-index":b.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${b.start}px)`},children:[T&&k?.date&&jsxRuntime.jsx(wt,{date:k.date}),k&&jsxRuntime.jsx(Bt,{message:k,activeUserId:o?._id,activeUserAvatar:o?.avatar,othersAvatar:n?.avatar})]},k?.id??b.key)})})}):jsxRuntime.jsx(material.Stack,{justifyContent:"center",alignItems:"center",sx:{minHeight:"100%",textAlign:"center",color:"#5E5E5E",gap:"1rem",padding:"1rem"},children:jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.Typography,{variant:"body1",children:"\u0647\u0646\u0648\u0632 \u067E\u06CC\u0627\u0645\u06CC \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647 \u0627\u0633\u062A."}),jsxRuntime.jsx(material.Typography,{variant:"body2",children:"\u0627\u0648\u0644\u06CC\u0646 \u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06A9\u0646\u06CC\u062F."})]})}),jsxRuntime.jsx("div",{ref:t})]}),c&&s&&jsxRuntime.jsxs(material.Button,{variant:"contained",onClick:()=>C("smooth"),sx:{position:"fixed",bottom:{xs:"126px",sm:"100px"},left:"50%",transform:"translateX(-50%)",backgroundColor:"#D9E2FF",color:"#001945",borderRadius:"3rem",boxShadow:"0 2px 8px rgba(0,0,0,0.1)","&:hover":{backgroundColor:"#BBDEFB"},zIndex:1e3,direction:"rtl",gap:"4px",padding:{xs:"8px 16px",sm:"10px 20px"},fontSize:{xs:"0.875rem",sm:"1rem"},whiteSpace:"nowrap",minWidth:{xs:"auto",sm:"200px"}},children:["\u067E\u06CC\u0627\u0645 \u062C\u062F\u06CC\u062F \u062F\u0627\u0631\u06CC\u062F",jsxRuntime.jsx(iconsMaterial.ArrowDownwardOutlined,{sx:{fontSize:{xs:"1.2rem",sm:"1.5rem"}}})]})]})},Ft=gr;var Dt={uploadFile:"/uploads/upload"};var xr=async t=>{let r=new FormData;return r.append("file",t.file),(await ce.post(Dt.uploadFile,r,{headers:{"Content-Type":"multipart/form-data"}})).data},Ut=()=>reactQuery.useMutation({mutationFn:xr});var Ar=({attachment:t,onRemove:r,showPreview:n=true})=>{let o=t instanceof File,c=o?t.type:t.mimeType,e=o?t.name:t.originalName,s=t.size,m=o?void 0:t.signedUrl||t.url,f=o?void 0:t.thumbnailSignedUrl||t.signedUrl||t.url,h=S=>S<1024?S+" B":S<1024*1024?(S/1024).toFixed(1)+" KB":(S/(1024*1024)).toFixed(1)+" MB",d=()=>c.startsWith("image/")?jsxRuntime.jsx(iconsMaterial.Image,{sx:{width:24,height:24}}):c.startsWith("video/")?jsxRuntime.jsx(iconsMaterial.VideoLibrary,{sx:{width:24,height:24}}):c.startsWith("audio/")?jsxRuntime.jsx(iconsMaterial.AudioFile,{sx:{width:24,height:24}}):jsxRuntime.jsx(iconsMaterial.InsertDriveFile,{sx:{width:24,height:24}}),i=o?URL.createObjectURL(t):f||m;c.startsWith("image/")&&n&&i;return jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",gap:"0.5rem",overflow:"hidden",border:"1px solid #E0E0E0"},children:[jsxRuntime.jsx(material.Box,{sx:{width:48,height:48,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#E0E0E0"},children:d()}),jsxRuntime.jsxs(material.Stack,{flex:1,minWidth:0,children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500},children:e}),jsxRuntime.jsx(material.Typography,{variant:"caption",color:"textSecondary",children:h(s)})]}),r&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:r,sx:{padding:"4px"},children:jsxRuntime.jsx(iconsMaterial.Close,{sx:{width:20,height:20}})})]})},Ke=Ar;var Fr=({onBack:t})=>{let r=react.useRef(null),n=react.useRef(null),[o,c]=react.useState(""),[e,s]=react.useState(null),[m,f]=react.useState([]),[h,d]=react.useState(null),[i,x]=react.useState(null),S=20*1024*1024,C=Ut(),F=react.useRef(null),M=react.useRef(void 0),E=react.useRef(false),{accounts:b,getActiveAccount:k,getCurrentChat:A,addMessageToChat:T,updateMessageInChat:D,setMessagesForChat:G,chats:U}=B(p=>({accounts:p.accounts,getActiveAccount:p.getActiveAccount,getCurrentChat:p.getCurrentChat,addMessageToChat:p.addMessageToChat,updateMessageInChat:p.updateMessageInChat,setMessagesForChat:p.setMessagesForChat,chats:p.chats})),g=A(),j=k(),J=j?._id||"",ne=j?.avatar,l=Y(p=>p.socket),I=react.useMemo(()=>g?g.canSendMessages===false||g.isBot===true:false,[g]),a=react.useMemo(()=>I?g?.isBot?"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F":g?.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":"",[g?.composerHint,g?.isBot,I]);react.useEffect(()=>{g&&r.current&&!I&&r.current.focus();},[g,I]),react.useEffect(()=>{c(""),f([]),s(null),d(null),new URL(window.location.href).searchParams.has("productId")||x(null);},[g?._id]),react.useEffect(()=>{if(l)return l.on("CHAT_SEEN",({chatId:p})=>{g&&g._id===p&&G(p,g.messages.map(L=>({...L,hasSeen:true})));}),()=>{l.off("CHAT_SEEN");}},[l,g,G]);let y=react.useCallback(p=>{!l||!g?._id||!g?.receiverId||E.current!==p&&(E.current=p,l.emit(p?"START_TYPING":"FINISH_TYPING",{targetId:g.receiverId}));},[l,g]),O=react.useCallback(p=>{if(I){me__default.default.error(a);return}let L=p.target.value;c(L),M.current&&clearTimeout(M.current),L.length>0&&y(true),M.current=setTimeout(()=>{y(false);},1e3);},[y,I,a]);react.useEffect(()=>()=>{M.current&&clearTimeout(M.current),y(false);},[y,g?._id]),react.useEffect(()=>{if(!g?._id){x(null);return}let L=new URL(window.location.href).searchParams.get("productId");if(!L){x(null);return}let z=Number(L);if(!z||Number.isNaN(z)){x(null);return}let P=K().baseApi;(async()=>{try{let ge=await fetch(`${P}Catalog/Products/${z}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!ge.ok)throw new Error("Failed to load product");let Re=await ge.json(),$=Re?.value||Re,Jt=$?.name||$?.titleFa||String(z),Qt=($?.images||[]).find(eo=>eo?.isMain)?.url||$?.images?.[0]?.url,Zt=`https://rasmio.com/product/${z}`;x({id:z,title:Jt,image:Qt,url:Zt});}catch(ge){console.error("Error fetching product attachment:",ge),x({id:z,title:String(z),image:void 0,url:`https://rasmio.com/product/${z}`});}})();},[g?._id]);let u=react.useCallback(async p=>{if(I){me__default.default.error(a),p.target&&(p.target.value="");return}let L=p.target.files?.[0];if(L){if(d(null),L.size>S){d(`\u062D\u062C\u0645 \u0641\u0627\u06CC\u0644 \u0646\u0628\u0627\u06CC\u062F \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 ${S/(1024*1024)} \u0645\u06AF\u0627\u0628\u0627\u06CC\u062A \u0628\u0627\u0634\u062F`);return}s(L);try{let P=(await C.mutateAsync({file:L}))?.data?.attachments;P&&P.length>0?(f(P),s(null)):(d("\u067E\u0627\u0633\u062E \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0632 \u0633\u0631\u0648\u0631"),s(null));}catch{d("\u062E\u0637\u0627 \u062F\u0631 \u0622\u067E\u0644\u0648\u062F \u0641\u0627\u06CC\u0644. \u0644\u0637\u0641\u0627 \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F."),s(null);}p.target&&(p.target.value="");}},[C,S,I,a]),w=react.useCallback(()=>{s(null),f([]),d(null);},[]),H=react.useCallback(()=>{if(I){me__default.default.error(a);return}n.current?.click();},[I,a]),q=react.useCallback(()=>{if(I){me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.");return}let p=o.trim(),L=p.length>0||m.length>0,z=i?.url?p?`${p}
35
+ ${i.url}`:`${i.url}`:p;if(L&&j&&l&&g){y(false),M.current&&clearTimeout(M.current);let P=`temp-${Date.now()}`,he={id:P,senderId:J,senderName:"You",content:z,time:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:"\u0627\u0645\u0631\u0648\u0632",createdAt:Date.now(),status:"sending",avatar:ne||""},ge=m.length>0,Re=m.map($=>$.id);if(T(g?._id,he),c(""),f([]),d(null),i){x(null);let $=new URL(window.location.href);$.searchParams.delete("productId"),window.history.replaceState({},"",$.toString());}ge?l.emit("SEND_ATTACHMENT",{targetId:g?.receiverId,text:p||void 0,attachments:Re},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});}):l.emit("SEND_MESSAGE",{targetId:g?.receiverId,content:z,isChatId:g?.type==="Broadcast"},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});});}},[o,j,l,J,T,D,g,y,m,i,I,a]),Z=react.useCallback(p=>{if(I){me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."),p.preventDefault();return}p.key==="Enter"&&!p.shiftKey&&(q(),p.preventDefault());},[q,I,a]);return g&&jsxRuntime.jsxs(material.Stack,{flexDirection:"column",bgcolor:"#E3E3E3",borderRadius:{xs:0,md:2},position:"relative",flex:1,children:[jsxRuntime.jsx(material.Stack,{bgcolor:"#F4F4F4",borderBottom:"1px solid #ccc",px:2,flexBasis:"64px",sx:{borderTopRightRadius:{md:"0.75rem"}},justifyContent:"center",alignItems:"flex-start",boxSizing:"content-box",children:jsxRuntime.jsx(bt,{onBack:t})}),jsxRuntime.jsx(material.Stack,{flex:"1 0 0",position:"relative",overflow:"auto",children:jsxRuntime.jsx(Ft,{messagesEndRef:F,productAttachment:i})}),jsxRuntime.jsxs(material.Stack,{sx:{padding:"16px"},position:"relative",onDragOver:p=>{I&&(p.preventDefault(),p.stopPropagation(),me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},onDrop:p=>{I&&(p.preventDefault(),p.stopPropagation(),me__default.default.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},children:[jsxRuntime.jsxs(material.Stack,{children:[i&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",marginBottom:"8px",width:"100%",gap:"1rem",overflow:"hidden"},children:[i.image&&jsxRuntime.jsx("img",{src:i.image,alt:i.title||"product",style:{width:48,height:48,borderRadius:4,objectFit:"contain",background:"#F4F4F4"}}),jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i.title||i.id}),jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>{x(null);let p=new URL(window.location.href);p.searchParams.delete("productId"),window.history.replaceState({},"",p.toString());},children:jsxRuntime.jsx("span",{style:{fontSize:20,lineHeight:1},children:"\xD7"})})]}),(e||m.length>0)&&jsxRuntime.jsxs(material.Stack,{sx:{marginBottom:"8px",maxWidth:"100%",width:{xs:"91%",md:"100%"}},children:[e&&jsxRuntime.jsx(Ke,{attachment:e,onRemove:w}),m.map(p=>jsxRuntime.jsx(Ke,{attachment:p,onRemove:w},p.id))]}),h&&jsxRuntime.jsx(material.Alert,{severity:"error",onClose:()=>d(null),sx:{marginBottom:"8px"},children:h})]}),g?.isBlockedByMe?jsxRuntime.jsxs(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px"},direction:"row",justifyContent:"center",alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0634\u0645\u0627 \u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0631\u0627 \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0647\u200C\u0627\u06CC\u062F"}),jsxRuntime.jsx(material.Button,{variant:"outlined",onClick:()=>{l&&g&&(l.emit("USER_UNBLOCK",{accountId:g.receiverId}),B.getState().unblockUser(g._id));},sx:{borderColor:"#777",color:"#0058CB"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]}):g?.isBlockedByTarget?jsxRuntime.jsx(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center"},children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0627\u0632 \u0637\u0631\u0641 \u06A9\u0627\u0631\u0628\u0631 \u0645\u0642\u0627\u0628\u0644 \u0645\u0633\u062F\u0648\u062F \u0634\u062F\u0647 \u0627\u0633\u062A"})}):I?jsxRuntime.jsxs(material.Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px",flexDirection:"row"},justifyContent:"center",alignItems:"center",children:[jsxRuntime.jsx(iconsMaterial.NotificationsActive,{sx:{color:"#FF9800"}}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"textSecondary",children:a||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."})]}):jsxRuntime.jsx(material.TextField,{fullWidth:true,placeholder:"\u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u06CC\u0646\u062C\u0627 \u0628\u0646\u0648\u06CC\u0633\u06CC\u062F",value:o,multiline:true,maxRows:4,inputRef:r,onChange:O,onKeyDown:Z,sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",fontFamily:"RASMIO","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"},"& textarea":{fontFamily:"RASMIO",overflowY:"auto",maxHeight:"96px",resize:"none",lineHeight:"24px",paddingRight:"40px",paddingLeft:"40px","&::-webkit-scrollbar":{width:"8px"},"&::-webkit-scrollbar-track":{background:"#f1f1f1",borderRadius:"4px"},"&::-webkit-scrollbar-thumb":{background:"#888",borderRadius:"4px"},"&::-webkit-scrollbar-thumb:hover":{background:"#555"}},"& textarea::placeholder":{fontFamily:"RASMIO"}},InputProps:{endAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"end",children:o.length>0||m.length>0||C.isLoading?jsxRuntime.jsx(material.IconButton,{onClick:q,disabled:C.isLoading||m.length===0&&o.trim().length===0,children:jsxRuntime.jsx(iconsMaterial.Send,{sx:{transform:"rotate(180deg)",color:C.isLoading||m.length===0&&o.trim().length===0?"#999":"#0058CB"}})}):jsxRuntime.jsx(material.IconButton,{onClick:H,children:jsxRuntime.jsx(iconsMaterial.AttachFile,{sx:{color:"#777"}})})})}}),jsxRuntime.jsx("input",{ref:n,type:"file",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",style:{display:"none"},onChange:u})]}),jsxRuntime.jsx("div",{ref:F})]})},zt=Fr;var Wt=(t,r)=>react.useCallback(o=>{let c=r();o!==c?._id&&t?.emit("USER_JOINED",{accountId:o});},[t,r]);var Gt=(t,r,n,o)=>react.useCallback(e=>{t&&t.emit("GET_MESSAGES",{chatId:e}),r(e),window.history&&window.history.pushState({},"",`?chatId=${e}`),n&&n(),o&&o(false);},[t,r,n,o]);var $t=(t,r,n)=>react.useMemo(()=>{let o=K(),c=t||[];if(o.companyId){if(!n)return [];let e=Number(o.companyId);if(Number(n.rasmioId)!==e)return []}if(r){let e=String(r).toLowerCase();c.length;c=c.filter(m=>String(m?.title||"").toLowerCase().includes(e));}return c},[t,r,n]);var qt=material.styled(({className:t,...r})=>jsxRuntime.jsx(material.Tooltip,{...r,classes:{popper:t}}))(({theme:t})=>({"& .MuiTooltip-tooltip":{borderRadius:"0.25rem",background:"#1B1B1B",display:"flex",minHeight:"1.5rem",padding:"0.25rem 0.5rem",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"0.625rem",color:"#fff",fontSize:"0.875rem"}})),en=({onChatSelect:t})=>{let[r,n]=react.useState(null),[o,c]=react.useState(""),s=!!K().companyId,{accounts:m,chats:f,getActiveAccount:h,setCurrentChat:d,isMy:i}=B(l=>({accounts:l.accounts,chats:l.chats,getActiveAccount:l.getActiveAccount,setCurrentChat:l.setCurrentChat,isMy:l.isMy})),{statusTooltip:x,setStatusTooltip:S}=B(),C=Y(l=>l.socket),F=material.useTheme(),M=material.useMediaQuery(F.breakpoints.down("sm")),E=m.some(l=>l?.unreadChatsCount>0),b=Wt(C,h),k=Gt(C,d,t,S),A=m.find(l=>l.isActive),T=$t(f,o,A),D=react.useRef(null),G=reactVirtual.useVirtualizer({count:T?.length||0,getScrollElement:()=>D.current,estimateSize:react.useCallback(()=>80,[]),overscan:10}),U=react.useRef(null),g=l=>{if(!(s||m.length<=1||i))if(m.length>1&&!i)n(U.current);else return},j=()=>{n(null);},J=l=>{switch(l){case "online":return "#006D3F";case "disconnected":return "#BD1300";case "reconnecting":return "#ff9800";default:return "#006D3F"}},ne=l=>{switch(l){case "online":return "\u0622\u0646\u0644\u0627\u06CC\u0646";case "disconnected":return "\u0622\u0641\u0644\u0627\u06CC\u0646";case "reconnecting":return "\u062F\u0631 \u062D\u0627\u0644 \u0627\u062A\u0635\u0627\u0644";default:return "\u0622\u0646\u0644\u0627\u06CC\u0646"}};return jsxRuntime.jsxs(material.Stack,{sx:{width:M?"100%":"20rem",display:"flex",flexDirection:"column",borderRight:M?"none":"1px solid #ccc",height:"100%",background:"#F4F4F4",borderTopLeftRadius:M?0:"16px",borderBottomLeftRadius:M?0:"16px"},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 0.75rem",width:"100%",gap:"0.5rem",flexBasis:"64px"},children:[M?x&&jsxRuntime.jsx(qt,{title:ne(h()?.status),children:jsxRuntime.jsx(material.Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsxRuntime.jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}):jsxRuntime.jsx(qt,{title:ne(h()?.status),children:jsxRuntime.jsx(material.Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsxRuntime.jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}),m.length>1&&!i&&!s&&(E?jsxRuntime.jsx(material.Badge,{variant:"dot",color:"error",sx:{ml:1,"& .MuiBadge-badge":{right:"auto",left:0,top:"20%",transform:"translateY(-50%)"}},children:jsxRuntime.jsx(material.Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer"},onClick:g,children:jsxRuntime.jsx(iconsMaterial.ExpandMore,{})})}):jsxRuntime.jsx(material.Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer",marginInlineEnd:"0.75rem",marginInlineStart:"0.25rem"},onClick:g,children:jsxRuntime.jsx(iconsMaterial.ExpandMore,{})})),M?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(material.Drawer,{anchor:"bottom",open:!!r,onClose:j,PaperProps:{sx:{maxHeight:"50%",width:"100%",borderTopLeftRadius:"16px",borderTopRightRadius:"16px",padding:"0.5rem"}},children:[jsxRuntime.jsxs(material.Stack,{flexDirection:"row",alignItems:"center",justifyContent:"space-between",children:[jsxRuntime.jsx(material.Typography,{sx:{fontSize:"1rem",fontWeight:700,padding:"0.5rem 1rem",color:"#1B1B1B"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),jsxRuntime.jsx(material.IconButton,{onClick:j,children:jsxRuntime.jsx(iconsMaterial.CloseOutlined,{style:{color:"#1B1B1B"}})})]}),m.map(l=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondary:l?.__t==="User"?"":l?.rasmioId}),(l?.unreadChatsCount??0)>0&&jsxRuntime.jsx(material.Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{ml:1,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]})}):jsxRuntime.jsxs(material.Menu,{anchorEl:r,open:!!r,onClose:j,PaperProps:{sx:{boxShadow:"0px 4px 24px 0px rgba(0, 0, 0, 0.12)",width:"20rem",marginInlineEnd:"4.6rem",marginTop:"1.2rem",padding:"1rem 1rem",borderRadius:"0.75rem"}},anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[jsxRuntime.jsx(material.Typography,{variant:"body1",sx:{fontSize:"0.875rem",fontWeight:400,color:"#5E5E5E"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),m.map(l=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem 0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600,marginInlineStart:"0.5rem"},secondary:l?.__t==="User"?"":l?.rasmioId,secondaryTypographyProps:{marginInlineStart:"0.5rem"}}),(l?.unreadChatsCount??0)>0&&jsxRuntime.jsx(material.Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{mt:2,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]}),jsxRuntime.jsx(material.TextField,{value:o,onChange:l=>c(l.target.value),variant:"outlined",size:"small",placeholder:"\u062C\u0633\u062A\u062C\u0648",sx:{flexGrow:1,borderRadius:"0.5rem",background:"#F4F4F4",border:"0.5px solid #777","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},InputProps:{endAdornment:o&&jsxRuntime.jsx(iconsMaterial.Close,{sx:{cursor:"pointer",width:"1.125rem",height:"1.125rem",marginInlineEnd:"0.75rem"},onClick:()=>c("")})}})]}),jsxRuntime.jsx(material.Divider,{sx:{marginBottom:"0.75rem"},orientation:"horizontal",flexItem:true}),jsxRuntime.jsxs(material.Typography,{sx:{color:"#5E5E5E",fontSize:"0.875rem",fontWeight:"400",padding:"0.75rem"},children:["\u06AF\u0641\u062A \u0648 \u06AF\u0648\u0647\u0627\u06CC ",h()?.displayName]}),jsxRuntime.jsxs(material.Stack,{ref:D,sx:{height:`${G.getTotalSize()}px`,flex:1,overflowY:"auto",scrollbarWidth:"none",width:"100%",position:"relative","&::-webkit-scrollbar":{display:"none"},msOverflowStyle:"none"},children:[f.length<1&&jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"flex-start",alignItems:"center",height:"100%",marginBlockStart:"8rem",width:"100%",fontFamily:"RASMIO",gap:"0.5rem"},children:[jsxRuntime.jsx(iconsMaterial.CommentsDisabledOutlined,{sx:{fontSize:48,color:"#1B1B1B"}}),jsxRuntime.jsx(material.Typography,{color:"#1B1B1B",sx:{mb:2},children:"\u0634\u0645\u0627 \u0647\u06CC\u0686 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0641\u0639\u0627\u0644\u06CC \u0646\u062F\u0627\u0631\u06CC\u062F"})]}),jsxRuntime.jsx(material.Stack,{sx:{width:"100%",position:"relative"},children:G.getVirtualItems().map(l=>{let I=T[l.index];return jsxRuntime.jsx(material.Stack,{"data-index":l.index,ref:G.measureElement,sx:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${l.start}px)`},children:jsxRuntime.jsxs(material.ListItemButton,{onClick:()=>k(I._id),sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"0.75rem",gap:"0.25rem",backgroundColor:I?.isActive?"#DADADA":"transparent","&:hover":{backgroundColor:"#e0e0e0"}},children:[jsxRuntime.jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:I?.title,src:I?.avatar}),jsxRuntime.jsx(material.ListItemText,{primary:I?.title,secondary:I?.isTyping?"\u062F\u0631 \u062D\u0627\u0644 \u0646\u0648\u0634\u062A\u0646 ...":I?.lastMessage?.content||"",primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondaryTypographyProps:{noWrap:true,color:I?.isTyping?"#006D3F":"#555",fontSize:"0.875rem",fontWeight:400},sx:{marginRight:"1rem"}}),jsxRuntime.jsxs(material.Stack,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"1rem",marginLeft:"auto",minWidth:"50px"},children:[I.lastMessage?.createdAt&&jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:"#999",fontSize:"0.75rem"},children:new Date(I.lastMessage.createdAt).toLocaleDateString("fa-IR")===new Date().toLocaleDateString("fa-IR")?new Date(I.lastMessage.createdAt).toLocaleTimeString("fa-IR",{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:"Asia/Tehran"}):de(new Date(I.lastMessage.createdAt).toISOString())}),!I.isActive&&I?.unReadCount>0&&jsxRuntime.jsx(material.Badge,{badgeContent:I.unReadCount,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff",fontSize:"0.75rem",height:"1.25rem",minWidth:"1.25rem"}}})]})]})},l.key)})})]})]})},Vt=en;var nn=react.memo(({token:t,serviceApi:r,socketUrl:n,baseApi:o,companyId:c})=>{react.useEffect(()=>{let d={};r&&(d.serviceApi=r),c&&(d.companyId=c),n&&(d.socketUrl=n),o&&(d.baseApi=o),Object.keys(d).length>0&&Je(d);},[r,n,o,c]);let e=B(d=>d.getCurrentChat()),s=B(d=>d.setCurrentChat),m=B(d=>d.chats),f=B(d=>d.refreshBroadcastPermissions),h=Y(d=>d.socket);return react.useEffect(()=>{let d=new URL(window.location.href),i=d.searchParams.get("chatId");if(!d.searchParams.get("targetCompanyId")&&i&&m.length>0&&h){let S=m.find(C=>C._id===i);S?(!e||e._id!==i)&&(s(i),S.isPreview||h.emit("GET_MESSAGES",{chatId:i})):i.startsWith("preview_chat_")||(d.searchParams.delete("chatId"),window.history.replaceState({},"",d.toString()));}},[m,s,e,h]),react.useEffect(()=>{let d=i=>{if(i.key==="Escape"&&(s(""),window.history)){let x=new URL(window.location.href);x.searchParams.delete("chatId"),window.history.pushState({},"",x.toString());}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),react.useEffect(()=>{f();},[f,e?._id]),jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:pt,children:jsxRuntime.jsx(Ze,{token:t,children:jsxRuntime.jsx(mt,{children:jsxRuntime.jsx(at,{socketUrl:n,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"row",bgcolor:"#E3E3E3",borderRadius:"16px",width:"100%",marginBlockStart:"1rem",flex:1,position:"relative",overflow:"hidden",minHeight:"500px"},children:[jsxRuntime.jsx(material.Box,{sx:{width:{xs:"100%",sm:"unset"},display:e?{xs:"none",sm:"block"}:"block"},children:jsxRuntime.jsx(Vt,{})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,position:{xs:"absolute",sm:"relative"},display:e?"flex":"none",inset:0,zIndex:e?10:-1,visibility:e?"visible":"hidden"},children:jsxRuntime.jsx(zt,{})})]})})})})})},(t,r)=>t.token===r.token&&t.serviceApi===r.serviceApi&&t.socketUrl===r.socketUrl);
36
36
 
37
37
  module.exports = nn;
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- import { styled, Tooltip, Grid, Box, Divider, Typography, useTheme, useMediaQuery, Stack, Button, Badge, Drawer, IconButton, MenuItem, ListItemText, Menu, TextField, ListItem, Alert, InputAdornment, Skeleton, Avatar, ListItemIcon, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
1
+ import { styled, Tooltip, Box, Divider, Typography, useTheme, useMediaQuery, Stack, Button, Badge, Drawer, IconButton, MenuItem, ListItemText, Menu, TextField, ListItemButton, Alert, InputAdornment, Skeleton, Avatar, ListItemIcon, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
2
2
  import { memo, useEffect, useState, useMemo, useRef, useCallback } from 'react';
3
3
  import { QueryClient, QueryClientProvider, useMutation } from 'react-query';
4
4
  import { create } from 'zustand';
5
- import ar from 'axios';
5
+ import ao from 'axios';
6
6
  import me from 'react-hot-toast';
7
7
  import { useShallow } from 'zustand/react/shallow';
8
- import { io } from 'socket.io-client';
8
+ import { io as io$1 } from 'socket.io-client';
9
9
  import be from 'dayjs';
10
- import ur from 'jalaliday';
11
- import mr from 'dayjs/plugin/isToday.js';
12
- import pr from 'dayjs/plugin/isYesterday.js';
10
+ import mo from 'jalaliday';
11
+ import po from 'dayjs/plugin/isToday.js';
12
+ import ho from 'dayjs/plugin/isYesterday.js';
13
13
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
14
  import { Player } from '@lottiefiles/react-lottie-player';
15
15
  import { Check, DoneAll, AccessTime, ErrorOutline, ExpandMore, CloseOutlined, Close, CommentsDisabledOutlined, NotificationsActive, Send, AttachFile, Download, ArrowForward, MoreVert, BlockOutlined, ArrowDownwardOutlined, Image, VideoLibrary, AudioFile, PictureAsPdf, AttachmentOutlined, InsertDriveFile } from '@mui/icons-material';
16
16
  import { useVirtualizer } from '@tanstack/react-virtual';
17
- import qr from 'react-markdown';
18
- import Vr from 'remark-gfm';
17
+ import Vo from 'react-markdown';
18
+ import Jo from 'remark-gfm';
19
19
 
20
- var B=create((t,o)=>({accounts:[],chats:[],statusTooltip:true,isMy:false,broadcastState:null,addPreviewChat:n=>{let r=`preview_chat_${n.receiverId}`;if(o().chats.find(e=>e._id===r)){o().setCurrentChat(r);return}t(e=>({chats:[{_id:r,avatar:n.avatar,messages:[],isActive:true,unReadCount:0,status:n.status,title:n.displayName,receiverId:n.receiverId,isPreview:true,isBot:false,lastSeen:n.lastActive},...e.chats.map(s=>({...s,isActive:false}))]}));},updateChatStatus:(n,r)=>{t(c=>({accounts:c.accounts.map(e=>e._id===n?{...e,status:r}:e)}));},setActiveAccount:n=>{let{accounts:r}=o();if(!r.find(s=>s._id===n)){console.warn("[setActiveAccount] Account not found:",n);return}let e=r.map(s=>({...s,isActive:s._id===n}));t({accounts:e}),o().refreshBroadcastPermissions();},setAccounts:n=>{t({accounts:n});},setChats:n=>t(()=>{let r=o().getActiveAccount(),c=o().broadcastState,s=o().chats.filter(i=>i.isPreview&&!n.some(x=>x._id===i._id)),f=n.map(i=>{let x=!!(i?.type==="Broadcast"||i?.isDefaultBroadcast),S=i?.isBot===true,F=i?.ownerId||(typeof i?.owner=="object"?i?.owner?._id:void 0)||c?.ownerId||void 0,M=x&&F?F===(r?._id??""):true,E=S?false:x?M:i?.canSendMessages??true,b=i?.composerHint||(S?"\u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u062A\u0648\u0633\u0637 \u0631\u0628\u0627\u062A \u0645\u062F\u06CC\u0631\u06CC\u062A \u0645\u06CC\u200C\u0634\u0648\u062F \u0648 \u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":E?void 0:"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.");return {...i,ownerId:F,isTyping:false,canSendMessages:E,composerHint:b,isBot:S}}).sort((i,x)=>{let S=!!(i.type==="Broadcast"||i.isDefaultBroadcast),C=!!(x.type==="Broadcast"||x.isDefaultBroadcast);return S&&!C?-1:C&&!S?1:0}),h=[...s,...f],d=f.find(i=>i.type==="Broadcast"||i.isDefaultBroadcast);return {chats:h,broadcastState:d?{chatId:d._id,ownerId:d.ownerId,isDefault:!!d.isDefaultBroadcast}:null}}),getActiveAccount:()=>{let{accounts:n}=o();return n.find(r=>r.isActive)},setCurrentChat:n=>{t(r=>({accounts:r.accounts.map(e=>({...e,unreadChatsCount:e.isActive&&e.unreadChatsCount&&e.unreadChatsCount>0?e.unreadChatsCount-1:e.unreadChatsCount})),chats:r.chats.map(e=>({...e,isActive:e._id===n,unReadCount:e._id===n?0:e.unReadCount,messages:e._id===n?e.messages.map(s=>({...s,hasSeen:true})):e.messages}))}));},getCurrentChat:()=>{let{chats:n}=o();return n.find(r=>r.isActive)??null},addMessageToChat:(n,r)=>{t(c=>{let e=c.chats.findIndex(m=>m._id===n),s=[...c.chats];if(e!==-1){let m=s[e];if(m.messages.some(d=>d.id===r.id)){if(r.id.startsWith("temp-")===false&&m.messages.some(i=>i.id.startsWith("temp-"))){let i=m.messages.map(S=>S.id.startsWith("temp-")&&S.content===r.content&&Math.abs(S.createdAt-r.createdAt)<5e3?r:S),x={...m,lastMessage:r,messages:i};return s.splice(e,1),s.unshift(x),{chats:s}}return c}let h={...s[e],lastMessage:r,messages:[...s[e].messages,r]};return s.splice(e,1),s.unshift(h),{chats:s}}else {let m=c.chats.findIndex(f=>f.isPreview&&f.receiverId===r.senderId);if(m!==-1){let f=s[m],h={...f,_id:n,isPreview:false,lastMessage:r,messages:[...f.messages,r]};return s.splice(m,1),s.unshift(h),{chats:s}}else return {chats:[{_id:n,lastMessage:r,messages:[r],avatar:r.avatar,isActive:false,title:r.senderName,receiverId:r.senderId,unReadCount:0,lastSeen:new Date().toISOString()},...c.chats]}}});},updateMessageInChat:(n,r,c)=>{t(e=>{let s=e.chats.findIndex(x=>x._id===n);if(s===-1)return e;let m=[...e.chats],f=m[s],h=f.messages.findIndex(x=>x.id===r);if(h===-1)return e;let d=[...f.messages];d[h]={...d[h],...c};let i={...f,messages:d,lastMessage:h===d.length-1?d[h]:f.lastMessage};return m[s]=i,{chats:m}});},setMessagesForChat:(n,r)=>{t(c=>{let e=c.chats.findIndex(s=>s._id===n);if(e!==-1){let s=[...c.chats];return s[e].messages=r,r.length>0&&(s[e].lastMessage=r[r.length-1]),{chats:s}}else return console.warn(`Chat with ID ${n} not found. Messages not set.`),{}});},setTypingStatus:(n,r)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,isTyping:r}:e)})),setStatusTooltip:n=>t({statusTooltip:n}),blockUser:n=>{t(r=>({chats:r.chats.map(c=>c._id===n?{...c,isBlockedByMe:true}:c)}));},unblockUser:n=>{t(r=>({chats:r.chats.map(c=>c._id===n?{...c,isBlockedByMe:false}:c)}));},updateChatBlockStatus:(n,r,c)=>{t(e=>({chats:e.chats.map(s=>s._id===n?{...s,isBlockedByMe:r,isBlockedByTarget:c}:s)}));},setIsMy:n=>t({isMy:n}),setBroadcastState:n=>t({broadcastState:n}),refreshBroadcastPermissions:()=>{let{broadcastState:n}=o();if(!n)return;let r=o().getActiveAccount();t(c=>({chats:c.chats.map(e=>{if(e._id!==n.chatId)return e;let s=n.ownerId?n.ownerId===(r?._id??""):false;return {...e,canSendMessages:s,composerHint:s?void 0:e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."}})}));},updateChatPermissions:(n,r)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,...r,composerHint:r.canSendMessages===false?r.composerHint||e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":r.composerHint}:e)}))}));var Y=create(t=>({socket:null,socketConnect:o=>t({socket:o}),socketDisconnect:()=>t({socket:null})}));var fe=create(t=>({token:"",setToken:o=>t({token:o})}));var nr={serviceApi:"https://gwdev.rasmio.com/api/chat/",socketUrl:"wss://devsocket.rasmio.com/chat",baseApi:"https://gwdev.rasmio.com/api/"},ye={...nr},Fe=new Set,K=()=>ye,Je=t=>(ye={...ye,...Object.fromEntries(Object.entries(t).filter(([,o])=>o!==void 0))},Fe.forEach(o=>o(ye)),ye);var Qe=t=>(Fe.add(t),()=>Fe.delete(t));var{serviceApi:ir}=K(),ce=ar.create({adapter:"fetch",baseURL:ir,timeout:2e4});Qe(t=>{ce.defaults.baseURL=t.serviceApi;});var cr=({children:t,token:o})=>{let n=fe(r=>r.setToken);return useEffect(()=>{o&&(n(o),ce.defaults.headers.common.Authorization=`Bearer ${o}`);},[o]),o?t:null},Ze=cr;var et=(t,o)=>{let{current:n}=useRef(io(t,o));return n};be.extend(ur);be.extend(mr);be.extend(pr);var de=t=>{let o=be(t).calendar("jalali").locale("fa"),n=be().calendar("jalali").locale("fa");return o.isSame(n,"day")?"\u0627\u0645\u0631\u0648\u0632":o.isSame(n.subtract(1,"day"),"day")?"\u062F\u06CC\u0631\u0648\u0632":o.year()===n.year()?o.format("D MMMM"):o.format("D MMMM YYYY")};var gr=({children:t,socketUrl:o})=>{let n=fe(a=>a.token),r=useMemo(()=>o||"wss://devsocket.rasmio.com/chat",[o]),{socketConnect:c}=Y(useShallow(a=>({socketConnect:a.socketConnect}))),e=et(r,{transports:["websocket"],reconnectionAttempts:3,reconnectionDelay:3e3,withCredentials:false,autoConnect:false,upgrade:false,auth:{token:`Bearer ${n}`}}),{setAccounts:s,setChats:m,addMessageToChat:f,setMessagesForChat:h,setActiveAccount:d,currentChat:i,setCurrentChat:x,addPreviewChat:S,accounts:C,updateChatStatus:F,updateChatBlockStatus:M,setIsMy:E,refreshBroadcastPermissions:b,updateChatPermissions:k}=B(useShallow(a=>({setAccounts:a.setAccounts,setChats:a.setChats,addMessageToChat:a.addMessageToChat,setMessagesForChat:a.setMessagesForChat,setActiveAccount:a.setActiveAccount,currentChat:a.getCurrentChat(),setCurrentChat:a.setCurrentChat,addPreviewChat:a.addPreviewChat,accounts:a.accounts,updateChatStatus:a.updateChatStatus,updateChatBlockStatus:a.updateChatBlockStatus,setIsMy:a.setIsMy,refreshBroadcastPermissions:a.refreshBroadcastPermissions,updateChatPermissions:a.updateChatPermissions}))),A=useRef(false),T=useRef(new Set);useEffect(()=>{let y=K().companyId;if(!y||!e||C.length===0||!e.connected)return;let O=C.find(w=>String(w.rasmioId)===String(y));!O||C.find(w=>w.isActive)?._id===O._id||e.emit("USER_JOINED",{accountId:O._id});},[e,C]);let D=useCallback(a=>{let y=B.getState().getActiveAccount(),O={id:a._id,senderId:a.sender._id,senderName:a.sender.displayName,avatar:a.sender.avatar,content:a.content,time:new Date(a.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(a.createdAt),createdAt:new Date(a.createdAt).getTime(),hasSeen:a.hasSeen,attachments:a.attachments?a.attachments.map(u=>({id:u._id||u.id,url:u.url,thumbnailUrl:u.thumbnailUrl,signedUrl:u.signedUrl,thumbnailSignedUrl:u.thumbnailSignedUrl,mimeType:u.mimeType,size:u.size,originalName:u.originalName,sha256:u.sha256,width:u.width,height:u.height,durationSec:u.durationSec})):[],buttons:a.buttons||[]};if(a.sender._id===y?._id){let u=B.getState(),w=u.chats.find(H=>H._id===a.chatId);if(w){let H=w.messages.find(q=>q.id===a._id||q.id.startsWith("temp-")&&q.content===a.content);if(H){u.updateMessageInChat(a.chatId,H.id,O);return}}}f(a.chatId,O);},[f]),G=useCallback(a=>{let O=K().companyId,u=new URL(window.location.href),w=a.find(P=>P.__t==="User"),H=u.searchParams.has("cmp"),q=u.searchParams.get("my")==="true",Z=a.find(P=>P.__t==="Company"),p=u.searchParams.get("cmp");E(q);let L=O||p,z=L?a.find(P=>String(P?.rasmioId)===String(L)):void 0;if(L&&z&&!A.current)e.emit("USER_JOINED",{accountId:z._id}),A.current=true,p&&(u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString()));else if(w&&!A.current&&!H&&!q&&!L){e.emit("USER_JOINED",{accountId:w._id}),A.current=true;let P=u.searchParams.get("targetCompanyId");P&&!T.current.has(P)&&(T.current.add(P),e.emit("ACCOUNT_INFO",{id:P}),setTimeout(()=>{let he=new URL(window.location.href);he.searchParams.get("targetCompanyId")===P&&(he.searchParams.delete("targetCompanyId"),window.history.replaceState({},document.title,he.toString()),me.error("\u0627\u0645\u06A9\u0627\u0646 \u0628\u0627\u0632 \u06A9\u0631\u062F\u0646 \u06AF\u0641\u062A\u06AF\u0648 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F"));},5e3));}else if(!A.current){let P=Z;e.emit("USER_JOINED",{accountId:P?._id}),A.current=true,u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString());}u.searchParams.has("my")&&(u.searchParams.delete("my"),window.history.replaceState({},document.title,u.toString())),s(a);},[e,s,E]),U=useCallback(a=>{let y=a.map(w=>({...w,messages:w.messages||[],unReadCount:w.unReadCount||0}));m(y),b();let u=new URL(window.location.href).searchParams.get("chatId");u&&y.find(H=>H._id===u)&&!B.getState().getCurrentChat()&&(x(u),e&&e.emit("GET_MESSAGES",{chatId:u}));},[m,b,x,e]),g=useCallback(a=>{d(a);},[d]),j=useCallback(a=>{let y=a?.message||a?.payload?.message||a?.payload?.reason||a?.data?.message||"\u062E\u0637\u0627\u06CC \u0646\u0627\u0645\u0634\u062E\u0635 \u0631\u062E \u062F\u0627\u062F\u0647 \u0627\u0633\u062A";me.error(y);let O=a?.chatId||a?.payload?.chatId||a?.data?.chatId||a?.meta?.chatId;!O||!(a?.code&&["BROADCAST_READ_ONLY","CHAT_PERMISSION_DENIED"].includes(a.code)||y.toLowerCase().includes("broadcast")||y.toLowerCase().includes("\u0627\u062C\u0627\u0632\u0647"))||k(O,{canSendMessages:false,composerHint:y});},[k]),J=useCallback(a=>{let O=a.map(u=>({id:u._id,senderId:u.sender._id,senderName:u.sender.displayName,avatar:u.sender.avatar,content:u.content,time:new Date(u.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(u.createdAt),createdAt:new Date(u.createdAt).getTime(),hasSeen:u.hasSeen,attachments:u.attachments?u.attachments.map(w=>({id:w._id||w.id,url:w.url,thumbnailUrl:w.thumbnailUrl,signedUrl:w.signedUrl,thumbnailSignedUrl:w.thumbnailSignedUrl,mimeType:w.mimeType,size:w.size,originalName:w.originalName,sha256:w.sha256,width:w.width,height:w.height,durationSec:w.durationSec})):[],buttons:u.buttons||[]})).sort((u,w)=>u.createdAt-w.createdAt);i&&h(i._id,O);},[i,h]),ne=useCallback(a=>{let y=B.getState(),O=y.chats.find(H=>H._id===a.chatId);if(a.receiverId){let H=`preview_chat_${a.receiverId}`;y.chats.find(Z=>Z._id===H)&&B.setState(Z=>({chats:Z.chats.filter(p=>p._id!==H)}));}if(O)x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId});else {let H=setInterval(()=>{B.getState().chats.find(Z=>Z._id===a.chatId)&&(clearInterval(H),x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId}));},100);setTimeout(()=>clearInterval(H),3e3);}let u=new URL(window.location.href),w=false;u.searchParams.has("targetCompanyId")&&(u.searchParams.delete("targetCompanyId"),w=true),(w||!u.searchParams.has("chatId"))&&(u.searchParams.set("chatId",a.chatId),window.history.replaceState({},document.title,u.toString()));},[x,e]),l=useCallback(a=>{S(a);let y=new URL(window.location.href);y.searchParams.has("targetCompanyId")&&(y.searchParams.delete("targetCompanyId"),true);let u=`preview_chat_${a.receiverId}`;y.searchParams.set("chatId",u),window.history.replaceState({},document.title,y.toString());},[S]),I=useCallback(a=>{M(a.chatId,a.isBlockedByMe,a.isBlockedByTarget);},[M]);return useEffect(()=>(e.connected||(e.connect(),c(e)),e.on("USER_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,true);}),e.on("USER_FINISH_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,false);}),e.on("NEW_MESSAGE",D),e.on("CHAT_MESSAGES",J),e.on("ACCOUNT_LIST",G),e.on("CHAT_LIST",U),e.on("ACCOUNT_SWITCHED",g),e.on("ERROR_OCCURED",j),e.on("OPEN_CHAT",ne),e.on("PREVIEW_CHAT",l),e.on("BLOCK_STATUS_UPDATED",I),e.on("connect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"online");}),e.on("disconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"disconnected");}),e.on("reconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"reconnecting");}),()=>{e.off("NEW_MESSAGE",D),e.off("CHAT_MESSAGES",J),e.off("ACCOUNT_LIST",G),e.off("CHAT_LIST",U),e.off("ACCOUNT_SWITCHED",g),e.off("ERROR_OCCURED",j),e.off("USER_TYPING"),e.off("USER_FINISH_TYPING"),e.off("OPEN_CHAT",ne),e.off("PREVIEW_CHAT",l),e.off("BLOCK_STATUS_UPDATED",I),e?.off("connect"),e?.off("disconnect"),e?.off("reconnect");}),[e,c,D,J,G,U,g,j,ne,l,I,C,F]),e?jsx(Fragment,{children:t}):null},at=gr;var yr=()=>jsx(Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",background:"#E3E3E3",borderRadius:"16px",height:"100vh"},children:jsx(Player,{src:"/lottie/waiting.json",autoplay:true,loop:true,style:{width:"5rem",height:"5rem"}})}),st=yr;var ct={challenge:"challenge"};var Ir=async t=>(await ce.post("/authentication/challenge",t)).data,dt=()=>useMutation({mutationFn:Ir,mutationKey:[ct.challenge]});var vr=({children:t})=>{let[o,n]=useState(true),[r,c]=useState(false),{mutate:e}=dt(),s=()=>{fe.setState({token:""}),Y.setState({socket:null}),B.setState({accounts:[],chats:[],statusTooltip:true});};return useEffect(()=>{s();let m=window.location.search,h=new URLSearchParams(m).get("targetCompanyId");e(h?{targetCompanyId:h}:{},{onSuccess:d=>{d.data?n(false):c(true);},onError:d=>{c(true);}});},[]),r?jsx(Fragment,{children:"Error"}):o?jsx(st,{}):jsx(Fragment,{children:t})},mt=vr;var pt=new QueryClient({});var Pr=()=>{let t=B(U=>U.getCurrentChat()),o=B(U=>U.setCurrentChat),{setStatusTooltip:n,blockUser:r,unblockUser:c}=B(),e=Y(U=>U.socket),[s,m]=useState(null),[f,h]=useState(false),[d,i]=useState(false),x=()=>{if(o(""),n(true),window.history){let U=new URL(window.location.href);U.searchParams.delete("chatId"),window.history.pushState({},"",U.toString());}},S=U=>{m(U.currentTarget);},C=()=>{m(null);},F=()=>{C(),h(true);},M=()=>{C(),i(true);},E=()=>{h(false);},b=()=>{i(false);},k=()=>{t&&e&&(e.emit("USER_BLOCK",{accountId:t.receiverId}),r(t._id)),h(false);},A=()=>{t&&e&&(e.emit("USER_UNBLOCK",{accountId:t.receiverId}),c(t._id)),i(false);};if(!t)return jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,width:"100%",children:[jsx(Skeleton,{variant:"circular",width:48,height:48}),jsxs(Stack,{flex:1,spacing:.5,children:[jsx(Skeleton,{variant:"text",width:"40%",height:16}),jsx(Skeleton,{variant:"text",width:"20%",height:12})]})]});let T=t?.title?.trim()||"\u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u062C\u062F\u06CC\u062F",D=t?.isBot===true?"":t?.status==="online"?"\u0622\u0646\u0644\u0627\u06CC\u0646":t?.lastSeen?`\u0622\u062E\u0631\u06CC\u0646 \u0628\u0627\u0632\u062F\u06CC\u062F : ${de(new Date(t.lastSeen).toISOString())}`:"";return jsxs(Fragment,{children:[jsxs(Stack,{alignItems:"center",justifyContent:"flex-start",flexDirection:"row",width:"100%",children:[jsx(Stack,{display:{xs:"flex",md:"none"},children:jsx(IconButton,{sx:{color:"#1B1B1B"},onClick:x,children:jsx(ArrowForward,{})})}),t?.avatar?jsx("img",{width:48,height:48,style:{borderRadius:"4px",objectFit:"cover"},alt:T,src:t.avatar}):jsx(Avatar,{sx:{width:48,height:48,bgcolor:"#0058CB",fontWeight:600},children:T.charAt(0)||"\u061F"}),jsxs(Stack,{marginLeft:"0.5rem",flex:1,children:[jsx(Typography,{variant:"body1",color:"#1B1B1B",children:T}),D&&jsx(Typography,{variant:"body2",color:t?.status==="online"?"#006D3F":"textSecondary",children:D})]}),jsx(Stack,{flex:1,alignItems:"flex-end",children:jsx(IconButton,{sx:{color:"#1B1B1B"},onClick:S,children:jsx(MoreVert,{})})})]}),jsx(Menu,{anchorEl:s,open:!!s,onClose:C,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:t?.isBlockedByMe?jsxs(MenuItem,{onClick:M,children:[jsx(ListItemIcon,{sx:{color:"green"},children:jsx(BlockOutlined,{fontSize:"small"})}),jsx(ListItemText,{primary:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A",sx:{color:"green"}})]}):jsxs(MenuItem,{onClick:F,children:[jsx(ListItemIcon,{sx:{color:"red"},children:jsx(BlockOutlined,{fontSize:"small"})}),jsx(ListItemText,{primary:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646",sx:{color:"red"}})]})}),jsxs(Dialog,{open:f,onClose:E,maxWidth:"xs",PaperProps:{sx:{borderRadius:"16px"}},"aria-labelledby":"block-dialog-title",children:[jsxs(DialogTitle,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px"},children:[jsx(Typography,{variant:"h6",children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"}),jsx(IconButton,{onClick:E,children:jsx(Close,{})})]}),jsx(DialogContent,{children:jsxs(Typography,{variant:"body1",gutterBottom:true,children:["\u062F\u0631\u0635\u0648\u0631\u062A \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646\u060C \u06A9\u0627\u0631\u0628\u0631 \u0645\u0648\u0631\u062F\u0646\u0638\u0631 \u0646\u0645\u06CC\u200C\u062A\u0648\u0627\u0646\u062F \u0628\u0647 \u0634\u0645\u0627 \u067E\u06CC\u0627\u0645 \u0628\u062F\u0647\u062F. \u0622\u06CC\u0627 \u0627\u0632 \u0627\u06CC\u0646 \u06A9\u0627\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"," "]})}),jsxs(DialogActions,{sx:{gap:"1rem"},children:[jsx(Button,{onClick:E,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsx(Button,{onClick:k,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem",background:"#BD1300",color:"#fff","&:hover":{background:"#BD1300",color:"#fff"}},children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"})]})]}),jsxs(Dialog,{open:d,onClose:b,maxWidth:"xs","aria-labelledby":"unblock-dialog-title",PaperProps:{sx:{borderRadius:"16px"}},children:[jsx(DialogContent,{children:jsx(Typography,{variant:"body1",gutterBottom:true,children:"\u0622\u06CC\u0627 \u0627\u0632 \u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A \u0627\u06CC\u0646 \u06A9\u0627\u0631\u0628\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:b,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsx(Button,{onClick:A,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]})]})]})},bt=Pr;var Or=({date:t})=>jsxs(Box,{sx:{display:"flex",alignItems:"center",marginY:"16px"},children:[jsx(Divider,{sx:{flexGrow:1}}),jsx(Typography,{variant:"body2",sx:{marginX:"8px",padding:"0.25rem 0.75rem",background:"#F4F4F4",borderRadius:"1rem"},children:t}),jsx(Divider,{sx:{flexGrow:1}})]}),wt=memo(Or);var Yr=({attachment:t,isMe:o})=>{let[n,r]=useState(false),c=t.isProductPreview||t.mimeType==="product/preview",e=t.mimeType?.startsWith("image/")||false,s=t.signedUrl||t.url,m=t.thumbnailSignedUrl||s,f=i=>!i||i<1024?(i||0)+" B":i<1024*1024?(i/1024).toFixed(1)+" KB":(i/(1024*1024)).toFixed(1)+" MB",h=()=>t.mimeType?.startsWith("image/")?jsx(Image,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("video/")?jsx(VideoLibrary,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("audio/")?jsx(AudioFile,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType==="application/pdf"?jsx(PictureAsPdf,{sx:{width:24,height:24,color:"#1B1B1B"}}):jsx(AttachmentOutlined,{sx:{width:24,height:24,color:"#1B1B1B"}}),d=()=>{let i=document.createElement("a");i.href=s,i.download=t.originalName,i.target="_blank",document.body.appendChild(i),i.click(),document.body.removeChild(i);};return c?jsxs(Box,{component:"a",href:t.productUrl||t.url,target:"_blank",rel:"noopener noreferrer",sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"0.75rem",padding:"0.75rem",borderRadius:"0.5rem",border:`1px solid ${o?"rgba(255,255,255,0.2)":"#E0E0E0"}`,background:o?"rgba(255,255,255,0.1)":"#F4F4F4",textDecoration:"none",maxWidth:"350px",cursor:"pointer",transition:"all 0.2s ease","&:hover":{background:o?"rgba(255,255,255,0.15)":"#EEEEEE"}},children:[t.productImage&&jsx(Box,{component:"img",src:t.productImage,alt:t.productTitle||"Product",sx:{width:60,height:60,borderRadius:"0.375rem",objectFit:"cover",flexShrink:0}}),jsx(Stack,{flex:1,minWidth:0,children:jsx(Typography,{variant:"body2",sx:{fontWeight:600,color:o?"white":"#1B1B1B",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"0.25rem"},children:t.productTitle||t.originalName})})]}):e?jsxs(Fragment,{children:[jsxs(Box,{sx:{position:"relative",maxWidth:"300px",cursor:"pointer",borderRadius:"8px",overflow:"hidden"},onClick:()=>r(true),children:[jsx(Box,{component:"img",src:m,alt:t.originalName,sx:{width:"100%",height:"auto",maxHeight:"300px",objectFit:"cover",display:"block"}}),t.width&&t.height&&jsxs(Box,{sx:{position:"absolute",bottom:4,right:4,background:"rgba(0,0,0,0.5)",color:"white",padding:"2px 6px",borderRadius:"4px",fontSize:"10px"},children:[t.width," \xD7 ",t.height]})]}),n&&jsxs(Box,{sx:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.9)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:2},onClick:()=>r(false),children:[jsx(IconButton,{sx:{position:"absolute",top:16,right:16,color:"white"},onClick:()=>r(false),children:jsx(Close,{})}),jsx(IconButton,{sx:{position:"absolute",top:16,left:16,color:"white"},onClick:i=>{i.stopPropagation(),d();},children:jsx(Download,{})}),jsx(Box,{component:"img",src:s,alt:t.originalName,sx:{maxWidth:"90%",maxHeight:"90%",objectFit:"contain"},onClick:i=>i.stopPropagation()})]})]}):jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:o?"rgba(255,255,255,0.1)":"#F4F4F4",borderRadius:"0.5rem",padding:"0.75rem",gap:"0.5rem",maxWidth:"300px",cursor:"pointer",border:o?"1px solid rgba(255,255,255,0.2)":"1px solid #E0E0E0"},onClick:d,children:[jsx(Box,{sx:{width:40,height:40,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:o?"#E3E3E3":"##E3E3E3",color:o?"white":"inherit"},children:h()}),jsxs(Stack,{flex:1,minWidth:0,children:[jsx(Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500,color:o?"white":"inherit"},children:t.originalName}),jsx(Typography,{variant:"caption",sx:{color:o?"rgba(255,255,255,0.7)":"textSecondary"},children:f(t.size)})]}),jsx(IconButton,{size:"small",sx:{color:o?"white":"inherit"},children:jsx(Download,{sx:{width:20,height:20}})})]})},Ge=Yr;var Qr=({content:t,isMe:o,hasOpenGraph:n=false})=>{let r=t.replace(/\n/g,`
21
- `);return jsx(Box,{sx:{"& p":{margin:0,marginBottom:"0.5em","&:last-child":{marginBottom:0}},"& a":{color:o?"#FFFFFF":"#1976d2",textDecoration:"underline !important","&:hover":{textDecoration:"underline !important"}},"& code":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.2em 0.4em",borderRadius:"3px",fontSize:"0.9em",fontFamily:"monospace"},"& pre":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.75em",borderRadius:"4px",overflow:"auto",margin:"0.5em 0","& code":{backgroundColor:"transparent",padding:0}},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& ul, & ol":{margin:"0.5em 0",paddingLeft:"1.5em"},"& li":{marginBottom:"0.25em"},"& blockquote":{borderLeft:`3px solid ${o?"rgba(255, 255, 255, 0.3)":"rgba(0, 0, 0, 0.2)"}`,paddingLeft:"1em",marginLeft:0,marginRight:0,fontStyle:"italic",opacity:.9},"& h1, & h2, & h3, & h4, & h5, & h6":{margin:"0.5em 0 0.3em 0",fontWeight:600},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& hr":{border:"none",borderTop:`1px solid ${o?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,margin:"0.75em 0"},"& table":{borderCollapse:"collapse",width:"100%",margin:"0.5em 0"},"& th, & td":{border:`1px solid ${o?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,padding:"0.5em",textAlign:"left"},"& th":{backgroundColor:o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",fontWeight:600},direction:"auto"},children:jsx(qr,{remarkPlugins:[Vr],components:{a:({node:c,...e})=>jsx("a",{...e,target:"_blank",rel:"noopener noreferrer"})},children:r})})},kt=memo(Qr);var so=({message:t,activeUserId:o,othersAvatar:n})=>{let r=Y(C=>C.socket),c=B(C=>C.getCurrentChat()),e=t.senderId===o,{baseApi:s}=K(),m=useTheme(),f=useMediaQuery(m.breakpoints.down("sm")),h=n,[d,i]=useState(null),[x,S]=useState(null);return useEffect(()=>{!e&&r&&c?._id&&r?.emit("SEEN_CHAT",{chatId:c._id});},[e,r,c?._id]),useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(!M||M.length===0){S(null);return}let E=M[0],b=null;try{let A=new URL(E).searchParams.get("productId");if(A)b=Number(A);else if(E.includes("/product/")){let T=E.match(/\/product\/(\d+)/);T&&(b=Number(T[1]));}}catch{S(null);return}if(!b||Number.isNaN(b)){S(null);return}try{let k=await fetch(`${s}Catalog/Products/${b}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!k.ok)throw new Error("Failed to load product");let A=await k.json(),T=A?.value||A,D=T?.name||T?.titleFa||String(b),G=(T?.images||[]).find(g=>g?.isMain)?.url||T?.images?.[0]?.url,U=`https://rasmio.com/product/${b}`;S({id:`product-${b}`,url:U,thumbnailUrl:G,signedUrl:U,thumbnailSignedUrl:G,mimeType:"product/preview",size:0,originalName:D,isProductPreview:!0,productTitle:D,productImage:G,productUrl:U});}catch(k){console.error("Error fetching product data:",k),S(null);}})(),()=>{S(null);}),[t.content,t.id]),useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(M&&M.length>0){let E=M[0];if(E.includes("productId=")||E.includes("/product/")){i(null);return}try{let A=await(await fetch(`${s}v3/OpenGraph/GetOpenGraph?url=${encodeURIComponent(E)}`)).json();A&&(A.title||A.description||A.image)?i({title:A.title,description:A.description,image:A.image,url:E}):i(null);}catch(k){console.error("Error fetching OpenGraph data:",k),i(null);}}else i(null);})(),()=>{i(null);}),[t.content,t.id,s]),jsx(Box,{display:"flex",justifyContent:e?"flex-start":"flex-end",marginY:f?"16px":"8px",paddingX:"8px",children:jsxs(Box,{display:"flex",flexDirection:e?"row":"row-reverse",alignItems:"flex-start",maxWidth:f?"100%":"70%",children:[!e&&jsx("img",{src:h,alt:e?"You":t.senderName,style:{width:40,height:40,borderRadius:"4px"}}),jsxs(Box,{display:"flex",flexDirection:"column",alignItems:e?"flex-start":"flex-end",marginX:"8px",children:[jsxs(Box,{sx:{backgroundColor:e?"#0058CB":"#FFFFFF",color:e?"#FFFFFF":"#000000",padding:"0.75rem 1rem",borderRadius:e?"0 0.5rem 0.5rem 0.5rem":"0.5rem 0 0.5rem 0.5rem",wordBreak:"break-word"},children:[t?.attachments&&t?.attachments?.length>0&&jsx(Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:t?.attachments?.map(C=>jsx(Ge,{attachment:C,isMe:e},C.id))}),x&&jsx(Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:jsx(Ge,{attachment:x,isMe:e})}),t?.content&&jsx(Box,{sx:{direction:"auto"},children:jsx(kt,{content:t.content,isMe:e,hasOpenGraph:!!d})}),d&&jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"0.25rem 0.5rem 0 0.25rem",display:"flex",textDecoration:"underline !important",width:"100%",alignItems:"flex-start",borderRight:"3px solid #C7C7C7",gap:"0.5rem",marginTop:"0.5rem"},children:[d.image&&jsx("img",{src:d.image,alt:d.title,style:{width:"3rem",height:"3rem",borderRadius:"4px",marginBottom:1,marginLeft:1}}),jsxs(Stack,{direction:"column",gap:.5,flex:1,children:[jsx(Typography,{sx:{fontWeight:"bold",direction:"auto"},children:d.title}),d.description&&jsxs(Typography,{sx:{display:"block",opacity:.8,direction:"auto"},children:[d.description.substring(0,100),"..."]})]})]})]}),t?.buttons&&t.buttons.length>0&&jsx(Stack,{spacing:1,sx:{marginTop:"8px",width:"100%"},children:t.buttons.map((C,F)=>jsx(Button,{variant:"contained",fullWidth:true,href:C.link,target:"_blank",rel:"noopener noreferrer",sx:{textTransform:"none",padding:"8px 16px",fontSize:"0.875rem",fontWeight:500},children:C.text},F))}),jsxs(Box,{sx:{marginTop:"4px",display:"flex",alignItems:"center",justifyContent:"center",gap:"0.38rem"},children:[jsx(Typography,{variant:"caption",color:"textSecondary",sx:{direction:"auto"},children:t.time}),e&&jsxs(Fragment,{children:[!t.hasSeen&&jsx(Check,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.hasSeen&&jsx(DoneAll,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.status==="sending"&&jsx(AccessTime,{style:{color:"#FFA500",width:"1rem",height:"1rem"}}),t.status==="failed"&&jsx(ErrorOutline,{style:{color:"#FF0000",width:"1rem",height:"1rem"}})]})]})]})]})})},Bt=memo(so);var _t=t=>{if(!t)return "";let o=t.trim(),n=new Date;if(n.setHours(0,0,0,0),o==="\u0627\u0645\u0631\u0648\u0632"||o.toLowerCase()==="today")return n.toDateString();if(o==="\u062F\u06CC\u0631\u0648\u0632"||o.toLowerCase()==="yesterday"){let c=new Date(n);return c.setDate(c.getDate()-1),c.toDateString()}let r=new Date(o);return Number.isNaN(r.getTime())?o:(r.setHours(0,0,0,0),r.toDateString())},ho=(t,o)=>t?o?_t(t.date)!==_t(o.date):true:false,go=({messagesEndRef:t,productAttachment:o})=>{let{currentChat:n}=B(b=>({currentChat:b.getCurrentChat()})),r=B.getState().getActiveAccount(),[c,e]=useState(false),[s,m]=useState(false),f=useRef(null),h=useRef(n?.messages.length??0),d=n?.messages??[],i=d.length,x=i>0?d[i-1]:void 0,S=useVirtualizer({count:i,getScrollElement:()=>f.current,estimateSize:()=>80,overscan:5}),C=useCallback((b="smooth")=>{let k=f.current;k&&(k.scrollTo({top:k.scrollHeight,behavior:b}),e(false),m(false));},[]),F=useCallback(()=>{let b=f.current;if(!b)return;let{scrollTop:k,scrollHeight:A,clientHeight:T}=b,D=A-(k+T)<=50;m(!D),D&&e(false);},[]);useEffect(()=>{let b=h.current;if(i===0){h.current=0;return}if(!f.current){h.current=i;return}if(i>b){let k=f.current,{scrollTop:A,scrollHeight:T,clientHeight:D}=k;T-(A+D)<=50||x?.senderId===r?._id?C("smooth"):e(true);}else i<b&&C("auto");h.current=i;},[i,x?.id,x?.senderId,r?._id,C]),useEffect(()=>{e(false),m(false),h.current=n?.messages.length??0,C("auto");},[n?._id,C]);let M=i>0,E=S.getVirtualItems();return jsxs(Box,{position:"relative",flex:1,children:[jsxs(Box,{ref:f,onScroll:F,sx:{position:"relative",height:"100%",overflowY:"auto",padding:{xs:"1rem 0.75rem",md:"1.5rem"}},children:[M?jsx(Fragment,{children:jsx(Box,{sx:{height:`${S.getTotalSize()}px`,position:"relative"},children:E.map(b=>{let k=d[b.index],A=b.index>0?d[b.index-1]:void 0,T=ho(k,A);return jsxs(Box,{ref:S.measureElement,"data-index":b.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${b.start}px)`},children:[T&&k?.date&&jsx(wt,{date:k.date}),k&&jsx(Bt,{message:k,activeUserId:r?._id,activeUserAvatar:r?.avatar,othersAvatar:n?.avatar})]},k?.id??b.key)})})}):jsx(Stack,{justifyContent:"center",alignItems:"center",sx:{minHeight:"100%",textAlign:"center",color:"#5E5E5E",gap:"1rem",padding:"1rem"},children:jsxs(Box,{children:[jsx(Typography,{variant:"body1",children:"\u0647\u0646\u0648\u0632 \u067E\u06CC\u0627\u0645\u06CC \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647 \u0627\u0633\u062A."}),jsx(Typography,{variant:"body2",children:"\u0627\u0648\u0644\u06CC\u0646 \u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06A9\u0646\u06CC\u062F."})]})}),jsx("div",{ref:t})]}),c&&s&&jsxs(Button,{variant:"contained",onClick:()=>C("smooth"),sx:{position:"fixed",bottom:{xs:"126px",sm:"100px"},left:"50%",transform:"translateX(-50%)",backgroundColor:"#D9E2FF",color:"#001945",borderRadius:"3rem",boxShadow:"0 2px 8px rgba(0,0,0,0.1)","&:hover":{backgroundColor:"#BBDEFB"},zIndex:1e3,direction:"rtl",gap:"4px",padding:{xs:"8px 16px",sm:"10px 20px"},fontSize:{xs:"0.875rem",sm:"1rem"},whiteSpace:"nowrap",minWidth:{xs:"auto",sm:"200px"}},children:["\u067E\u06CC\u0627\u0645 \u062C\u062F\u06CC\u062F \u062F\u0627\u0631\u06CC\u062F",jsx(ArrowDownwardOutlined,{sx:{fontSize:{xs:"1.2rem",sm:"1.5rem"}}})]})]})},Ft=go;var Dt={uploadFile:"/uploads/upload"};var xo=async t=>{let o=new FormData;return o.append("file",t.file),(await ce.post(Dt.uploadFile,o,{headers:{"Content-Type":"multipart/form-data"}})).data},Ut=()=>useMutation({mutationFn:xo});var Ao=({attachment:t,onRemove:o,showPreview:n=true})=>{let r=t instanceof File,c=r?t.type:t.mimeType,e=r?t.name:t.originalName,s=t.size,m=r?void 0:t.signedUrl||t.url,f=r?void 0:t.thumbnailSignedUrl||t.signedUrl||t.url,h=S=>S<1024?S+" B":S<1024*1024?(S/1024).toFixed(1)+" KB":(S/(1024*1024)).toFixed(1)+" MB",d=()=>c.startsWith("image/")?jsx(Image,{sx:{width:24,height:24}}):c.startsWith("video/")?jsx(VideoLibrary,{sx:{width:24,height:24}}):c.startsWith("audio/")?jsx(AudioFile,{sx:{width:24,height:24}}):jsx(InsertDriveFile,{sx:{width:24,height:24}}),i=r?URL.createObjectURL(t):f||m;c.startsWith("image/")&&n&&i;return jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",gap:"0.5rem",overflow:"hidden",border:"1px solid #E0E0E0"},children:[jsx(Box,{sx:{width:48,height:48,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#E0E0E0"},children:d()}),jsxs(Stack,{flex:1,minWidth:0,children:[jsx(Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500},children:e}),jsx(Typography,{variant:"caption",color:"textSecondary",children:h(s)})]}),o&&jsx(IconButton,{size:"small",onClick:o,sx:{padding:"4px"},children:jsx(Close,{sx:{width:20,height:20}})})]})},Ke=Ao;var Fo=({onBack:t})=>{let o=useRef(null),n=useRef(null),[r,c]=useState(""),[e,s]=useState(null),[m,f]=useState([]),[h,d]=useState(null),[i,x]=useState(null),S=20*1024*1024,C=Ut(),F=useRef(null),M=useRef(),E=useRef(false),{accounts:b,getActiveAccount:k,getCurrentChat:A,addMessageToChat:T,updateMessageInChat:D,setMessagesForChat:G,chats:U}=B(p=>({accounts:p.accounts,getActiveAccount:p.getActiveAccount,getCurrentChat:p.getCurrentChat,addMessageToChat:p.addMessageToChat,updateMessageInChat:p.updateMessageInChat,setMessagesForChat:p.setMessagesForChat,chats:p.chats})),g=A(),j=k(),J=j?._id||"",ne=j?.avatar,l=Y(p=>p.socket),I=useMemo(()=>g?g.canSendMessages===false||g.isBot===true:false,[g]),a=useMemo(()=>I?g?.isBot?"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F":g?.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":"",[g?.composerHint,g?.isBot,I]);useEffect(()=>{g&&o.current&&!I&&o.current.focus();},[g,I]),useEffect(()=>{c(""),f([]),s(null),d(null),new URL(window.location.href).searchParams.has("productId")||x(null);},[g?._id]),useEffect(()=>{if(l)return l.on("CHAT_SEEN",({chatId:p})=>{g&&g._id===p&&G(p,g.messages.map(L=>({...L,hasSeen:true})));}),()=>{l.off("CHAT_SEEN");}},[l,g,G]);let y=useCallback(p=>{!l||!g?._id||!g?.receiverId||E.current!==p&&(E.current=p,l.emit(p?"START_TYPING":"FINISH_TYPING",{targetId:g.receiverId}));},[l,g]),O=useCallback(p=>{if(I){me.error(a);return}let L=p.target.value;c(L),M.current&&clearTimeout(M.current),L.length>0&&y(true),M.current=setTimeout(()=>{y(false);},1e3);},[y,I,a]);useEffect(()=>()=>{M.current&&clearTimeout(M.current),y(false);},[y,g?._id]),useEffect(()=>{if(!g?._id){x(null);return}let L=new URL(window.location.href).searchParams.get("productId");if(!L){x(null);return}let z=Number(L);if(!z||Number.isNaN(z)){x(null);return}let P=K().baseApi;(async()=>{try{let ge=await fetch(`${P}Catalog/Products/${z}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!ge.ok)throw new Error("Failed to load product");let Re=await ge.json(),$=Re?.value||Re,Jt=$?.name||$?.titleFa||String(z),Qt=($?.images||[]).find(er=>er?.isMain)?.url||$?.images?.[0]?.url,Zt=`https://rasmio.com/product/${z}`;x({id:z,title:Jt,image:Qt,url:Zt});}catch(ge){console.error("Error fetching product attachment:",ge),x({id:z,title:String(z),image:void 0,url:`https://rasmio.com/product/${z}`});}})();},[g?._id]);let u=useCallback(async p=>{if(I){me.error(a),p.target&&(p.target.value="");return}let L=p.target.files?.[0];if(L){if(d(null),L.size>S){d(`\u062D\u062C\u0645 \u0641\u0627\u06CC\u0644 \u0646\u0628\u0627\u06CC\u062F \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 ${S/(1024*1024)} \u0645\u06AF\u0627\u0628\u0627\u06CC\u062A \u0628\u0627\u0634\u062F`);return}s(L);try{let P=(await C.mutateAsync({file:L}))?.data?.attachments;P&&P.length>0?(f(P),s(null)):(d("\u067E\u0627\u0633\u062E \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0632 \u0633\u0631\u0648\u0631"),s(null));}catch{d("\u062E\u0637\u0627 \u062F\u0631 \u0622\u067E\u0644\u0648\u062F \u0641\u0627\u06CC\u0644. \u0644\u0637\u0641\u0627 \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F."),s(null);}p.target&&(p.target.value="");}},[C,S,I,a]),w=useCallback(()=>{s(null),f([]),d(null);},[]),H=useCallback(()=>{if(I){me.error(a);return}n.current?.click();},[I,a]),q=useCallback(()=>{if(I){me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.");return}let p=r.trim(),L=p.length>0||m.length>0,z=i?.url?p?`${p}
22
- ${i.url}`:`${i.url}`:p;if(L&&j&&l&&g){y(false),M.current&&clearTimeout(M.current);let P=`temp-${Date.now()}`,he={id:P,senderId:J,senderName:"You",content:z,time:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:"\u0627\u0645\u0631\u0648\u0632",createdAt:Date.now(),status:"sending",avatar:ne||""},ge=m.length>0,Re=m.map($=>$.id);if(T(g?._id,he),c(""),f([]),d(null),i){x(null);let $=new URL(window.location.href);$.searchParams.delete("productId"),window.history.replaceState({},"",$.toString());}ge?l.emit("SEND_ATTACHMENT",{targetId:g?.receiverId,text:p||void 0,attachments:Re},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});}):l.emit("SEND_MESSAGE",{targetId:g?.receiverId,content:z,isChatId:g?.type==="Broadcast"},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});});}},[r,j,l,J,T,D,g,y,m,i,I,a]),Z=useCallback(p=>{if(I){me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."),p.preventDefault();return}p.key==="Enter"&&!p.shiftKey&&(q(),p.preventDefault());},[q,I,a]);return g&&jsxs(Stack,{flexDirection:"column",bgcolor:"#E3E3E3",borderRadius:{xs:0,md:2},position:"relative",flex:1,children:[jsx(Stack,{bgcolor:"#F4F4F4",borderBottom:"1px solid #ccc",px:2,flexBasis:"64px",sx:{borderTopRightRadius:{md:"0.75rem"}},justifyContent:"center",alignItems:"flex-start",boxSizing:"content-box",children:jsx(bt,{onBack:t})}),jsx(Stack,{flex:"1 0 0",position:"relative",overflow:"auto",children:jsx(Ft,{messagesEndRef:F,productAttachment:i})}),jsxs(Stack,{sx:{padding:"16px"},position:"relative",onDragOver:p=>{I&&(p.preventDefault(),p.stopPropagation(),me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},onDrop:p=>{I&&(p.preventDefault(),p.stopPropagation(),me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},children:[jsxs(Stack,{children:[i&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",marginBottom:"8px",width:"100%",gap:"1rem",overflow:"hidden"},children:[i.image&&jsx("img",{src:i.image,alt:i.title||"product",style:{width:48,height:48,borderRadius:4,objectFit:"contain",background:"#F4F4F4"}}),jsx(Typography,{variant:"body2",sx:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i.title||i.id}),jsx(IconButton,{size:"small",onClick:()=>{x(null);let p=new URL(window.location.href);p.searchParams.delete("productId"),window.history.replaceState({},"",p.toString());},children:jsx("span",{style:{fontSize:20,lineHeight:1},children:"\xD7"})})]}),(e||m.length>0)&&jsxs(Stack,{sx:{marginBottom:"8px",maxWidth:"100%",width:{xs:"91%",md:"100%"}},children:[e&&jsx(Ke,{attachment:e,onRemove:w}),m.map(p=>jsx(Ke,{attachment:p,onRemove:w},p.id))]}),h&&jsx(Alert,{severity:"error",onClose:()=>d(null),sx:{marginBottom:"8px"},children:h})]}),g?.isBlockedByMe?jsxs(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px"},direction:"row",justifyContent:"center",alignItems:"center",children:[jsx(Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0634\u0645\u0627 \u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0631\u0627 \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0647\u200C\u0627\u06CC\u062F"}),jsx(Button,{variant:"outlined",onClick:()=>{l&&g&&(l.emit("USER_UNBLOCK",{accountId:g.receiverId}),B.getState().unblockUser(g._id));},sx:{borderColor:"#777",color:"#0058CB"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]}):g?.isBlockedByTarget?jsx(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center"},children:jsx(Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0627\u0632 \u0637\u0631\u0641 \u06A9\u0627\u0631\u0628\u0631 \u0645\u0642\u0627\u0628\u0644 \u0645\u0633\u062F\u0648\u062F \u0634\u062F\u0647 \u0627\u0633\u062A"})}):I?jsxs(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px",flexDirection:"row"},justifyContent:"center",alignItems:"center",children:[jsx(NotificationsActive,{sx:{color:"#FF9800"}}),jsx(Typography,{variant:"body2",color:"textSecondary",children:a||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."})]}):jsx(TextField,{fullWidth:true,placeholder:"\u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u06CC\u0646\u062C\u0627 \u0628\u0646\u0648\u06CC\u0633\u06CC\u062F",value:r,multiline:true,maxRows:4,inputRef:o,onChange:O,onKeyDown:Z,sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",fontFamily:"RASMIO","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"},"& textarea":{fontFamily:"RASMIO",overflowY:"auto",maxHeight:"96px",resize:"none",lineHeight:"24px",paddingRight:"40px",paddingLeft:"40px","&::-webkit-scrollbar":{width:"8px"},"&::-webkit-scrollbar-track":{background:"#f1f1f1",borderRadius:"4px"},"&::-webkit-scrollbar-thumb":{background:"#888",borderRadius:"4px"},"&::-webkit-scrollbar-thumb:hover":{background:"#555"}},"& textarea::placeholder":{fontFamily:"RASMIO"}},InputProps:{endAdornment:jsx(InputAdornment,{position:"end",children:r.length>0||m.length>0||C.isLoading?jsx(IconButton,{onClick:q,disabled:C.isLoading||m.length===0&&r.trim().length===0,children:jsx(Send,{sx:{transform:"rotate(180deg)",color:C.isLoading||m.length===0&&r.trim().length===0?"#999":"#0058CB"}})}):jsx(IconButton,{onClick:H,children:jsx(AttachFile,{sx:{color:"#777"}})})})}}),jsx("input",{ref:n,type:"file",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",style:{display:"none"},onChange:u})]}),jsx("div",{ref:F})]})},zt=Fo;var Wt=(t,o)=>useCallback(r=>{let c=o();r!==c?._id&&t?.emit("USER_JOINED",{accountId:r});},[t,o]);var Gt=(t,o,n,r)=>useCallback(e=>{t&&t.emit("GET_MESSAGES",{chatId:e}),o(e),window.history&&window.history.pushState({},"",`?chatId=${e}`),n&&n(),r&&r(false);},[t,o,n,r]);var $t=(t,o,n)=>useMemo(()=>{let r=K(),c=t||[];if(r.companyId){if(!n)return [];let e=Number(r.companyId);if(Number(n.rasmioId)!==e)return []}if(o){let e=String(o).toLowerCase();c.length;c=c.filter(m=>String(m?.title||"").toLowerCase().includes(e));}return c},[t,o,n]);var qt=styled(({className:t,...o})=>jsx(Tooltip,{...o,classes:{popper:t}}))(({theme:t})=>({"& .MuiTooltip-tooltip":{borderRadius:"0.25rem",background:"#1B1B1B",display:"flex",minHeight:"1.5rem",padding:"0.25rem 0.5rem",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"0.625rem",color:"#fff",fontSize:"0.875rem"}})),en=({onChatSelect:t})=>{let[o,n]=useState(null),[r,c]=useState(""),s=!!K().companyId,{accounts:m,chats:f,getActiveAccount:h,setCurrentChat:d,isMy:i}=B(l=>({accounts:l.accounts,chats:l.chats,getActiveAccount:l.getActiveAccount,setCurrentChat:l.setCurrentChat,isMy:l.isMy})),{statusTooltip:x,setStatusTooltip:S}=B(),C=Y(l=>l.socket),F=useTheme(),M=useMediaQuery(F.breakpoints.down("sm")),E=m.some(l=>l?.unreadChatsCount>0),b=Wt(C,h),k=Gt(C,d,t,S),A=m.find(l=>l.isActive),T=$t(f,r,A),D=useRef(null),G=useVirtualizer({count:T?.length||0,getScrollElement:()=>D.current,estimateSize:useCallback(()=>80,[]),overscan:10}),U=useRef(null),g=l=>{if(!(s||m.length<=1||i))if(m.length>1&&!i)n(U.current);else return},j=()=>{n(null);},J=l=>{switch(l){case "online":return "#006D3F";case "disconnected":return "#BD1300";case "reconnecting":return "#ff9800";default:return "#006D3F"}},ne=l=>{switch(l){case "online":return "\u0622\u0646\u0644\u0627\u06CC\u0646";case "disconnected":return "\u0622\u0641\u0644\u0627\u06CC\u0646";case "reconnecting":return "\u062F\u0631 \u062D\u0627\u0644 \u0627\u062A\u0635\u0627\u0644";default:return "\u0622\u0646\u0644\u0627\u06CC\u0646"}};return jsxs(Stack,{sx:{width:M?"100%":"20rem",display:"flex",flexDirection:"column",borderRight:M?"none":"1px solid #ccc",height:"100%",background:"#F4F4F4",borderTopLeftRadius:M?0:"16px",borderBottomLeftRadius:M?0:"16px"},children:[jsxs(Stack,{direction:"row",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 0.75rem",width:"100%",gap:"0.5rem",flexBasis:"64px"},children:[M?x&&jsx(qt,{title:ne(h()?.status),children:jsx(Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}):jsx(qt,{title:ne(h()?.status),children:jsx(Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}),m.length>1&&!i&&!s&&(E?jsx(Badge,{variant:"dot",color:"error",sx:{ml:1,"& .MuiBadge-badge":{right:"auto",left:0,top:"20%",transform:"translateY(-50%)"}},children:jsx(Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer"},onClick:g,children:jsx(ExpandMore,{})})}):jsx(Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer",marginInlineEnd:"0.75rem",marginInlineStart:"0.25rem"},onClick:g,children:jsx(ExpandMore,{})})),M?jsx(Fragment,{children:jsxs(Drawer,{anchor:"bottom",open:!!o,onClose:j,PaperProps:{sx:{maxHeight:"50%",width:"100%",borderTopLeftRadius:"16px",borderTopRightRadius:"16px",padding:"0.5rem"}},children:[jsxs(Stack,{flexDirection:"row",alignItems:"center",justifyContent:"space-between",children:[jsx(Typography,{sx:{fontSize:"1rem",fontWeight:700,padding:"0.5rem 1rem",color:"#1B1B1B"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),jsx(IconButton,{onClick:j,children:jsx(CloseOutlined,{style:{color:"#1B1B1B"}})})]}),m.map(l=>jsxs(MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsx(ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondary:l?.__t==="User"?"":l?.rasmioId}),(l?.unreadChatsCount??0)>0&&jsx(Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{ml:1,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]})}):jsxs(Menu,{anchorEl:o,open:!!o,onClose:j,PaperProps:{sx:{boxShadow:"0px 4px 24px 0px rgba(0, 0, 0, 0.12)",width:"20rem",marginInlineEnd:"4.6rem",marginTop:"1.2rem",padding:"1rem 1rem",borderRadius:"0.75rem"}},anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[jsx(Typography,{variant:"body1",sx:{fontSize:"0.875rem",fontWeight:400,color:"#5E5E5E"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),m.map(l=>jsxs(MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem 0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsx(ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600,marginInlineStart:"0.5rem"},secondary:l?.__t==="User"?"":l?.rasmioId,secondaryTypographyProps:{marginInlineStart:"0.5rem"}}),(l?.unreadChatsCount??0)>0&&jsx(Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{mt:2,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]}),jsx(TextField,{value:r,onChange:l=>c(l.target.value),variant:"outlined",size:"small",placeholder:"\u062C\u0633\u062A\u062C\u0648",sx:{flexGrow:1,borderRadius:"0.5rem",background:"#F4F4F4",border:"0.5px solid #777","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},InputProps:{endAdornment:r&&jsx(Close,{sx:{cursor:"pointer",width:"1.125rem",height:"1.125rem",marginInlineEnd:"0.75rem"},onClick:()=>c("")})}})]}),jsx(Divider,{sx:{marginBottom:"0.75rem"},orientation:"horizontal",flexItem:true}),jsxs(Typography,{sx:{color:"#5E5E5E",fontSize:"0.875rem",fontWeight:"400",padding:"0.75rem"},children:["\u06AF\u0641\u062A \u0648 \u06AF\u0648\u0647\u0627\u06CC ",h()?.displayName]}),jsxs(Stack,{ref:D,sx:{height:`${G.getTotalSize()}px`,flex:1,overflowY:"auto",scrollbarWidth:"none",width:"100%",position:"relative","&::-webkit-scrollbar":{display:"none"},msOverflowStyle:"none"},children:[f.length<1&&jsxs(Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"flex-start",alignItems:"center",height:"100%",marginBlockStart:"8rem",width:"100%",fontFamily:"RASMIO",gap:"0.5rem"},children:[jsx(CommentsDisabledOutlined,{sx:{fontSize:48,color:"#1B1B1B"}}),jsx(Typography,{color:"#1B1B1B",sx:{mb:2},children:"\u0634\u0645\u0627 \u0647\u06CC\u0686 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0641\u0639\u0627\u0644\u06CC \u0646\u062F\u0627\u0631\u06CC\u062F"})]}),jsx(Stack,{sx:{width:"100%",position:"relative"},children:G.getVirtualItems().map(l=>{let I=T[l.index];return jsx(Stack,{"data-index":l.index,ref:G.measureElement,sx:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${l.start}px)`},children:jsxs(ListItem,{onClick:()=>k(I._id),button:true,sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"0.75rem",gap:"0.25rem",backgroundColor:I?.isActive?"#DADADA":"transparent","&:hover":{backgroundColor:"#e0e0e0"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:I?.title,src:I?.avatar}),jsx(ListItemText,{primary:I?.title,secondary:I?.isTyping?"\u062F\u0631 \u062D\u0627\u0644 \u0646\u0648\u0634\u062A\u0646 ...":I?.lastMessage?.content||"",primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondaryTypographyProps:{noWrap:true,color:I?.isTyping?"#006D3F":"#555",fontSize:"0.875rem",fontWeight:400},sx:{marginRight:"1rem"}}),jsxs(Stack,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"1rem",marginLeft:"auto",minWidth:"50px"},children:[I.lastMessage?.createdAt&&jsx(Typography,{variant:"caption",sx:{color:"#999",fontSize:"0.75rem"},children:new Date(I.lastMessage.createdAt).toLocaleDateString("fa-IR")===new Date().toLocaleDateString("fa-IR")?new Date(I.lastMessage.createdAt).toLocaleTimeString("fa-IR",{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:"Asia/Tehran"}):de(new Date(I.lastMessage.createdAt).toISOString())}),!I.isActive&&I?.unReadCount>0&&jsx(Badge,{badgeContent:I.unReadCount,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff",fontSize:"0.75rem",height:"1.25rem",minWidth:"1.25rem"}}})]})]})},l.key)})})]})]})},Vt=en;var nn=memo(({token:t,serviceApi:o,socketUrl:n,baseApi:r,companyId:c})=>{useEffect(()=>{let d={};o&&(d.serviceApi=o),c&&(d.companyId=c),n&&(d.socketUrl=n),r&&(d.baseApi=r),Object.keys(d).length>0&&Je(d);},[o,n,r,c]);let e=B(d=>d.getCurrentChat()),s=B(d=>d.setCurrentChat),m=B(d=>d.chats),f=B(d=>d.refreshBroadcastPermissions),h=Y(d=>d.socket);return useEffect(()=>{let d=new URL(window.location.href),i=d.searchParams.get("chatId");if(!d.searchParams.get("targetCompanyId")&&i&&m.length>0&&h){let S=m.find(C=>C._id===i);S?(!e||e._id!==i)&&(s(i),S.isPreview||h.emit("GET_MESSAGES",{chatId:i})):i.startsWith("preview_chat_")||(d.searchParams.delete("chatId"),window.history.replaceState({},"",d.toString()));}},[m,s,e,h]),useEffect(()=>{let d=i=>{if(i.key==="Escape"&&(s(""),window.history)){let x=new URL(window.location.href);x.searchParams.delete("chatId"),window.history.pushState({},"",x.toString());}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),useEffect(()=>{f();},[f,e?._id]),jsx(QueryClientProvider,{client:pt,children:jsx(Ze,{token:t,children:jsx(mt,{children:jsx(at,{socketUrl:n,children:jsxs(Grid,{flexDirection:"row",bgcolor:"#E3E3E3",borderRadius:"16px",width:"100%",marginBlockStart:"1rem",flex:1,container:true,position:"relative",sx:{overflow:"hidden",minHeight:"500px"},children:[jsx(Grid,{item:true,width:{xs:"100%",sm:"unset"},sx:{display:e?{xs:"none",sm:"block"}:"block"},children:jsx(Vt,{})}),jsx(Grid,{item:true,flex:1,position:{xs:"absolute",sm:"relative"},display:e?"flex":"none",sx:{inset:0,zIndex:e?10:-1,visibility:e?"visible":"hidden"},children:jsx(zt,{})})]})})})})})},(t,o)=>t.token===o.token&&t.serviceApi===o.serviceApi&&t.socketUrl===o.socketUrl);
20
+ var B=create((t,r)=>({accounts:[],chats:[],statusTooltip:true,isMy:false,broadcastState:null,addPreviewChat:n=>{let o=`preview_chat_${n.receiverId}`;if(r().chats.find(e=>e._id===o)){r().setCurrentChat(o);return}t(e=>({chats:[{_id:o,avatar:n.avatar,messages:[],isActive:true,unReadCount:0,status:n.status,title:n.displayName,receiverId:n.receiverId,isPreview:true,isBot:false,lastSeen:n.lastActive},...e.chats.map(s=>({...s,isActive:false}))]}));},updateChatStatus:(n,o)=>{t(c=>({accounts:c.accounts.map(e=>e._id===n?{...e,status:o}:e)}));},setActiveAccount:n=>{let{accounts:o}=r();if(!o.find(s=>s._id===n)){console.warn("[setActiveAccount] Account not found:",n);return}let e=o.map(s=>({...s,isActive:s._id===n}));t({accounts:e}),r().refreshBroadcastPermissions();},setAccounts:n=>{t({accounts:n});},setChats:n=>t(()=>{let o=r().getActiveAccount(),c=r().broadcastState,s=r().chats.filter(i=>i.isPreview&&!n.some(x=>x._id===i._id)),f=n.map(i=>{let x=!!(i?.type==="Broadcast"||i?.isDefaultBroadcast),S=i?.isBot===true,F=i?.ownerId||(typeof i?.owner=="object"?i?.owner?._id:void 0)||c?.ownerId||void 0,M=x&&F?F===(o?._id??""):true,E=S?false:x?M:i?.canSendMessages??true,b=i?.composerHint||(S?"\u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u062A\u0648\u0633\u0637 \u0631\u0628\u0627\u062A \u0645\u062F\u06CC\u0631\u06CC\u062A \u0645\u06CC\u200C\u0634\u0648\u062F \u0648 \u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":E?void 0:"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.");return {...i,ownerId:F,isTyping:false,canSendMessages:E,composerHint:b,isBot:S}}).sort((i,x)=>{let S=!!(i.type==="Broadcast"||i.isDefaultBroadcast),C=!!(x.type==="Broadcast"||x.isDefaultBroadcast);return S&&!C?-1:C&&!S?1:0}),h=[...s,...f],d=f.find(i=>i.type==="Broadcast"||i.isDefaultBroadcast);return {chats:h,broadcastState:d?{chatId:d._id,ownerId:d.ownerId,isDefault:!!d.isDefaultBroadcast}:null}}),getActiveAccount:()=>{let{accounts:n}=r();return n.find(o=>o.isActive)},setCurrentChat:n=>{t(o=>({accounts:o.accounts.map(e=>({...e,unreadChatsCount:e.isActive&&e.unreadChatsCount&&e.unreadChatsCount>0?e.unreadChatsCount-1:e.unreadChatsCount})),chats:o.chats.map(e=>({...e,isActive:e._id===n,unReadCount:e._id===n?0:e.unReadCount,messages:e._id===n?e.messages.map(s=>({...s,hasSeen:true})):e.messages}))}));},getCurrentChat:()=>{let{chats:n}=r();return n.find(o=>o.isActive)??null},addMessageToChat:(n,o)=>{t(c=>{let e=c.chats.findIndex(m=>m._id===n),s=[...c.chats];if(e!==-1){let m=s[e];if(m.messages.some(d=>d.id===o.id)){if(o.id.startsWith("temp-")===false&&m.messages.some(i=>i.id.startsWith("temp-"))){let i=m.messages.map(S=>S.id.startsWith("temp-")&&S.content===o.content&&Math.abs(S.createdAt-o.createdAt)<5e3?o:S),x={...m,lastMessage:o,messages:i};return s.splice(e,1),s.unshift(x),{chats:s}}return c}let h={...s[e],lastMessage:o,messages:[...s[e].messages,o]};return s.splice(e,1),s.unshift(h),{chats:s}}else {let m=c.chats.findIndex(f=>f.isPreview&&f.receiverId===o.senderId);if(m!==-1){let f=s[m],h={...f,_id:n,isPreview:false,lastMessage:o,messages:[...f.messages,o]};return s.splice(m,1),s.unshift(h),{chats:s}}else return {chats:[{_id:n,lastMessage:o,messages:[o],avatar:o.avatar,isActive:false,title:o.senderName,receiverId:o.senderId,unReadCount:0,lastSeen:new Date().toISOString()},...c.chats]}}});},updateMessageInChat:(n,o,c)=>{t(e=>{let s=e.chats.findIndex(x=>x._id===n);if(s===-1)return e;let m=[...e.chats],f=m[s],h=f.messages.findIndex(x=>x.id===o);if(h===-1)return e;let d=[...f.messages];d[h]={...d[h],...c};let i={...f,messages:d,lastMessage:h===d.length-1?d[h]:f.lastMessage};return m[s]=i,{chats:m}});},setMessagesForChat:(n,o)=>{t(c=>{let e=c.chats.findIndex(s=>s._id===n);if(e!==-1){let s=[...c.chats];return s[e].messages=o,o.length>0&&(s[e].lastMessage=o[o.length-1]),{chats:s}}else return console.warn(`Chat with ID ${n} not found. Messages not set.`),{}});},setTypingStatus:(n,o)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,isTyping:o}:e)})),setStatusTooltip:n=>t({statusTooltip:n}),blockUser:n=>{t(o=>({chats:o.chats.map(c=>c._id===n?{...c,isBlockedByMe:true}:c)}));},unblockUser:n=>{t(o=>({chats:o.chats.map(c=>c._id===n?{...c,isBlockedByMe:false}:c)}));},updateChatBlockStatus:(n,o,c)=>{t(e=>({chats:e.chats.map(s=>s._id===n?{...s,isBlockedByMe:o,isBlockedByTarget:c}:s)}));},setIsMy:n=>t({isMy:n}),setBroadcastState:n=>t({broadcastState:n}),refreshBroadcastPermissions:()=>{let{broadcastState:n}=r();if(!n)return;let o=r().getActiveAccount();t(c=>({chats:c.chats.map(e=>{if(e._id!==n.chatId)return e;let s=n.ownerId?n.ownerId===(o?._id??""):false;return {...e,canSendMessages:s,composerHint:s?void 0:e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."}})}));},updateChatPermissions:(n,o)=>t(c=>({chats:c.chats.map(e=>e._id===n?{...e,...o,composerHint:o.canSendMessages===false?o.composerHint||e.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":o.composerHint}:e)}))}));var Y=create(t=>({socket:null,socketConnect:r=>t({socket:r}),socketDisconnect:()=>t({socket:null})}));var fe=create(t=>({token:"",setToken:r=>t({token:r})}));var no={serviceApi:"https://gwdev.rasmio.com/api/chat/",socketUrl:"wss://devsocket.rasmio.com/chat",baseApi:"https://gwdev.rasmio.com/api/"},ye={...no},Fe=new Set,K=()=>ye,Je=t=>(ye={...ye,...Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0))},Fe.forEach(r=>r(ye)),ye);var Qe=t=>(Fe.add(t),()=>Fe.delete(t));var{serviceApi:io}=K(),ce=ao.create({adapter:"fetch",baseURL:io,timeout:2e4});Qe(t=>{ce.defaults.baseURL=t.serviceApi;});var co=({children:t,token:r})=>{let n=fe(o=>o.setToken);return useEffect(()=>{r&&(n(r),ce.defaults.headers.common.Authorization=`Bearer ${r}`);},[r]),r?t:null},Ze=co;var et=(t,r)=>{let{current:n}=useRef(io$1(t,r));return n};be.extend(mo);be.extend(po);be.extend(ho);var de=t=>{let r=be(t).calendar("jalali").locale("fa"),n=be().calendar("jalali").locale("fa");return r.isSame(n,"day")?"\u0627\u0645\u0631\u0648\u0632":r.isSame(n.subtract(1,"day"),"day")?"\u062F\u06CC\u0631\u0648\u0632":r.year()===n.year()?r.format("D MMMM"):r.format("D MMMM YYYY")};var fo=({children:t,socketUrl:r})=>{let n=fe(a=>a.token),o=useMemo(()=>r||"wss://devsocket.rasmio.com/chat",[r]),{socketConnect:c}=Y(useShallow(a=>({socketConnect:a.socketConnect}))),e=et(o,{transports:["websocket"],reconnectionAttempts:3,reconnectionDelay:3e3,withCredentials:false,autoConnect:false,upgrade:false,auth:{token:`Bearer ${n}`}}),{setAccounts:s,setChats:m,addMessageToChat:f,setMessagesForChat:h,setActiveAccount:d,currentChat:i,setCurrentChat:x,addPreviewChat:S,accounts:C,updateChatStatus:F,updateChatBlockStatus:M,setIsMy:E,refreshBroadcastPermissions:b,updateChatPermissions:k}=B(useShallow(a=>({setAccounts:a.setAccounts,setChats:a.setChats,addMessageToChat:a.addMessageToChat,setMessagesForChat:a.setMessagesForChat,setActiveAccount:a.setActiveAccount,currentChat:a.getCurrentChat(),setCurrentChat:a.setCurrentChat,addPreviewChat:a.addPreviewChat,accounts:a.accounts,updateChatStatus:a.updateChatStatus,updateChatBlockStatus:a.updateChatBlockStatus,setIsMy:a.setIsMy,refreshBroadcastPermissions:a.refreshBroadcastPermissions,updateChatPermissions:a.updateChatPermissions}))),A=useRef(false),T=useRef(new Set);useEffect(()=>{let y=K().companyId;if(!y||!e||C.length===0||!e.connected)return;let O=C.find(w=>String(w.rasmioId)===String(y));!O||C.find(w=>w.isActive)?._id===O._id||e.emit("USER_JOINED",{accountId:O._id});},[e,C]);let D=useCallback(a=>{let y=B.getState().getActiveAccount(),O={id:a._id,senderId:a.sender._id,senderName:a.sender.displayName,avatar:a.sender.avatar,content:a.content,time:new Date(a.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(a.createdAt),createdAt:new Date(a.createdAt).getTime(),hasSeen:a.hasSeen,attachments:a.attachments?a.attachments.map(u=>({id:u._id||u.id,url:u.url,thumbnailUrl:u.thumbnailUrl,signedUrl:u.signedUrl,thumbnailSignedUrl:u.thumbnailSignedUrl,mimeType:u.mimeType,size:u.size,originalName:u.originalName,sha256:u.sha256,width:u.width,height:u.height,durationSec:u.durationSec})):[],buttons:a.buttons||[]};if(a.sender._id===y?._id){let u=B.getState(),w=u.chats.find(H=>H._id===a.chatId);if(w){let H=w.messages.find(q=>q.id===a._id||q.id.startsWith("temp-")&&q.content===a.content);if(H){u.updateMessageInChat(a.chatId,H.id,O);return}}}f(a.chatId,O);},[f]),G=useCallback(a=>{let O=K().companyId,u=new URL(window.location.href),w=a.find(P=>P.__t==="User"),H=u.searchParams.has("cmp"),q=u.searchParams.get("my")==="true",Z=a.find(P=>P.__t==="Company"),p=u.searchParams.get("cmp");E(q);let L=O||p,z=L?a.find(P=>String(P?.rasmioId)===String(L)):void 0;if(L&&z&&!A.current)e.emit("USER_JOINED",{accountId:z._id}),A.current=true,p&&(u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString()));else if(w&&!A.current&&!H&&!q&&!L){e.emit("USER_JOINED",{accountId:w._id}),A.current=true;let P=u.searchParams.get("targetCompanyId");P&&!T.current.has(P)&&(T.current.add(P),e.emit("ACCOUNT_INFO",{id:P}),setTimeout(()=>{let he=new URL(window.location.href);he.searchParams.get("targetCompanyId")===P&&(he.searchParams.delete("targetCompanyId"),window.history.replaceState({},document.title,he.toString()),me.error("\u0627\u0645\u06A9\u0627\u0646 \u0628\u0627\u0632 \u06A9\u0631\u062F\u0646 \u06AF\u0641\u062A\u06AF\u0648 \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F"));},5e3));}else if(!A.current){let P=Z;e.emit("USER_JOINED",{accountId:P?._id}),A.current=true,u.searchParams.delete("cmp"),window.history.replaceState({},document.title,u.toString());}u.searchParams.has("my")&&(u.searchParams.delete("my"),window.history.replaceState({},document.title,u.toString())),s(a);},[e,s,E]),U=useCallback(a=>{let y=a.map(w=>({...w,messages:w.messages||[],unReadCount:w.unReadCount||0}));m(y),b();let u=new URL(window.location.href).searchParams.get("chatId");u&&y.find(H=>H._id===u)&&!B.getState().getCurrentChat()&&(x(u),e&&e.emit("GET_MESSAGES",{chatId:u}));},[m,b,x,e]),g=useCallback(a=>{d(a);},[d]),j=useCallback(a=>{let y=a?.message||a?.payload?.message||a?.payload?.reason||a?.data?.message||"\u062E\u0637\u0627\u06CC \u0646\u0627\u0645\u0634\u062E\u0635 \u0631\u062E \u062F\u0627\u062F\u0647 \u0627\u0633\u062A";me.error(y);let O=a?.chatId||a?.payload?.chatId||a?.data?.chatId||a?.meta?.chatId;!O||!(a?.code&&["BROADCAST_READ_ONLY","CHAT_PERMISSION_DENIED"].includes(a.code)||y.toLowerCase().includes("broadcast")||y.toLowerCase().includes("\u0627\u062C\u0627\u0632\u0647"))||k(O,{canSendMessages:false,composerHint:y});},[k]),J=useCallback(a=>{let O=a.map(u=>({id:u._id,senderId:u.sender._id,senderName:u.sender.displayName,avatar:u.sender.avatar,content:u.content,time:new Date(u.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:de(u.createdAt),createdAt:new Date(u.createdAt).getTime(),hasSeen:u.hasSeen,attachments:u.attachments?u.attachments.map(w=>({id:w._id||w.id,url:w.url,thumbnailUrl:w.thumbnailUrl,signedUrl:w.signedUrl,thumbnailSignedUrl:w.thumbnailSignedUrl,mimeType:w.mimeType,size:w.size,originalName:w.originalName,sha256:w.sha256,width:w.width,height:w.height,durationSec:w.durationSec})):[],buttons:u.buttons||[]})).sort((u,w)=>u.createdAt-w.createdAt);i&&h(i._id,O);},[i,h]),ne=useCallback(a=>{let y=B.getState(),O=y.chats.find(H=>H._id===a.chatId);if(a.receiverId){let H=`preview_chat_${a.receiverId}`;y.chats.find(Z=>Z._id===H)&&B.setState(Z=>({chats:Z.chats.filter(p=>p._id!==H)}));}if(O)x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId});else {let H=setInterval(()=>{B.getState().chats.find(Z=>Z._id===a.chatId)&&(clearInterval(H),x(a.chatId),e?.emit("GET_MESSAGES",{chatId:a.chatId}));},100);setTimeout(()=>clearInterval(H),3e3);}let u=new URL(window.location.href),w=false;u.searchParams.has("targetCompanyId")&&(u.searchParams.delete("targetCompanyId"),w=true),(w||!u.searchParams.has("chatId"))&&(u.searchParams.set("chatId",a.chatId),window.history.replaceState({},document.title,u.toString()));},[x,e]),l=useCallback(a=>{S(a);let y=new URL(window.location.href);y.searchParams.has("targetCompanyId")&&(y.searchParams.delete("targetCompanyId"),true);let u=`preview_chat_${a.receiverId}`;y.searchParams.set("chatId",u),window.history.replaceState({},document.title,y.toString());},[S]),I=useCallback(a=>{M(a.chatId,a.isBlockedByMe,a.isBlockedByTarget);},[M]);return useEffect(()=>(e.connected||(e.connect(),c(e)),e.on("USER_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,true);}),e.on("USER_FINISH_TYPING",a=>{let y=B.getState();y.chats.find(u=>u._id===a.chatId)&&y.setTypingStatus(a.chatId,false);}),e.on("NEW_MESSAGE",D),e.on("CHAT_MESSAGES",J),e.on("ACCOUNT_LIST",G),e.on("CHAT_LIST",U),e.on("ACCOUNT_SWITCHED",g),e.on("ERROR_OCCURED",j),e.on("OPEN_CHAT",ne),e.on("PREVIEW_CHAT",l),e.on("BLOCK_STATUS_UPDATED",I),e.on("connect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"online");}),e.on("disconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"disconnected");}),e.on("reconnect",()=>{let a=C.find(y=>y.isActive);a&&F(a._id,"reconnecting");}),()=>{e.off("NEW_MESSAGE",D),e.off("CHAT_MESSAGES",J),e.off("ACCOUNT_LIST",G),e.off("CHAT_LIST",U),e.off("ACCOUNT_SWITCHED",g),e.off("ERROR_OCCURED",j),e.off("USER_TYPING"),e.off("USER_FINISH_TYPING"),e.off("OPEN_CHAT",ne),e.off("PREVIEW_CHAT",l),e.off("BLOCK_STATUS_UPDATED",I),e?.off("connect"),e?.off("disconnect"),e?.off("reconnect");}),[e,c,D,J,G,U,g,j,ne,l,I,C,F]),e?jsx(Fragment,{children:t}):null},at=fo;var bo=()=>jsx(Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",background:"#E3E3E3",borderRadius:"16px",height:"100vh"},children:jsx(Player,{src:"/lottie/waiting.json",autoplay:true,loop:true,style:{width:"5rem",height:"5rem"}})}),st=bo;var ct={challenge:"challenge"};var wo=async t=>(await ce.post("/authentication/challenge",t)).data,dt=()=>useMutation({mutationFn:wo,mutationKey:[ct.challenge]});var ko=({children:t})=>{let[r,n]=useState(true),[o,c]=useState(false),{mutate:e}=dt(),s=()=>{fe.setState({token:""}),Y.setState({socket:null}),B.setState({accounts:[],chats:[],statusTooltip:true});};return useEffect(()=>{s();let m=window.location.search,h=new URLSearchParams(m).get("targetCompanyId");e(h?{targetCompanyId:h}:{},{onSuccess:d=>{d.data?n(false):c(true);},onError:d=>{c(true);}});},[]),o?jsx(Fragment,{children:"Error"}):r?jsx(st,{}):jsx(Fragment,{children:t})},mt=ko;var pt=new QueryClient({});var _o=()=>{let t=B(U=>U.getCurrentChat()),r=B(U=>U.setCurrentChat),{setStatusTooltip:n,blockUser:o,unblockUser:c}=B(),e=Y(U=>U.socket),[s,m]=useState(null),[f,h]=useState(false),[d,i]=useState(false),x=()=>{if(r(""),n(true),window.history){let U=new URL(window.location.href);U.searchParams.delete("chatId"),window.history.pushState({},"",U.toString());}},S=U=>{m(U.currentTarget);},C=()=>{m(null);},F=()=>{C(),h(true);},M=()=>{C(),i(true);},E=()=>{h(false);},b=()=>{i(false);},k=()=>{t&&e&&(e.emit("USER_BLOCK",{accountId:t.receiverId}),o(t._id)),h(false);},A=()=>{t&&e&&(e.emit("USER_UNBLOCK",{accountId:t.receiverId}),c(t._id)),i(false);};if(!t)return jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,width:"100%",children:[jsx(Skeleton,{variant:"circular",width:48,height:48}),jsxs(Stack,{flex:1,spacing:.5,children:[jsx(Skeleton,{variant:"text",width:"40%",height:16}),jsx(Skeleton,{variant:"text",width:"20%",height:12})]})]});let T=t?.title?.trim()||"\u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u062C\u062F\u06CC\u062F",D=t?.isBot===true?"":t?.status==="online"?"\u0622\u0646\u0644\u0627\u06CC\u0646":t?.lastSeen?`\u0622\u062E\u0631\u06CC\u0646 \u0628\u0627\u0632\u062F\u06CC\u062F : ${de(new Date(t.lastSeen).toISOString())}`:"";return jsxs(Fragment,{children:[jsxs(Stack,{alignItems:"center",justifyContent:"flex-start",flexDirection:"row",width:"100%",children:[jsx(Stack,{display:{xs:"flex",md:"none"},children:jsx(IconButton,{sx:{color:"#1B1B1B"},onClick:x,children:jsx(ArrowForward,{})})}),t?.avatar?jsx("img",{width:48,height:48,style:{borderRadius:"4px",objectFit:"cover"},alt:T,src:t.avatar}):jsx(Avatar,{sx:{width:48,height:48,bgcolor:"#0058CB",fontWeight:600},children:T.charAt(0)||"\u061F"}),jsxs(Stack,{marginLeft:"0.5rem",flex:1,children:[jsx(Typography,{variant:"body1",color:"#1B1B1B",children:T}),D&&jsx(Typography,{variant:"body2",color:t?.status==="online"?"#006D3F":"textSecondary",children:D})]}),jsx(Stack,{flex:1,alignItems:"flex-end",children:jsx(IconButton,{sx:{color:"#1B1B1B"},onClick:S,children:jsx(MoreVert,{})})})]}),jsx(Menu,{anchorEl:s,open:!!s,onClose:C,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:t?.isBlockedByMe?jsxs(MenuItem,{onClick:M,children:[jsx(ListItemIcon,{sx:{color:"green"},children:jsx(BlockOutlined,{fontSize:"small"})}),jsx(ListItemText,{primary:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A",sx:{color:"green"}})]}):jsxs(MenuItem,{onClick:F,children:[jsx(ListItemIcon,{sx:{color:"red"},children:jsx(BlockOutlined,{fontSize:"small"})}),jsx(ListItemText,{primary:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646",sx:{color:"red"}})]})}),jsxs(Dialog,{open:f,onClose:E,maxWidth:"xs",PaperProps:{sx:{borderRadius:"16px"}},"aria-labelledby":"block-dialog-title",children:[jsxs(DialogTitle,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px"},children:[jsx(Typography,{variant:"h6",children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"}),jsx(IconButton,{onClick:E,children:jsx(Close,{})})]}),jsx(DialogContent,{children:jsxs(Typography,{variant:"body1",gutterBottom:true,children:["\u062F\u0631\u0635\u0648\u0631\u062A \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646\u060C \u06A9\u0627\u0631\u0628\u0631 \u0645\u0648\u0631\u062F\u0646\u0638\u0631 \u0646\u0645\u06CC\u200C\u062A\u0648\u0627\u0646\u062F \u0628\u0647 \u0634\u0645\u0627 \u067E\u06CC\u0627\u0645 \u0628\u062F\u0647\u062F. \u0622\u06CC\u0627 \u0627\u0632 \u0627\u06CC\u0646 \u06A9\u0627\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"," "]})}),jsxs(DialogActions,{sx:{gap:"1rem"},children:[jsx(Button,{onClick:E,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsx(Button,{onClick:k,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem",background:"#BD1300",color:"#fff","&:hover":{background:"#BD1300",color:"#fff"}},children:"\u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0646"})]})]}),jsxs(Dialog,{open:d,onClose:b,maxWidth:"xs","aria-labelledby":"unblock-dialog-title",PaperProps:{sx:{borderRadius:"16px"}},children:[jsx(DialogContent,{children:jsx(Typography,{variant:"body1",gutterBottom:true,children:"\u0622\u06CC\u0627 \u0627\u0632 \u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A \u0627\u06CC\u0646 \u06A9\u0627\u0631\u0628\u0631 \u0627\u0637\u0645\u06CC\u0646\u0627\u0646 \u062F\u0627\u0631\u06CC\u062F\u061F"})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:b,variant:"text",children:"\u0627\u0646\u0635\u0631\u0627\u0641"}),jsx(Button,{onClick:A,sx:{padding:"0.75rem 1rem",borderRadius:"0.5rem"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]})]})]})},bt=_o;var Lo=({date:t})=>jsxs(Box,{sx:{display:"flex",alignItems:"center",marginY:"16px"},children:[jsx(Divider,{sx:{flexGrow:1}}),jsx(Typography,{variant:"body2",sx:{marginX:"8px",padding:"0.25rem 0.75rem",background:"#F4F4F4",borderRadius:"1rem"},children:t}),jsx(Divider,{sx:{flexGrow:1}})]}),wt=memo(Lo);var Ko=({attachment:t,isMe:r})=>{let[n,o]=useState(false),c=t.isProductPreview||t.mimeType==="product/preview",e=t.mimeType?.startsWith("image/")||false,s=t.signedUrl||t.url,m=t.thumbnailSignedUrl||s,f=i=>!i||i<1024?(i||0)+" B":i<1024*1024?(i/1024).toFixed(1)+" KB":(i/(1024*1024)).toFixed(1)+" MB",h=()=>t.mimeType?.startsWith("image/")?jsx(Image,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("video/")?jsx(VideoLibrary,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType?.startsWith("audio/")?jsx(AudioFile,{sx:{width:24,height:24,color:"#1B1B1B"}}):t.mimeType==="application/pdf"?jsx(PictureAsPdf,{sx:{width:24,height:24,color:"#1B1B1B"}}):jsx(AttachmentOutlined,{sx:{width:24,height:24,color:"#1B1B1B"}}),d=()=>{let i=document.createElement("a");i.href=s,i.download=t.originalName,i.target="_blank",document.body.appendChild(i),i.click(),document.body.removeChild(i);};return c?jsxs(Box,{component:"a",href:t.productUrl||t.url,target:"_blank",rel:"noopener noreferrer",sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"0.75rem",padding:"0.75rem",borderRadius:"0.5rem",border:`1px solid ${r?"rgba(255,255,255,0.2)":"#E0E0E0"}`,background:r?"rgba(255,255,255,0.1)":"#F4F4F4",textDecoration:"none",maxWidth:"350px",cursor:"pointer",transition:"all 0.2s ease","&:hover":{background:r?"rgba(255,255,255,0.15)":"#EEEEEE"}},children:[t.productImage&&jsx(Box,{component:"img",src:t.productImage,alt:t.productTitle||"Product",sx:{width:60,height:60,borderRadius:"0.375rem",objectFit:"cover",flexShrink:0}}),jsx(Stack,{flex:1,minWidth:0,children:jsx(Typography,{variant:"body2",sx:{fontWeight:600,color:r?"white":"#1B1B1B",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"0.25rem"},children:t.productTitle||t.originalName})})]}):e?jsxs(Fragment,{children:[jsxs(Box,{sx:{position:"relative",maxWidth:"300px",cursor:"pointer",borderRadius:"8px",overflow:"hidden"},onClick:()=>o(true),children:[jsx(Box,{component:"img",src:m,alt:t.originalName,sx:{width:"100%",height:"auto",maxHeight:"300px",objectFit:"cover",display:"block"}}),t.width&&t.height&&jsxs(Box,{sx:{position:"absolute",bottom:4,right:4,background:"rgba(0,0,0,0.5)",color:"white",padding:"2px 6px",borderRadius:"4px",fontSize:"10px"},children:[t.width," \xD7 ",t.height]})]}),n&&jsxs(Box,{sx:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.9)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:2},onClick:()=>o(false),children:[jsx(IconButton,{sx:{position:"absolute",top:16,right:16,color:"white"},onClick:()=>o(false),children:jsx(Close,{})}),jsx(IconButton,{sx:{position:"absolute",top:16,left:16,color:"white"},onClick:i=>{i.stopPropagation(),d();},children:jsx(Download,{})}),jsx(Box,{component:"img",src:s,alt:t.originalName,sx:{maxWidth:"90%",maxHeight:"90%",objectFit:"contain"},onClick:i=>i.stopPropagation()})]})]}):jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:r?"rgba(255,255,255,0.1)":"#F4F4F4",borderRadius:"0.5rem",padding:"0.75rem",gap:"0.5rem",maxWidth:"300px",cursor:"pointer",border:r?"1px solid rgba(255,255,255,0.2)":"1px solid #E0E0E0"},onClick:d,children:[jsx(Box,{sx:{width:40,height:40,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:r?"#E3E3E3":"##E3E3E3",color:r?"white":"inherit"},children:h()}),jsxs(Stack,{flex:1,minWidth:0,children:[jsx(Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500,color:r?"white":"inherit"},children:t.originalName}),jsx(Typography,{variant:"caption",sx:{color:r?"rgba(255,255,255,0.7)":"textSecondary"},children:f(t.size)})]}),jsx(IconButton,{size:"small",sx:{color:r?"white":"inherit"},children:jsx(Download,{sx:{width:20,height:20}})})]})},Ge=Ko;var Zo=({content:t,isMe:r,hasOpenGraph:n=false})=>{let o=t.replace(/\n/g,`
21
+ `);return jsx(Box,{sx:{"& p":{margin:0,marginBottom:"0.5em","&:last-child":{marginBottom:0}},"& a":{color:r?"#FFFFFF":"#1976d2",textDecoration:"underline !important","&:hover":{textDecoration:"underline !important"}},"& code":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.2em 0.4em",borderRadius:"3px",fontSize:"0.9em",fontFamily:"monospace"},"& pre":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",padding:"0.75em",borderRadius:"4px",overflow:"auto",margin:"0.5em 0","& code":{backgroundColor:"transparent",padding:0}},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& ul, & ol":{margin:"0.5em 0",paddingLeft:"1.5em"},"& li":{marginBottom:"0.25em"},"& blockquote":{borderLeft:`3px solid ${r?"rgba(255, 255, 255, 0.3)":"rgba(0, 0, 0, 0.2)"}`,paddingLeft:"1em",marginLeft:0,marginRight:0,fontStyle:"italic",opacity:.9},"& h1, & h2, & h3, & h4, & h5, & h6":{margin:"0.5em 0 0.3em 0",fontWeight:600},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& hr":{border:"none",borderTop:`1px solid ${r?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,margin:"0.75em 0"},"& table":{borderCollapse:"collapse",width:"100%",margin:"0.5em 0"},"& th, & td":{border:`1px solid ${r?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"}`,padding:"0.5em",textAlign:"left"},"& th":{backgroundColor:r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",fontWeight:600},direction:"auto"},children:jsx(Vo,{remarkPlugins:[Jo],components:{a:({node:c,...e})=>jsx("a",{...e,target:"_blank",rel:"noopener noreferrer"})},children:o})})},kt=memo(Zo);var cr=({message:t,activeUserId:r,othersAvatar:n})=>{let o=Y(C=>C.socket),c=B(C=>C.getCurrentChat()),e=t.senderId===r,{baseApi:s}=K(),m=useTheme(),f=useMediaQuery(m.breakpoints.down("sm")),h=n,[d,i]=useState(null),[x,S]=useState(null);return useEffect(()=>{!e&&o&&c?._id&&o?.emit("SEEN_CHAT",{chatId:c._id});},[e,o,c?._id]),useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(!M||M.length===0){S(null);return}let E=M[0],b=null;try{let A=new URL(E).searchParams.get("productId");if(A)b=Number(A);else if(E.includes("/product/")){let T=E.match(/\/product\/(\d+)/);T&&(b=Number(T[1]));}}catch{S(null);return}if(!b||Number.isNaN(b)){S(null);return}try{let k=await fetch(`${s}Catalog/Products/${b}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!k.ok)throw new Error("Failed to load product");let A=await k.json(),T=A?.value||A,D=T?.name||T?.titleFa||String(b),G=(T?.images||[]).find(g=>g?.isMain)?.url||T?.images?.[0]?.url,U=`https://rasmio.com/product/${b}`;S({id:`product-${b}`,url:U,thumbnailUrl:G,signedUrl:U,thumbnailSignedUrl:G,mimeType:"product/preview",size:0,originalName:D,isProductPreview:!0,productTitle:D,productImage:G,productUrl:U});}catch(k){console.error("Error fetching product data:",k),S(null);}})(),()=>{S(null);}),[t.content,t.id]),useEffect(()=>((async()=>{let F=/(https?:\/\/[^\s]+)/g,M=t.content.match(F);if(M&&M.length>0){let E=M[0];if(E.includes("productId=")||E.includes("/product/")){i(null);return}try{let A=await(await fetch(`${s}v3/OpenGraph/GetOpenGraph?url=${encodeURIComponent(E)}`)).json();A&&(A.title||A.description||A.image)?i({title:A.title,description:A.description,image:A.image,url:E}):i(null);}catch(k){console.error("Error fetching OpenGraph data:",k),i(null);}}else i(null);})(),()=>{i(null);}),[t.content,t.id,s]),jsx(Box,{display:"flex",justifyContent:e?"flex-start":"flex-end",marginY:f?"16px":"8px",paddingX:"8px",children:jsxs(Box,{display:"flex",flexDirection:e?"row":"row-reverse",alignItems:"flex-start",maxWidth:f?"100%":"70%",children:[!e&&jsx("img",{src:h,alt:e?"You":t.senderName,style:{width:40,height:40,borderRadius:"4px"}}),jsxs(Box,{display:"flex",flexDirection:"column",alignItems:e?"flex-start":"flex-end",marginX:"8px",children:[jsxs(Box,{sx:{backgroundColor:e?"#0058CB":"#FFFFFF",color:e?"#FFFFFF":"#000000",padding:"0.75rem 1rem",borderRadius:e?"0 0.5rem 0.5rem 0.5rem":"0.5rem 0 0.5rem 0.5rem",wordBreak:"break-word"},children:[t?.attachments&&t?.attachments?.length>0&&jsx(Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:t?.attachments?.map(C=>jsx(Ge,{attachment:C,isMe:e},C.id))}),x&&jsx(Stack,{spacing:1,sx:{marginBottom:t?.content?1:0},children:jsx(Ge,{attachment:x,isMe:e})}),t?.content&&jsx(Box,{sx:{direction:"auto"},children:jsx(kt,{content:t.content,isMe:e,hasOpenGraph:!!d})}),d&&jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"0.25rem 0.5rem 0 0.25rem",display:"flex",textDecoration:"underline !important",width:"100%",alignItems:"flex-start",borderRight:"3px solid #C7C7C7",gap:"0.5rem",marginTop:"0.5rem"},children:[d.image&&jsx("img",{src:d.image,alt:d.title,style:{width:"3rem",height:"3rem",borderRadius:"4px",marginBottom:1,marginLeft:1}}),jsxs(Stack,{direction:"column",gap:.5,flex:1,children:[jsx(Typography,{sx:{fontWeight:"bold",direction:"auto"},children:d.title}),d.description&&jsxs(Typography,{sx:{display:"block",opacity:.8,direction:"auto"},children:[d.description.substring(0,100),"..."]})]})]})]}),t?.buttons&&t.buttons.length>0&&jsx(Stack,{spacing:1,sx:{marginTop:"8px",width:"100%"},children:t.buttons.map((C,F)=>jsx(Button,{variant:"contained",fullWidth:true,href:C.link,target:"_blank",rel:"noopener noreferrer",sx:{textTransform:"none",padding:"8px 16px",fontSize:"0.875rem",fontWeight:500},children:C.text},F))}),jsxs(Box,{sx:{marginTop:"4px",display:"flex",alignItems:"center",justifyContent:"center",gap:"0.38rem"},children:[jsx(Typography,{variant:"caption",color:"textSecondary",sx:{direction:"auto"},children:t.time}),e&&jsxs(Fragment,{children:[!t.hasSeen&&jsx(Check,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.hasSeen&&jsx(DoneAll,{style:{color:"#006D3F",width:"1rem",height:"1rem"}}),t.status==="sending"&&jsx(AccessTime,{style:{color:"#FFA500",width:"1rem",height:"1rem"}}),t.status==="failed"&&jsx(ErrorOutline,{style:{color:"#FF0000",width:"1rem",height:"1rem"}})]})]})]})]})})},Bt=memo(cr);var _t=t=>{if(!t)return "";let r=t.trim(),n=new Date;if(n.setHours(0,0,0,0),r==="\u0627\u0645\u0631\u0648\u0632"||r.toLowerCase()==="today")return n.toDateString();if(r==="\u062F\u06CC\u0631\u0648\u0632"||r.toLowerCase()==="yesterday"){let c=new Date(n);return c.setDate(c.getDate()-1),c.toDateString()}let o=new Date(r);return Number.isNaN(o.getTime())?r:(o.setHours(0,0,0,0),o.toDateString())},hr=(t,r)=>t?r?_t(t.date)!==_t(r.date):true:false,gr=({messagesEndRef:t,productAttachment:r})=>{let{currentChat:n}=B(b=>({currentChat:b.getCurrentChat()})),o=B.getState().getActiveAccount(),[c,e]=useState(false),[s,m]=useState(false),f=useRef(null),h=useRef(n?.messages.length??0),d=n?.messages??[],i=d.length,x=i>0?d[i-1]:void 0,S=useVirtualizer({count:i,getScrollElement:()=>f.current,estimateSize:()=>80,overscan:5}),C=useCallback((b="smooth")=>{let k=f.current;k&&(k.scrollTo({top:k.scrollHeight,behavior:b}),e(false),m(false));},[]),F=useCallback(()=>{let b=f.current;if(!b)return;let{scrollTop:k,scrollHeight:A,clientHeight:T}=b,D=A-(k+T)<=50;m(!D),D&&e(false);},[]);useEffect(()=>{let b=h.current;if(i===0){h.current=0;return}if(!f.current){h.current=i;return}if(i>b){let k=f.current,{scrollTop:A,scrollHeight:T,clientHeight:D}=k;T-(A+D)<=50||x?.senderId===o?._id?C("smooth"):e(true);}else i<b&&C("auto");h.current=i;},[i,x?.id,x?.senderId,o?._id,C]),useEffect(()=>{e(false),m(false),h.current=n?.messages.length??0,C("auto");},[n?._id,C]);let M=i>0,E=S.getVirtualItems();return jsxs(Box,{position:"relative",flex:1,children:[jsxs(Box,{ref:f,onScroll:F,sx:{position:"relative",height:"100%",overflowY:"auto",padding:{xs:"1rem 0.75rem",md:"1.5rem"}},children:[M?jsx(Fragment,{children:jsx(Box,{sx:{height:`${S.getTotalSize()}px`,position:"relative"},children:E.map(b=>{let k=d[b.index],A=b.index>0?d[b.index-1]:void 0,T=hr(k,A);return jsxs(Box,{ref:S.measureElement,"data-index":b.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${b.start}px)`},children:[T&&k?.date&&jsx(wt,{date:k.date}),k&&jsx(Bt,{message:k,activeUserId:o?._id,activeUserAvatar:o?.avatar,othersAvatar:n?.avatar})]},k?.id??b.key)})})}):jsx(Stack,{justifyContent:"center",alignItems:"center",sx:{minHeight:"100%",textAlign:"center",color:"#5E5E5E",gap:"1rem",padding:"1rem"},children:jsxs(Box,{children:[jsx(Typography,{variant:"body1",children:"\u0647\u0646\u0648\u0632 \u067E\u06CC\u0627\u0645\u06CC \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647 \u0627\u0633\u062A."}),jsx(Typography,{variant:"body2",children:"\u0627\u0648\u0644\u06CC\u0646 \u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06A9\u0646\u06CC\u062F."})]})}),jsx("div",{ref:t})]}),c&&s&&jsxs(Button,{variant:"contained",onClick:()=>C("smooth"),sx:{position:"fixed",bottom:{xs:"126px",sm:"100px"},left:"50%",transform:"translateX(-50%)",backgroundColor:"#D9E2FF",color:"#001945",borderRadius:"3rem",boxShadow:"0 2px 8px rgba(0,0,0,0.1)","&:hover":{backgroundColor:"#BBDEFB"},zIndex:1e3,direction:"rtl",gap:"4px",padding:{xs:"8px 16px",sm:"10px 20px"},fontSize:{xs:"0.875rem",sm:"1rem"},whiteSpace:"nowrap",minWidth:{xs:"auto",sm:"200px"}},children:["\u067E\u06CC\u0627\u0645 \u062C\u062F\u06CC\u062F \u062F\u0627\u0631\u06CC\u062F",jsx(ArrowDownwardOutlined,{sx:{fontSize:{xs:"1.2rem",sm:"1.5rem"}}})]})]})},Ft=gr;var Dt={uploadFile:"/uploads/upload"};var xr=async t=>{let r=new FormData;return r.append("file",t.file),(await ce.post(Dt.uploadFile,r,{headers:{"Content-Type":"multipart/form-data"}})).data},Ut=()=>useMutation({mutationFn:xr});var Ar=({attachment:t,onRemove:r,showPreview:n=true})=>{let o=t instanceof File,c=o?t.type:t.mimeType,e=o?t.name:t.originalName,s=t.size,m=o?void 0:t.signedUrl||t.url,f=o?void 0:t.thumbnailSignedUrl||t.signedUrl||t.url,h=S=>S<1024?S+" B":S<1024*1024?(S/1024).toFixed(1)+" KB":(S/(1024*1024)).toFixed(1)+" MB",d=()=>c.startsWith("image/")?jsx(Image,{sx:{width:24,height:24}}):c.startsWith("video/")?jsx(VideoLibrary,{sx:{width:24,height:24}}):c.startsWith("audio/")?jsx(AudioFile,{sx:{width:24,height:24}}):jsx(InsertDriveFile,{sx:{width:24,height:24}}),i=o?URL.createObjectURL(t):f||m;c.startsWith("image/")&&n&&i;return jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",gap:"0.5rem",overflow:"hidden",border:"1px solid #E0E0E0"},children:[jsx(Box,{sx:{width:48,height:48,borderRadius:"4px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#E0E0E0"},children:d()}),jsxs(Stack,{flex:1,minWidth:0,children:[jsx(Typography,{variant:"body2",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontWeight:500},children:e}),jsx(Typography,{variant:"caption",color:"textSecondary",children:h(s)})]}),r&&jsx(IconButton,{size:"small",onClick:r,sx:{padding:"4px"},children:jsx(Close,{sx:{width:20,height:20}})})]})},Ke=Ar;var Fr=({onBack:t})=>{let r=useRef(null),n=useRef(null),[o,c]=useState(""),[e,s]=useState(null),[m,f]=useState([]),[h,d]=useState(null),[i,x]=useState(null),S=20*1024*1024,C=Ut(),F=useRef(null),M=useRef(void 0),E=useRef(false),{accounts:b,getActiveAccount:k,getCurrentChat:A,addMessageToChat:T,updateMessageInChat:D,setMessagesForChat:G,chats:U}=B(p=>({accounts:p.accounts,getActiveAccount:p.getActiveAccount,getCurrentChat:p.getCurrentChat,addMessageToChat:p.addMessageToChat,updateMessageInChat:p.updateMessageInChat,setMessagesForChat:p.setMessagesForChat,chats:p.chats})),g=A(),j=k(),J=j?._id||"",ne=j?.avatar,l=Y(p=>p.socket),I=useMemo(()=>g?g.canSendMessages===false||g.isBot===true:false,[g]),a=useMemo(()=>I?g?.isBot?"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F":g?.composerHint||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F.":"",[g?.composerHint,g?.isBot,I]);useEffect(()=>{g&&r.current&&!I&&r.current.focus();},[g,I]),useEffect(()=>{c(""),f([]),s(null),d(null),new URL(window.location.href).searchParams.has("productId")||x(null);},[g?._id]),useEffect(()=>{if(l)return l.on("CHAT_SEEN",({chatId:p})=>{g&&g._id===p&&G(p,g.messages.map(L=>({...L,hasSeen:true})));}),()=>{l.off("CHAT_SEEN");}},[l,g,G]);let y=useCallback(p=>{!l||!g?._id||!g?.receiverId||E.current!==p&&(E.current=p,l.emit(p?"START_TYPING":"FINISH_TYPING",{targetId:g.receiverId}));},[l,g]),O=useCallback(p=>{if(I){me.error(a);return}let L=p.target.value;c(L),M.current&&clearTimeout(M.current),L.length>0&&y(true),M.current=setTimeout(()=>{y(false);},1e3);},[y,I,a]);useEffect(()=>()=>{M.current&&clearTimeout(M.current),y(false);},[y,g?._id]),useEffect(()=>{if(!g?._id){x(null);return}let L=new URL(window.location.href).searchParams.get("productId");if(!L){x(null);return}let z=Number(L);if(!z||Number.isNaN(z)){x(null);return}let P=K().baseApi;(async()=>{try{let ge=await fetch(`${P}Catalog/Products/${z}`,{method:"GET",headers:{"Content-Type":"application/json","front-forwarded-for":window?.__CLIENT_IP__||""},cache:"no-store"});if(!ge.ok)throw new Error("Failed to load product");let Re=await ge.json(),$=Re?.value||Re,Jt=$?.name||$?.titleFa||String(z),Qt=($?.images||[]).find(eo=>eo?.isMain)?.url||$?.images?.[0]?.url,Zt=`https://rasmio.com/product/${z}`;x({id:z,title:Jt,image:Qt,url:Zt});}catch(ge){console.error("Error fetching product attachment:",ge),x({id:z,title:String(z),image:void 0,url:`https://rasmio.com/product/${z}`});}})();},[g?._id]);let u=useCallback(async p=>{if(I){me.error(a),p.target&&(p.target.value="");return}let L=p.target.files?.[0];if(L){if(d(null),L.size>S){d(`\u062D\u062C\u0645 \u0641\u0627\u06CC\u0644 \u0646\u0628\u0627\u06CC\u062F \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 ${S/(1024*1024)} \u0645\u06AF\u0627\u0628\u0627\u06CC\u062A \u0628\u0627\u0634\u062F`);return}s(L);try{let P=(await C.mutateAsync({file:L}))?.data?.attachments;P&&P.length>0?(f(P),s(null)):(d("\u067E\u0627\u0633\u062E \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0632 \u0633\u0631\u0648\u0631"),s(null));}catch{d("\u062E\u0637\u0627 \u062F\u0631 \u0622\u067E\u0644\u0648\u062F \u0641\u0627\u06CC\u0644. \u0644\u0637\u0641\u0627 \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F."),s(null);}p.target&&(p.target.value="");}},[C,S,I,a]),w=useCallback(()=>{s(null),f([]),d(null);},[]),H=useCallback(()=>{if(I){me.error(a);return}n.current?.click();},[I,a]),q=useCallback(()=>{if(I){me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.");return}let p=o.trim(),L=p.length>0||m.length>0,z=i?.url?p?`${p}
22
+ ${i.url}`:`${i.url}`:p;if(L&&j&&l&&g){y(false),M.current&&clearTimeout(M.current);let P=`temp-${Date.now()}`,he={id:P,senderId:J,senderName:"You",content:z,time:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:false}),date:"\u0627\u0645\u0631\u0648\u0632",createdAt:Date.now(),status:"sending",avatar:ne||""},ge=m.length>0,Re=m.map($=>$.id);if(T(g?._id,he),c(""),f([]),d(null),i){x(null);let $=new URL(window.location.href);$.searchParams.delete("productId"),window.history.replaceState({},"",$.toString());}ge?l.emit("SEND_ATTACHMENT",{targetId:g?.receiverId,text:p||void 0,attachments:Re},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});}):l.emit("SEND_MESSAGE",{targetId:g?.receiverId,content:z,isChatId:g?.type==="Broadcast"},$=>{$?D(g?._id,P,{id:$.messageId,status:"sent"}):D(g?._id,P,{status:"failed"});});}},[o,j,l,J,T,D,g,y,m,i,I,a]),Z=useCallback(p=>{if(I){me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."),p.preventDefault();return}p.key==="Enter"&&!p.shiftKey&&(q(),p.preventDefault());},[q,I,a]);return g&&jsxs(Stack,{flexDirection:"column",bgcolor:"#E3E3E3",borderRadius:{xs:0,md:2},position:"relative",flex:1,children:[jsx(Stack,{bgcolor:"#F4F4F4",borderBottom:"1px solid #ccc",px:2,flexBasis:"64px",sx:{borderTopRightRadius:{md:"0.75rem"}},justifyContent:"center",alignItems:"flex-start",boxSizing:"content-box",children:jsx(bt,{onBack:t})}),jsx(Stack,{flex:"1 0 0",position:"relative",overflow:"auto",children:jsx(Ft,{messagesEndRef:F,productAttachment:i})}),jsxs(Stack,{sx:{padding:"16px"},position:"relative",onDragOver:p=>{I&&(p.preventDefault(),p.stopPropagation(),me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},onDrop:p=>{I&&(p.preventDefault(),p.stopPropagation(),me.error(a||"\u0627\u0631\u0633\u0627\u0644 \u0641\u0627\u06CC\u0644 \u062F\u0631 \u0627\u06CC\u0646 \u06A9\u0627\u0646\u0627\u0644 \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A."));},children:[jsxs(Stack,{children:[i&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,sx:{background:"#F4F4F4",borderRadius:"0.5rem",padding:"0.5rem",marginBottom:"8px",width:"100%",gap:"1rem",overflow:"hidden"},children:[i.image&&jsx("img",{src:i.image,alt:i.title||"product",style:{width:48,height:48,borderRadius:4,objectFit:"contain",background:"#F4F4F4"}}),jsx(Typography,{variant:"body2",sx:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i.title||i.id}),jsx(IconButton,{size:"small",onClick:()=>{x(null);let p=new URL(window.location.href);p.searchParams.delete("productId"),window.history.replaceState({},"",p.toString());},children:jsx("span",{style:{fontSize:20,lineHeight:1},children:"\xD7"})})]}),(e||m.length>0)&&jsxs(Stack,{sx:{marginBottom:"8px",maxWidth:"100%",width:{xs:"91%",md:"100%"}},children:[e&&jsx(Ke,{attachment:e,onRemove:w}),m.map(p=>jsx(Ke,{attachment:p,onRemove:w},p.id))]}),h&&jsx(Alert,{severity:"error",onClose:()=>d(null),sx:{marginBottom:"8px"},children:h})]}),g?.isBlockedByMe?jsxs(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px"},direction:"row",justifyContent:"center",alignItems:"center",children:[jsx(Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0634\u0645\u0627 \u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0631\u0627 \u0645\u0633\u062F\u0648\u062F \u06A9\u0631\u062F\u0647\u200C\u0627\u06CC\u062F"}),jsx(Button,{variant:"outlined",onClick:()=>{l&&g&&(l.emit("USER_UNBLOCK",{accountId:g.receiverId}),B.getState().unblockUser(g._id));},sx:{borderColor:"#777",color:"#0058CB"},children:"\u0631\u0641\u0639 \u0645\u0633\u062F\u0648\u062F\u06CC\u062A"})]}):g?.isBlockedByTarget?jsx(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center"},children:jsx(Typography,{variant:"body2",color:"textSecondary",textAlign:"center",children:"\u0627\u06CC\u0646 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0627\u0632 \u0637\u0631\u0641 \u06A9\u0627\u0631\u0628\u0631 \u0645\u0642\u0627\u0628\u0644 \u0645\u0633\u062F\u0648\u062F \u0634\u062F\u0647 \u0627\u0633\u062A"})}):I?jsxs(Stack,{sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",padding:"16px",alignItems:"center",gap:"12px",flexDirection:"row"},justifyContent:"center",alignItems:"center",children:[jsx(NotificationsActive,{sx:{color:"#FF9800"}}),jsx(Typography,{variant:"body2",color:"textSecondary",children:a||"\u0627\u0645\u06A9\u0627\u0646 \u0627\u0631\u0633\u0627\u0644 \u067E\u06CC\u0627\u0645 \u062F\u0631 \u0627\u06CC\u0646 \u0686\u062A \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F."})]}):jsx(TextField,{fullWidth:true,placeholder:"\u067E\u06CC\u0627\u0645 \u062E\u0648\u062F \u0631\u0627 \u0627\u06CC\u0646\u062C\u0627 \u0628\u0646\u0648\u06CC\u0633\u06CC\u062F",value:o,multiline:true,maxRows:4,inputRef:r,onChange:O,onKeyDown:Z,sx:{background:"#FFF",border:"0.5px solid #777",borderRadius:"0.5rem",fontFamily:"RASMIO","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"},"& textarea":{fontFamily:"RASMIO",overflowY:"auto",maxHeight:"96px",resize:"none",lineHeight:"24px",paddingRight:"40px",paddingLeft:"40px","&::-webkit-scrollbar":{width:"8px"},"&::-webkit-scrollbar-track":{background:"#f1f1f1",borderRadius:"4px"},"&::-webkit-scrollbar-thumb":{background:"#888",borderRadius:"4px"},"&::-webkit-scrollbar-thumb:hover":{background:"#555"}},"& textarea::placeholder":{fontFamily:"RASMIO"}},InputProps:{endAdornment:jsx(InputAdornment,{position:"end",children:o.length>0||m.length>0||C.isLoading?jsx(IconButton,{onClick:q,disabled:C.isLoading||m.length===0&&o.trim().length===0,children:jsx(Send,{sx:{transform:"rotate(180deg)",color:C.isLoading||m.length===0&&o.trim().length===0?"#999":"#0058CB"}})}):jsx(IconButton,{onClick:H,children:jsx(AttachFile,{sx:{color:"#777"}})})})}}),jsx("input",{ref:n,type:"file",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",style:{display:"none"},onChange:u})]}),jsx("div",{ref:F})]})},zt=Fr;var Wt=(t,r)=>useCallback(o=>{let c=r();o!==c?._id&&t?.emit("USER_JOINED",{accountId:o});},[t,r]);var Gt=(t,r,n,o)=>useCallback(e=>{t&&t.emit("GET_MESSAGES",{chatId:e}),r(e),window.history&&window.history.pushState({},"",`?chatId=${e}`),n&&n(),o&&o(false);},[t,r,n,o]);var $t=(t,r,n)=>useMemo(()=>{let o=K(),c=t||[];if(o.companyId){if(!n)return [];let e=Number(o.companyId);if(Number(n.rasmioId)!==e)return []}if(r){let e=String(r).toLowerCase();c.length;c=c.filter(m=>String(m?.title||"").toLowerCase().includes(e));}return c},[t,r,n]);var qt=styled(({className:t,...r})=>jsx(Tooltip,{...r,classes:{popper:t}}))(({theme:t})=>({"& .MuiTooltip-tooltip":{borderRadius:"0.25rem",background:"#1B1B1B",display:"flex",minHeight:"1.5rem",padding:"0.25rem 0.5rem",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"0.625rem",color:"#fff",fontSize:"0.875rem"}})),en=({onChatSelect:t})=>{let[r,n]=useState(null),[o,c]=useState(""),s=!!K().companyId,{accounts:m,chats:f,getActiveAccount:h,setCurrentChat:d,isMy:i}=B(l=>({accounts:l.accounts,chats:l.chats,getActiveAccount:l.getActiveAccount,setCurrentChat:l.setCurrentChat,isMy:l.isMy})),{statusTooltip:x,setStatusTooltip:S}=B(),C=Y(l=>l.socket),F=useTheme(),M=useMediaQuery(F.breakpoints.down("sm")),E=m.some(l=>l?.unreadChatsCount>0),b=Wt(C,h),k=Gt(C,d,t,S),A=m.find(l=>l.isActive),T=$t(f,o,A),D=useRef(null),G=useVirtualizer({count:T?.length||0,getScrollElement:()=>D.current,estimateSize:useCallback(()=>80,[]),overscan:10}),U=useRef(null),g=l=>{if(!(s||m.length<=1||i))if(m.length>1&&!i)n(U.current);else return},j=()=>{n(null);},J=l=>{switch(l){case "online":return "#006D3F";case "disconnected":return "#BD1300";case "reconnecting":return "#ff9800";default:return "#006D3F"}},ne=l=>{switch(l){case "online":return "\u0622\u0646\u0644\u0627\u06CC\u0646";case "disconnected":return "\u0622\u0641\u0644\u0627\u06CC\u0646";case "reconnecting":return "\u062F\u0631 \u062D\u0627\u0644 \u0627\u062A\u0635\u0627\u0644";default:return "\u0622\u0646\u0644\u0627\u06CC\u0646"}};return jsxs(Stack,{sx:{width:M?"100%":"20rem",display:"flex",flexDirection:"column",borderRight:M?"none":"1px solid #ccc",height:"100%",background:"#F4F4F4",borderTopLeftRadius:M?0:"16px",borderBottomLeftRadius:M?0:"16px"},children:[jsxs(Stack,{direction:"row",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 0.75rem",width:"100%",gap:"0.5rem",flexBasis:"64px"},children:[M?x&&jsx(qt,{title:ne(h()?.status),children:jsx(Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}):jsx(qt,{title:ne(h()?.status),children:jsx(Badge,{overlap:"circular",anchorOrigin:{vertical:"bottom",horizontal:"left"},variant:"dot",sx:{"& .MuiBadge-badge":{backgroundColor:J(h()?.status),color:J(h()?.status),boxShadow:"0 0 0 2px #fff",borderRadius:"50%",height:"12px",minWidth:"12px"}},children:jsx("img",{ref:U,style:{width:48,height:48,cursor:i||s?"default":"pointer",borderRadius:"4px"},src:m.find(l=>l.isActive)?.avatar,alt:"Avatar",onClick:i||s?void 0:g})})}),m.length>1&&!i&&!s&&(E?jsx(Badge,{variant:"dot",color:"error",sx:{ml:1,"& .MuiBadge-badge":{right:"auto",left:0,top:"20%",transform:"translateY(-50%)"}},children:jsx(Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer"},onClick:g,children:jsx(ExpandMore,{})})}):jsx(Stack,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",width:"24px",height:"24px",cursor:"pointer",marginInlineEnd:"0.75rem",marginInlineStart:"0.25rem"},onClick:g,children:jsx(ExpandMore,{})})),M?jsx(Fragment,{children:jsxs(Drawer,{anchor:"bottom",open:!!r,onClose:j,PaperProps:{sx:{maxHeight:"50%",width:"100%",borderTopLeftRadius:"16px",borderTopRightRadius:"16px",padding:"0.5rem"}},children:[jsxs(Stack,{flexDirection:"row",alignItems:"center",justifyContent:"space-between",children:[jsx(Typography,{sx:{fontSize:"1rem",fontWeight:700,padding:"0.5rem 1rem",color:"#1B1B1B"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),jsx(IconButton,{onClick:j,children:jsx(CloseOutlined,{style:{color:"#1B1B1B"}})})]}),m.map(l=>jsxs(MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsx(ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondary:l?.__t==="User"?"":l?.rasmioId}),(l?.unreadChatsCount??0)>0&&jsx(Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{ml:1,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]})}):jsxs(Menu,{anchorEl:r,open:!!r,onClose:j,PaperProps:{sx:{boxShadow:"0px 4px 24px 0px rgba(0, 0, 0, 0.12)",width:"20rem",marginInlineEnd:"4.6rem",marginTop:"1.2rem",padding:"1rem 1rem",borderRadius:"0.75rem"}},anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[jsx(Typography,{variant:"body1",sx:{fontSize:"0.875rem",fontWeight:400,color:"#5E5E5E"},children:"\u0645\u0634\u0627\u0647\u062F\u0647 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648\u0647\u0627\u06CC:"}),m.map(l=>jsxs(MenuItem,{onClick:()=>{b(l._id),j();},sx:{display:"flex",alignItems:"center",borderRadius:"0.5rem",marginBlockStart:"0.5rem",padding:"0.5rem 0.5rem",backgroundColor:l?.isActive?"#e0e0e0":"transparent","&:hover":{backgroundColor:"#d5d5d5"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:l.displayName,src:l.avatar}),jsx(ListItemText,{primary:l.displayName,primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600,marginInlineStart:"0.5rem"},secondary:l?.__t==="User"?"":l?.rasmioId,secondaryTypographyProps:{marginInlineStart:"0.5rem"}}),(l?.unreadChatsCount??0)>0&&jsx(Badge,{badgeContent:l?.unreadChatsCount,color:"error",sx:{mt:2,"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff"}}})]},l._id))]}),jsx(TextField,{value:o,onChange:l=>c(l.target.value),variant:"outlined",size:"small",placeholder:"\u062C\u0633\u062A\u062C\u0648",sx:{flexGrow:1,borderRadius:"0.5rem",background:"#F4F4F4",border:"0.5px solid #777","& .MuiOutlinedInput-notchedOutline":{border:"none"},"&:hover .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},InputProps:{endAdornment:o&&jsx(Close,{sx:{cursor:"pointer",width:"1.125rem",height:"1.125rem",marginInlineEnd:"0.75rem"},onClick:()=>c("")})}})]}),jsx(Divider,{sx:{marginBottom:"0.75rem"},orientation:"horizontal",flexItem:true}),jsxs(Typography,{sx:{color:"#5E5E5E",fontSize:"0.875rem",fontWeight:"400",padding:"0.75rem"},children:["\u06AF\u0641\u062A \u0648 \u06AF\u0648\u0647\u0627\u06CC ",h()?.displayName]}),jsxs(Stack,{ref:D,sx:{height:`${G.getTotalSize()}px`,flex:1,overflowY:"auto",scrollbarWidth:"none",width:"100%",position:"relative","&::-webkit-scrollbar":{display:"none"},msOverflowStyle:"none"},children:[f.length<1&&jsxs(Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"flex-start",alignItems:"center",height:"100%",marginBlockStart:"8rem",width:"100%",fontFamily:"RASMIO",gap:"0.5rem"},children:[jsx(CommentsDisabledOutlined,{sx:{fontSize:48,color:"#1B1B1B"}}),jsx(Typography,{color:"#1B1B1B",sx:{mb:2},children:"\u0634\u0645\u0627 \u0647\u06CC\u0686 \u06AF\u0641\u062A\u200C\u0648\u06AF\u0648 \u0641\u0639\u0627\u0644\u06CC \u0646\u062F\u0627\u0631\u06CC\u062F"})]}),jsx(Stack,{sx:{width:"100%",position:"relative"},children:G.getVirtualItems().map(l=>{let I=T[l.index];return jsx(Stack,{"data-index":l.index,ref:G.measureElement,sx:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${l.start}px)`},children:jsxs(ListItemButton,{onClick:()=>k(I._id),sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"0.75rem",gap:"0.25rem",backgroundColor:I?.isActive?"#DADADA":"transparent","&:hover":{backgroundColor:"#e0e0e0"}},children:[jsx("img",{width:48,height:48,style:{borderRadius:"4px"},alt:I?.title,src:I?.avatar}),jsx(ListItemText,{primary:I?.title,secondary:I?.isTyping?"\u062F\u0631 \u062D\u0627\u0644 \u0646\u0648\u0634\u062A\u0646 ...":I?.lastMessage?.content||"",primaryTypographyProps:{color:"#1B1B1B",fontSize:"0.875rem",fontWeight:600},secondaryTypographyProps:{noWrap:true,color:I?.isTyping?"#006D3F":"#555",fontSize:"0.875rem",fontWeight:400},sx:{marginRight:"1rem"}}),jsxs(Stack,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"1rem",marginLeft:"auto",minWidth:"50px"},children:[I.lastMessage?.createdAt&&jsx(Typography,{variant:"caption",sx:{color:"#999",fontSize:"0.75rem"},children:new Date(I.lastMessage.createdAt).toLocaleDateString("fa-IR")===new Date().toLocaleDateString("fa-IR")?new Date(I.lastMessage.createdAt).toLocaleTimeString("fa-IR",{hour:"2-digit",minute:"2-digit",hour12:false,timeZone:"Asia/Tehran"}):de(new Date(I.lastMessage.createdAt).toISOString())}),!I.isActive&&I?.unReadCount>0&&jsx(Badge,{badgeContent:I.unReadCount,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#BD1300",color:"#fff",fontSize:"0.75rem",height:"1.25rem",minWidth:"1.25rem"}}})]})]})},l.key)})})]})]})},Vt=en;var nn=memo(({token:t,serviceApi:r,socketUrl:n,baseApi:o,companyId:c})=>{useEffect(()=>{let d={};r&&(d.serviceApi=r),c&&(d.companyId=c),n&&(d.socketUrl=n),o&&(d.baseApi=o),Object.keys(d).length>0&&Je(d);},[r,n,o,c]);let e=B(d=>d.getCurrentChat()),s=B(d=>d.setCurrentChat),m=B(d=>d.chats),f=B(d=>d.refreshBroadcastPermissions),h=Y(d=>d.socket);return useEffect(()=>{let d=new URL(window.location.href),i=d.searchParams.get("chatId");if(!d.searchParams.get("targetCompanyId")&&i&&m.length>0&&h){let S=m.find(C=>C._id===i);S?(!e||e._id!==i)&&(s(i),S.isPreview||h.emit("GET_MESSAGES",{chatId:i})):i.startsWith("preview_chat_")||(d.searchParams.delete("chatId"),window.history.replaceState({},"",d.toString()));}},[m,s,e,h]),useEffect(()=>{let d=i=>{if(i.key==="Escape"&&(s(""),window.history)){let x=new URL(window.location.href);x.searchParams.delete("chatId"),window.history.pushState({},"",x.toString());}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),useEffect(()=>{f();},[f,e?._id]),jsx(QueryClientProvider,{client:pt,children:jsx(Ze,{token:t,children:jsx(mt,{children:jsx(at,{socketUrl:n,children:jsxs(Box,{sx:{display:"flex",flexDirection:"row",bgcolor:"#E3E3E3",borderRadius:"16px",width:"100%",marginBlockStart:"1rem",flex:1,position:"relative",overflow:"hidden",minHeight:"500px"},children:[jsx(Box,{sx:{width:{xs:"100%",sm:"unset"},display:e?{xs:"none",sm:"block"}:"block"},children:jsx(Vt,{})}),jsx(Box,{sx:{flex:1,position:{xs:"absolute",sm:"relative"},display:e?"flex":"none",inset:0,zIndex:e?10:-1,visibility:e?"visible":"hidden"},children:jsx(zt,{})})]})})})})})},(t,r)=>t.token===r.token&&t.serviceApi===r.serviceApi&&t.socketUrl===r.socketUrl);
23
23
 
24
24
  export { nn as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amirnapster/chat",
3
- "version": "1.7.0",
3
+ "version": "1.7.16",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "dev": "tsup --watch"
26
26
  },
27
27
  "dependencies": {
28
- "@tanstack/react-virtual": "^3.10.8",
28
+ "@tanstack/react-virtual": "^3.14.2",
29
29
  "react-markdown": "^9.0.1",
30
30
  "react-query": "^3.39.3",
31
31
  "remark-gfm": "^4.0.0",
@@ -35,8 +35,8 @@
35
35
  "devDependencies": {
36
36
  "@eslint/js": "^9.11.1",
37
37
  "@types/node": "^22.7.4",
38
- "@types/react": "^18.3.10",
39
- "@types/react-dom": "^18.3.0",
38
+ "@types/react": "^19",
39
+ "@types/react-dom": "^19",
40
40
  "@vitejs/plugin-react-swc": "^3.5.0",
41
41
  "dotenv": "^16.4.5",
42
42
  "eslint": "^9.11.1",
@@ -57,10 +57,10 @@
57
57
  "@emotion/styled": "^11",
58
58
  "@iconify/react": "^4",
59
59
  "@lottiefiles/react-lottie-player": "^3",
60
- "@mui/material": "^5.15.16",
61
- "@mui/icons-material": "^5.15.16",
62
- "react": "^18",
63
- "react-dom": "^18",
60
+ "@mui/material": "^7",
61
+ "@mui/icons-material": "^7",
62
+ "react": "^19",
63
+ "react-dom": "^19",
64
64
  "react-hot-toast": "^2.4.1"
65
65
  },
66
66
  "type": "module",