UNPKG

softchatjs-react

Version:
1 lines 54.6 kB
import{useEffect as me,useRef as Fe,useState as H,useMemo as Nn}from"react";import Mt from"./components/chat/chat.module.module.css";import{useEffect as mt,useState as Q,useRef as Xs}from"react";import U from"./components/inputs/chat-input.module.module.css";import"./components/inputs/chat-input.module.module.css";import{AttachmentTypes as Ke,MediaType as ut,generateId as Ws}from"softchatjs-core";import{AiOutlineAudio as Gs,AiOutlineDelete as Ys,AiOutlinePlus as Ks}from"react-icons/ai";import Xe from"./components/edit-panel/edit.module.module.css";import _e from"./components/text/text.module.module.css";import{jsx as ws}from"react/jsx-runtime";var Ms=e=>{let t={bold:_e.textBold,medium:`${_e.textMedium}`},s={sm:_e.textSmall,md:_e.textSizeMd,xs:_e.textExtraSmall};return ws("p",{style:e.styles,className:`${_e.text} ${t[e.weight||"medium"]} ${s[e.size||"md"]}`,children:e.text})},x=Ms;import{AiOutlineClose as Ts}from"react-icons/ai";import{createContext as Rs,useContext as ks}from"react";import{createContext as Is,useContext as Ls,useState as Je}from"react";import{jsx as Ss}from"react/jsx-runtime";var Tt=Is({activeConversation:null,setActiveConversation:()=>{},conversations:[],setConversations:()=>{},showImageModal:[],setShowImageModal:()=>{},connectionStatus:{isConnected:!1,fetchingConversations:!1,connecting:!1},setConnectionStatus:()=>{}}),_=()=>Ls(Tt),_t=({children:e})=>{let[t,s]=Je(null),[n,c]=Je([]),[m,i]=Je([]),[l,r]=Je({isConnected:!1,fetchingConversations:!1,connecting:!1});return Ss(Tt.Provider,{value:{activeConversation:t,setActiveConversation:s,conversations:n,setConversations:c,showImageModal:m,setShowImageModal:i,connectionStatus:l,setConnectionStatus:r},children:e})};var rt={background:{primary:"#1b1d21",secondary:"#202326",disabled:"#E0E0E0"},text:{primary:"white",secondary:"#4A4A4A",disabled:"#9E9E9E"},action:{primary:"#007AFF",secondary:"#5AA3FF"},chatBubble:{left:{bgColor:"#343434",messageColor:"white",messageTimeColor:"#6D6D6D",replyBorderColor:"#D1D1D6"},right:{bgColor:"#343434",messageColor:"white",messageTimeColor:"#6D6D6D",replyBorderColor:"#A3D1FF"}},icon:"white",divider:"rgba(128, 128, 128, 0.136)",hideDivider:!1,input:{bgColor:"#1b1d21",textColor:"white",emojiPickerTheme:"dark"}};import{jsx as Pt}from"react/jsx-runtime";var Dt=Rs({config:{theme:rt},client:null}),w=()=>ks(Dt),Es=({theme:e,children:t,client:s})=>Pt(Dt.Provider,{value:{config:{theme:e||rt},client:s},children:Pt(_t,{children:t})});import{jsx as Pe,jsxs as At}from"react/jsx-runtime";var _s=e=>{let{isEditing:t,message:s,isReplying:n,closePanel:c,width:m}=e,{config:i}=w(),{theme:l}=i,r=l?.background?.secondary,a=l?.text?.primary,g=l?.icon;return Pe("div",{className:t||n?`${Xe.edit} ${Xe.editOpen}`:`${Xe.edit}`,style:{background:r||"#1b1d21",width:m},children:At("div",{style:{background:r||"#222529"},className:Xe.edit__message,children:[At("div",{style:{width:"90%"},children:[Pe(x,{text:"You",styles:{color:a},weight:"bold"}),Pe(x,{text:s?.message,styles:{color:a},weight:"medium"})]}),Pe("div",{style:{width:"10%",marginRight:"15px"},children:s?.attachedMedia[0]?.mediaUrl&&Pe("img",{style:{height:"100%",width:"100%",borderRadius:"5px"},src:s?.attachedMedia[0]?.mediaUrl,alt:""})}),Pe(Ts,{onClick:c,color:g,size:20,style:{cursor:"pointer"}})]})})},Nt=_s;import{useRef as Ps}from"react";import lt from"./components/menu/menu.module.module.css";import{HiPhoto as Ds}from"react-icons/hi2";import{jsx as De,jsxs as Bt}from"react/jsx-runtime";var Ht=e=>De("div",{ref:e.generalMenuRef,className:lt.menu,children:e.element}),zt=({onChange:e,setFiles:t,closeGeneralMenu:s})=>{let n=Ps(),c=[{icon:De(Ds,{size:24,color:"white"}),title:"Photo"}],m=i=>{s();let l=i.target.files;t(Array.from(l))};return De("div",{className:lt.attachment,children:c.map((i,l)=>De("label",{htmlFor:"upload",children:Bt("div",{className:lt.attachment__item,children:[Bt("div",{style:{marginRight:"10px"},children:[" ",i.icon]}),De("input",{onChange:m,ref:n,type:"file",hidden:!0,id:"upload"}),De(x,{styles:{marginBottom:"3px"},size:"sm",text:i.title})]})},l))})};import{v4 as ts}from"uuid";import{MdCancel as ss}from"react-icons/md";import{VscSend as ns}from"react-icons/vsc";import{CiFaceSmile as Qs}from"react-icons/ci";import As from"emoji-picker-react";import We from"./components/emoji/emoji.module.module.css";import{CiFaceSmile as Ns}from"react-icons/ci";import{BsReply as Bs}from"react-icons/bs";import{AiOutlineDelete as Hs}from"react-icons/ai";import{FiEdit2 as zs}from"react-icons/fi";import{jsx as he}from"react/jsx-runtime";var Us=["\u{1F44D}","\u{1F614}","\u{1F642}","\u{1F62E}","\u{1F603}"],Ut=e=>{let{client:t,message:s,conversationId:n,recipientId:c,setShowEmojiPanel:m}=e,{config:i}=w(),l=i?.theme?.background?.secondary||"#222529",r=({emoji:a})=>{t.messageClient(n).reactToMessage({conversationId:n,messageId:s.messageId,reactions:[{emoji:a,uid:t.chatUserId}],to:c}),m(!1)};return he("div",{ref:e.emojiPickerRef,style:{background:l},className:We.emoji,children:Us.map((a,g)=>he("div",{onClick:()=>r({emoji:a}),className:We.reaction__emoji,children:a},g))})},ct=({setEditDetails:e,message:t,closeOptionsMenu:s,textInputRef:n,openEmojiPanel:c,client:m,canEdit:i,conversationId:l})=>{let{config:r}=w(),a=r.theme?.icon||"#72767D",g=[{emoji:he(zs,{size:16,color:a}),onPress:()=>{e({message:t,isEditing:!0}),s()},enabled:i},{emoji:he(Ns,{size:16,color:a}),onPress:()=>{c()},enabled:!0},{emoji:he(Bs,{size:16,color:a}),onPress:()=>{e({message:t,isReplying:!0}),s(),n.current?.focus()},enabled:!0},{emoji:he(Hs,{size:16,color:a}),onPress:()=>{m.messageClient(l).deleteMessage(t.messageId,t.to,l)},enabled:i}];return he("div",{className:We.reactions,children:g.map((o,f)=>{if(o.enabled)return he("div",{onClick:o.onPress,className:We.reaction__emoji,children:o.emoji},f)})})},Ot=({onEmojiPick:e})=>{let{config:t}=w();return he(As,{height:350,width:300,onEmojiClick:s=>{e(s.emoji)},theme:t?.theme?.input?.emojiPickerTheme})};import Ge from"dayjs";import dt from"moment";import Os from"dayjs/plugin/localizedFormat";import js from"dayjs/plugin/calendar";Ge.extend(Os);Ge.extend(js);var jt=e=>Ge(e).format("LT"),Vt=e=>Ge(e).format("ll");function $t(e){if(!e)return"";let t=dt(),s=dt(e),n=dt.duration(t.diff(s)),c=Math.floor(n.asYears());if(c>0)return c+"yr";let m=Math.floor(n.asMonths());if(m>0)return m+"mo";let i=Math.floor(n.asWeeks());if(i>0)return i+"w";let l=Math.floor(n.asDays());if(l>0)return l+"d";let r=Math.floor(n.asHours());if(r>0)return r+"h";let a=Math.floor(n.asMinutes());return a>0?a+"m":"Just now"}function Ae(e){if(e===0)return"00:00";var t=Number(e.toFixed(0));let s=Math.floor(t/60),n=t%60,c=String(s).padStart(2,"0"),m=String(n).padStart(2,"0");return`${c}:${m}`}import{useState as Ye,useEffect as Vs,useRef as $s,useCallback as Fs}from"react";import{jsx as N}from"react/jsx-runtime";var Ft=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 256 256",fill:"none",children:N("path",{d:"M240 128C240.007 130.716 239.31 133.388 237.978 135.756C236.647 138.123 234.725 140.105 232.4 141.51L88.32 229.65C85.8909 231.138 83.1087 231.95 80.2608 232.002C77.4129 232.055 74.6025 231.347 72.12 229.95C69.6611 228.575 67.6128 226.57 66.1856 224.141C64.7585 221.712 64.0041 218.947 64 216.13V39.8701C64.0041 37.053 64.7585 34.2877 66.1856 31.8588C67.6128 29.4299 69.6611 27.4249 72.12 26.0501C74.6025 24.6536 77.4129 23.9451 80.2608 23.9979C83.1087 24.0506 85.8909 24.8626 88.32 26.3501L232.4 114.49C234.725 115.895 236.647 117.877 237.978 120.245C239.31 122.612 240.007 125.284 240 128Z",fill:s})})},Zt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",children:N("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M8 5C7.46957 5 6.96086 5.21071 6.58579 5.58579C6.21071 5.96086 6 6.46957 6 7V17C6 17.5304 6.21071 18.0391 6.58579 18.4142C6.96086 18.7893 7.46957 19 8 19H9C9.53043 19 10.0391 18.7893 10.4142 18.4142C10.7893 18.0391 11 17.5304 11 17V7C11 6.46957 10.7893 5.96086 10.4142 5.58579C10.0391 5.21071 9.53043 5 9 5H8ZM15 5C14.4696 5 13.9609 5.21071 13.5858 5.58579C13.2107 5.96086 13 6.46957 13 7V17C13 17.5304 13.2107 18.0391 13.5858 18.4142C13.9609 18.7893 14.4696 19 15 19H16C16.5304 19 17.0391 18.7893 17.4142 18.4142C17.7893 18.0391 18 17.5304 18 17V7C18 6.46957 17.7893 5.96086 17.4142 5.58579C17.0391 5.21071 16.5304 5 16 5H15Z",fill:s})})},Jt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",children:N("path",{d:"M18 8H17V6C17 3.24 14.76 1 12 1C9.24 1 7 3.24 7 6V8H6C4.9 8 4 8.9 4 10V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V10C20 8.9 19.1 8 18 8ZM9 6C9 4.34 10.34 3 12 3C13.66 3 15 4.34 15 6V8H9V6ZM18 20H6V10H18V20ZM12 17C13.1 17 14 16.1 14 15C14 13.9 13.1 13 12 13C10.9 13 10 13.9 10 15C10 16.1 10.9 17 12 17Z",fill:s})})},Xt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",children:N("path",{d:"M12 2C17.523 2 22 6.477 22 12C22 17.523 17.523 22 12 22H4C3.46957 22 2.96086 21.7893 2.58579 21.4142C2.21071 21.0391 2 20.5304 2 20V12C2 6.477 6.477 2 12 2ZM12 14H9C8.73478 14 8.48043 14.1054 8.29289 14.2929C8.10536 14.4804 8 14.7348 8 15C8 15.2652 8.10536 15.5196 8.29289 15.7071C8.48043 15.8946 8.73478 16 9 16H12C12.2652 16 12.5196 15.8946 12.7071 15.7071C12.8946 15.5196 13 15.2652 13 15C13 14.7348 12.8946 14.4804 12.7071 14.2929C12.5196 14.1054 12.2652 14 12 14ZM15 10H9C8.74512 10.0003 8.49997 10.0979 8.31463 10.2728C8.1293 10.4478 8.01776 10.687 8.00283 10.9414C7.98789 11.1958 8.07067 11.4464 8.23426 11.6418C8.39785 11.8373 8.6299 11.9629 8.883 11.993L9 12H15C15.2549 11.9997 15.5 11.9021 15.6854 11.7272C15.8707 11.5522 15.9822 11.313 15.9972 11.0586C16.0121 10.8042 15.9293 10.5536 15.7657 10.3582C15.6021 10.1627 15.3701 10.0371 15.117 10.007L15 10Z",fill:s})})},Wt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:N("path",{d:"M8.6 22.5L6.7 19.3L3.1 18.5L3.45 14.8L1 12L3.45 9.2L3.1 5.5L6.7 4.7L8.6 1.5L12 2.95L15.4 1.5L17.3 4.7L20.9 5.5L20.55 9.2L23 12L20.55 14.8L20.9 18.5L17.3 19.3L15.4 22.5L12 21.05L8.6 22.5ZM9.45 19.95L12 18.85L14.6 19.95L16 17.55L18.75 16.9L18.5 14.1L20.35 12L18.5 9.85L18.75 7.05L16 6.45L14.55 4.05L12 5.15L9.4 4.05L8 6.45L5.25 7.05L5.5 9.85L3.65 12L5.5 14.1L5.25 16.95L8 17.55L9.45 19.95ZM10.95 15.55L16.6 9.9L15.2 8.45L10.95 12.7L8.8 10.6L7.4 12L10.95 15.55Z",fill:s})})},Gt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:N("path",{d:"M8.50007 5.5C8.50007 5.36739 8.44739 5.24022 8.35362 5.14645C8.25985 5.05268 8.13268 5 8.00007 5C7.86746 5 7.74028 5.05268 7.64651 5.14645C7.55275 5.24022 7.50007 5.36739 7.50007 5.5V7.5H5.50007C5.36746 7.5 5.24028 7.55268 5.14651 7.64645C5.05275 7.74022 5.00007 7.86739 5.00007 8C5.00007 8.13261 5.05275 8.25979 5.14651 8.35355C5.24028 8.44732 5.36746 8.5 5.50007 8.5H7.50007V10.5C7.50007 10.6326 7.55275 10.7598 7.64651 10.8536C7.74028 10.9473 7.86746 11 8.00007 11C8.13268 11 8.25985 10.9473 8.35362 10.8536C8.44739 10.7598 8.50007 10.6326 8.50007 10.5V8.5H10.5001C10.6327 8.5 10.7599 8.44732 10.8536 8.35355C10.9474 8.25979 11.0001 8.13261 11.0001 8C11.0001 7.86739 10.9474 7.74022 10.8536 7.64645C10.7599 7.55268 10.6327 7.5 10.5001 7.5H8.50007V5.5ZM8.00007 2C6.95912 1.99965 5.93598 2.27012 5.0312 2.78485C4.12641 3.29957 3.37111 4.04083 2.83949 4.9358C2.30788 5.83077 2.01825 6.84864 1.99907 7.88942C1.97988 8.93019 2.2318 9.95805 2.73007 10.872L2.02007 13.362C1.99508 13.4494 1.99442 13.542 2.01814 13.6298C2.04187 13.7176 2.08908 13.7972 2.1547 13.8602C2.22033 13.9231 2.30187 13.967 2.39057 13.9871C2.47926 14.0071 2.57175 14.0026 2.65807 13.974L4.99607 13.195C5.79293 13.6555 6.68504 13.9265 7.60338 13.987C8.52173 14.0475 9.44169 13.896 10.2921 13.5441C11.1425 13.1922 11.9006 12.6494 12.5077 11.9577C13.1147 11.266 13.5545 10.4439 13.7931 9.555C14.0316 8.6661 14.0624 7.73425 13.8832 6.83153C13.704 5.92882 13.3195 5.07943 12.7594 4.34908C12.1994 3.61873 11.4789 3.027 10.6536 2.61967C9.82834 2.21233 8.92041 2.00031 8.00007 2ZM3.00007 8C3.00023 6.8906 3.36935 5.81277 4.04931 4.93618C4.72928 4.05959 5.68146 3.43403 6.75597 3.15799C7.83048 2.88195 8.96627 2.97111 9.98455 3.41142C11.0028 3.85174 11.8457 4.6182 12.3806 5.59015C12.9155 6.5621 13.1119 7.68433 12.9389 8.78017C12.766 9.876 12.2335 10.8832 11.4253 11.6432C10.6172 12.4032 9.57917 12.8728 8.47478 12.9782C7.3704 13.0835 6.26234 12.8185 5.32507 12.225C5.26237 12.1853 5.19161 12.16 5.11793 12.151C5.04424 12.142 4.96948 12.1495 4.89907 12.173L3.24107 12.726L3.75107 10.945C3.76965 10.8794 3.77462 10.8107 3.76568 10.7431C3.75674 10.6755 3.73407 10.6105 3.69907 10.552C3.24112 9.77954 2.99967 8.898 3.00007 8Z",fill:s})})},Yt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 20 20",fill:"none",children:N("path",{d:"M14.158 1.02584C14.2838 1.06763 14.3879 1.15768 14.4474 1.2762C14.5068 1.39472 14.5167 1.532 14.475 1.65784L13.975 3.15784C13.9331 3.28382 13.8428 3.38799 13.7241 3.44744C13.6054 3.50689 13.468 3.51675 13.342 3.47484C13.216 3.43294 13.1118 3.34271 13.0524 3.224C12.9929 3.10529 12.9831 2.96782 13.025 2.84184L13.525 1.34184C13.5458 1.27951 13.5786 1.22189 13.6217 1.17226C13.6648 1.12264 13.7172 1.08199 13.776 1.05265C13.8348 1.0233 13.8988 1.00582 13.9643 1.00123C14.0299 0.996627 14.0957 1.00499 14.158 1.02584ZM17.855 2.85384C17.9014 2.80736 17.9382 2.75218 17.9633 2.69147C17.9884 2.63075 18.0013 2.56569 18.0013 2.49999C18.0012 2.43429 17.9882 2.36925 17.963 2.30857C17.9379 2.24789 17.901 2.19277 17.8545 2.14634C17.808 2.09992 17.7528 2.06311 17.6921 2.03801C17.6314 2.01291 17.5663 2.00002 17.5006 2.00007C17.4349 2.00011 17.3699 2.0131 17.3092 2.03828C17.2485 2.06347 17.1934 2.10036 17.147 2.14684L15.147 4.14684C15.0559 4.24115 15.0055 4.36745 15.0066 4.49855C15.0078 4.62964 15.0604 4.75505 15.1531 4.84775C15.2458 4.94046 15.3712 4.99304 15.5023 4.99418C15.6334 4.99532 15.7597 4.94492 15.854 4.85384L17.855 2.85384ZM7.60698 3.14584C7.74648 2.85208 7.95551 2.59676 8.21596 2.40201C8.47641 2.20726 8.78042 2.07897 9.10164 2.02824C9.42287 1.97751 9.75162 2.00587 10.0594 2.11088C10.3672 2.21589 10.6447 2.39436 10.868 2.63084L17.455 9.61084C17.6748 9.84373 17.8355 10.126 17.9235 10.4339C18.0115 10.7418 18.0243 11.0663 17.9608 11.3802C17.8973 11.6941 17.7594 11.9882 17.5586 12.2376C17.3578 12.4871 17.1 12.6847 16.807 12.8138L12.87 14.5498C13.0159 15.0703 13.0395 15.6175 12.9387 16.1486C12.838 16.6797 12.6158 17.1803 12.2895 17.6113C11.9631 18.0422 11.5415 18.3918 11.0576 18.6327C10.5736 18.8736 10.0405 18.9992 9.49998 18.9998C8.90423 19 8.31831 18.848 7.7977 18.5584C7.27709 18.2688 6.83902 17.8511 6.52498 17.3448L5.32498 17.8738C5.04921 17.9953 4.74326 18.0308 4.447 17.9759C4.15073 17.921 3.87787 17.7781 3.66398 17.5658L2.44198 16.3558C2.22101 16.137 2.07355 15.8549 2.01998 15.5485C1.96641 15.2421 2.00939 14.9267 2.14298 14.6458L7.60698 3.14584ZM7.45298 16.9348C7.78487 17.4086 8.27081 17.7527 8.82797 17.9083C9.38512 18.064 9.97901 18.0216 10.5084 17.7884C11.0378 17.5552 11.4699 17.1456 11.7312 16.6294C11.9924 16.1133 12.0665 15.5225 11.941 14.9578L7.45298 16.9348ZM10.141 3.31784C10.0294 3.19969 9.89068 3.11052 9.73687 3.05805C9.58305 3.00557 9.41877 2.99137 9.25823 3.01669C9.0977 3.042 8.94575 3.10605 8.81555 3.20331C8.68534 3.30057 8.5808 3.42809 8.51098 3.57484L3.04598 15.0748C3.00172 15.1684 2.98757 15.2733 3.00548 15.3752C3.02339 15.4772 3.07248 15.571 3.14598 15.6438L4.36798 16.8548C4.4393 16.9253 4.53016 16.9728 4.62878 16.991C4.7274 17.0091 4.8292 16.9973 4.92098 16.9568L16.403 11.8998C16.5495 11.8354 16.6784 11.7366 16.7788 11.612C16.8793 11.4873 16.9483 11.3404 16.9801 11.1835C17.012 11.0266 17.0057 10.8644 16.9618 10.7105C16.9179 10.5565 16.8377 10.4154 16.728 10.2988L10.141 3.31784ZM17 5.99985C16.8674 5.99985 16.7402 6.05252 16.6464 6.14629C16.5527 6.24006 16.5 6.36724 16.5 6.49985C16.5 6.63245 16.5527 6.75963 16.6464 6.8534C16.7402 6.94717 16.8674 6.99985 17 6.99985H18.5C18.6326 6.99985 18.7598 6.94717 18.8535 6.8534C18.9473 6.75963 19 6.63245 19 6.49985C19 6.36724 18.9473 6.24006 18.8535 6.14629C18.7598 6.05252 18.6326 5.99985 18.5 5.99985H17Z",fill:s})})},Kt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t*2,viewBox:"0 0 12 24",fill:"none",children:N("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.1569 12.7111L4.49994 18.3681L3.08594 16.9541L8.03594 12.0041L3.08594 7.05414L4.49994 5.64014L10.1569 11.2971C10.3444 11.4847 10.4497 11.739 10.4497 12.0041C10.4497 12.2693 10.3444 12.5236 10.1569 12.7111Z",fill:s})})},Qt=e=>{let{size:t=25,color:s="black"}=e;return N("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:N("path",{d:"M10.75 7C10.75 7.13261 10.6973 7.25979 10.6036 7.35355C10.5098 7.44732 10.3826 7.5 10.25 7.5H6C5.86739 7.5 5.74021 7.44732 5.64645 7.35355C5.55268 7.25979 5.5 7.13261 5.5 7C5.5 6.86739 5.55268 6.74021 5.64645 6.64645C5.74021 6.55268 5.86739 6.5 6 6.5H10.25C10.3826 6.5 10.5098 6.55268 10.6036 6.64645C10.6973 6.74021 10.75 6.86739 10.75 7ZM10.25 8.5H6C5.86739 8.5 5.74021 8.55268 5.64645 8.64645C5.55268 8.74021 5.5 8.86739 5.5 9C5.5 9.13261 5.55268 9.25979 5.64645 9.35355C5.74021 9.44732 5.86739 9.5 6 9.5H10.25C10.3826 9.5 10.5098 9.44732 10.6036 9.35355C10.6973 9.25979 10.75 9.13261 10.75 9C10.75 8.86739 10.6973 8.74021 10.6036 8.64645C10.5098 8.55268 10.3826 8.5 10.25 8.5ZM14.5 7.75C14.4982 9.40704 13.8391 10.9957 12.6674 12.1674C11.4957 13.3391 9.90704 13.9982 8.25 14H3C2.73478 14 2.48043 13.8946 2.29289 13.7071C2.10536 13.5196 2 13.2652 2 13V7.75C2 6.0924 2.65848 4.50268 3.83058 3.33058C5.00268 2.15848 6.5924 1.5 8.25 1.5C9.9076 1.5 11.4973 2.15848 12.6694 3.33058C13.8415 4.50268 14.5 6.0924 14.5 7.75ZM13.5 7.75C13.5 6.35761 12.9469 5.02226 11.9623 4.03769C10.9777 3.05312 9.64239 2.5 8.25 2.5C6.85761 2.5 5.52226 3.05312 4.53769 4.03769C3.55312 5.02226 3 6.35761 3 7.75V13H8.25C9.64193 12.9985 10.9764 12.4449 11.9607 11.4607C12.9449 10.4764 13.4985 9.14193 13.5 7.75Z",fill:s})})};import{FaSpinner as Zs}from"react-icons/fa6";import{jsx as Ue,jsxs as qt}from"react/jsx-runtime";function Ne(e){let{blob:t,duration:s,url:n,style:c}=e,[m,i]=Ye(""),l=$s(null),[r,a]=Ye(!1),[g,o]=Ye(0),[f,d]=Ye(!0),{config:M}=w(),J=M.theme,k=M?.theme?.text?.primary||"white",oe=()=>{l.current&&(r?l.current.pause():l.current.play(),a(!r))},P=()=>{},S=()=>{o(l.current.currentTime)},B=()=>{a(!1),o(0)};Vs(()=>{if(n)return i(n);if(t){let X=URL.createObjectURL(t);i(X),d(!0)}},[t,n]);let V=Fs(()=>f?Ue(Zs,{style:{marginRight:"3px",color:k}}):Ue("button",{onClick:oe,style:{backgroundColor:"transparent",border:0,padding:0,margin:"0px",marginTop:"4px"},children:r?Ue(Zt,{size:15,color:k}):Ue(Ft,{size:15,color:k})}),[f,r]);return qt("div",{style:{display:"flex",alignItems:"center",padding:"5px",...c},children:[V(),Ue("audio",{ref:l,onLoadedMetadata:P,onTimeUpdate:S,onEnded:B,onLoadStart:()=>d(!0),onCanPlay:()=>d(!1),src:m}),qt("p",{style:{padding:0,marginLeft:"10px",marginTop:0,fontSize:"11.5px",color:k},children:[Ae(g)," : ",Ae(s)]})]})}import{IoStopCircleOutline as qs}from"react-icons/io5";import"./components/Loaders/loaders.css";import{jsx as Js}from"react/jsx-runtime";function es(){return Js("div",{className:"loader"})}import{jsx as C,jsxs as se}from"react/jsx-runtime";var en=({client:e,conversationId:t,recipientId:s,editProps:n,setEditDetails:c,recipientTyping:m,setMenuDetails:i,menuDetails:l,generalMenuRef:r,closeGeneralMenu:a,textInputRef:g,renderChatInput:o})=>{let[f,d]=Q(),[M,J]=Q([]),[k,oe]=Q(!1),[P,S]=Q(!1),[B,V]=Q(!1),[X,O]=Q([]),[ue,ie]=Q(null),z=Xs(),[D,W]=Q(0),[A,G]=Q(null),[Ie,ge]=Q(null),[$,nt]=Q(0),q=e.messageClient(t),{config:ye}=w(),{theme:j}=ye,{activeConversation:be}=_(),[Se,Y]=Q(!1),ee=j?.icon||"white",xe=ye?.theme?.input.bgColor||"#222529",Me=()=>{if(z.current){let{width:p}=z?.current?.getBoundingClientRect();nt(p)}};mt(()=>{Me()},[]),mt(()=>{n?.isEditing?d(n?.message):d({})},[n?.isEditing]);let He=()=>{if(navigator.mediaDevices){let p={audio:!0};navigator.mediaDevices.getUserMedia(p).then(E=>{let T=new MediaRecorder(E);T.start(1e3),V(!0),ie(T);var Ee=[];T.onstop=Le=>{let Te=new Blob(Ee,{type:"audio/mp3"});Ee=[],G(Te)},T.onstart=()=>{},T.ondataavailable=Le=>{Ee.push(Le.data),D>=300?T.stop():W(Te=>Te+1)}}).catch(E=>{console.error(`The following error occurred: ${E}`)})}else console.log("not media devices found")};mt(()=>{let p,E;return f?.message&&f.message.length>0&&(clearTimeout(p),p=setTimeout(()=>{e&&(e.messageClient(t).sendTypingNotification(s),p=void 0)},300),clearTimeout(E),E=setTimeout(()=>{e&&e.messageClient(t).sendStoppedTypingNotification(s)},1300)),()=>clearTimeout(p)},[f?.message,t]);let pe=async()=>{try{let p=[];if(M.length>0){let E=M[0].type.split("/")[0];Y(!0);let T=await q.uploadFile(M[0],{filename:M[0].name,mimeType:M[0].type,ext:E==="image"?".png":".mp4"});p.push({type:E==="image"?ut.IMAGE:ut.VIDEO,ext:E==="image"?".png":".mp4",mediaId:ts(),mediaUrl:T.link,mimeType:M[0].type})}if(A){Y(!0),console.log(A);let E=URL.createObjectURL(A),T=await q.uploadFile(E,{filename:`${Ws()}.mp3`,mimeType:"audio/mp3",ext:".mp3"});p.push({type:ut.AUDIO,ext:".mp3",mediaId:ts(),mediaUrl:T.link,mimeType:"audio/mp3",meta:{audioDurationSec:D}}),W(0)}return p}catch(p){return console.error(p.message),[]}finally{Y(!1)}},Ce=()=>{d({message:""}),c(void 0)},ot=async()=>{var p=await pe();q.sendMessage({conversationId:t,to:s,message:f?.message,reactions:[],attachedMedia:p,quotedMessage:n?.message,attachmentType:p.length>0?Ke.MEDIA:Ke.NONE}),Ce()},ze=async()=>{q.editMessage({to:s,conversationId:t,messageId:n?.message?.messageId,textMessage:f?.message,shouldEdit:!0}),Ce()},Re=async()=>{var p=await pe();e.messageClient(t).broadcastMessage({broadcastListId:t,participantsIds:be.conversation.participants,newMessage:{conversationId:t,to:s,message:f?.message,reactions:[],attachedMedia:p,attachmentType:p.length>0?Ke.MEDIA:Ke.NONE,quotedMessage:n?.message}}),Ce()},y=async()=>{S(!0);try{if(!f?.message?.length&&!M.length&&!A)return;if(be?.conversation.conversationType==="broadcast-chat")return n?.isEditing?ze():Re();if(n?.isEditing)return ze();ot()}catch(p){console.log(p)}finally{S(!1),J([]),G(null)}},h=p=>{p.key==="Enter"&&f?.message?.length&&y()},I=p=>{let E=URL.createObjectURL(p),T=document.createElement("audio");T.src=E,T.controls=!0,document.body.appendChild(T)},F=()=>{He()},K=()=>{ue.stop(),V(!1)},ke=()=>{G(null),ge(null)};return be?.conversation?.conversationType==="admin-chat"?se("div",{style:{padding:"20px",flex:1,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center"},children:[C(Jt,{color:"white",size:20}),C(x,{size:"xs",styles:{marginLeft:"5px"},text:"Only the Admin can send messages."})]}):B?C("div",{style:{backgroundColor:j?.background?.secondary,justifyContent:"flex-end",width:"100%",flex:1},className:U.input,children:se("div",{className:U.input__inner,style:{width:"30%",fontStyle:"italic",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px",backgroundColor:j?.background?.secondary,boxShadow:"rgba(0, 0, 0, 0.35) 0px 5px 15px"},children:[C("button",{onClick:K,style:{backgroundColor:"transparent",border:0,marginRight:"12px"},children:C(qs,{style:{marginTop:"5px"},color:"red",size:23})}),C("div",{style:{flex:1,width:"100%",height:"2px",backgroundColor:"grey"},children:C("div",{style:{height:"100%",backgroundColor:"white",width:`${D/300*100}%`}})}),se("p",{style:{fontSize:"11.5px",marginLeft:"15px",color:j?.text?.primary},children:[Ae(D)," : ",Ae(300)]})]})}):A&&!Ie?se("div",{style:{width:"100%",backgroundColor:j?.background?.secondary||"#1b1d21",justifyContent:"flex-start",display:"flex",alignItems:"center"},className:U.input,children:[se("div",{className:U.input__inner,style:{width:"30%",fontStyle:"italic",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px",marginRight:"10px",backgroundColor:j?.background?.secondary||"#1b1d21",boxShadow:"rgba(0, 0, 0, 0.35) 0px 5px 15px"},children:[C("button",{onClick:()=>{G(null),W(0)},style:{backgroundColor:"transparent",border:0},children:C(Ys,{size:22,color:"red"})}),C(Ne,{blob:A,duration:D})]}),C(ns,{onClick:()=>{ge(A)},size:22,color:ee})]}):se("div",{ref:z,style:{height:"auto",width:"100%"},children:[Se&&C(es,{}),C(Nt,{width:$,message:n?.message,isEditing:n?.isEditing,isReplying:n?.isReplying,closePanel:()=>c(void 0)}),M.length||A?C(tn,{width:$,files:M,setFiles:J,audioBlob:Ie,voiceMessageDuration:D,cancelAudioAttachment:ke}):null,C("div",{style:{backgroundColor:j?.background?.secondary},className:U.input,children:se("div",{className:U.input__wrap,children:[C("div",{className:U.input__icon,children:!A&&C("div",{children:C(Ks,{onClick:()=>i?.({element:C(zt,{closeGeneralMenu:a,setFiles:J})}),color:ee,size:22})})}),C("div",{className:U.input__inner,style:{flex:1,fontStyle:"italic",background:xe},children:o?o({onChange:p=>{d({...f,message:p})}}):se("div",{style:{display:"flex",alignItems:"center"},children:[C("input",{style:{background:xe,color:j?.input?.textColor||"white"},onKeyDown:h,ref:g,value:f?.message,onChange:p=>d({...f,message:p.target.value}),placeholder:"Say something..."}),C(Qs,{onClick:()=>oe(!k),className:U.input__emoji,size:24,color:ee})]})}),C("div",{className:U.input__button,children:f?.message?C(ns,{onClick:y,size:20,color:ee}):C("button",{onClick:F,style:{backgroundColor:"transparent",border:0,cursor:"pointer"},children:C(Gs,{color:ee,size:20})})}),l.element?C("div",{className:U.input__menu,children:C(Ht,{generalMenuRef:r,element:l.element})}):null,k?C("div",{className:U.input__emoji__picker,children:C(Ot,{onEmojiPick:p=>{d({...f,message:p}),oe(!1)}})}):null]})})]})},tn=({audioBlob:e,voiceMessageDuration:t,cancelAudioAttachment:s,files:n,setFiles:c,width:m})=>{let i=a=>{let g=n.filter(o=>o.name!==a);c(g)},{config:l}=w(),{theme:r}=l;return se("div",{className:U.chatPhotos,style:{width:m,paddingBottom:"10px"},children:[e?se("div",{style:{padding:"10px",background:r?.background?.primary||"#1b1d21",borderRadius:"30px",cursor:"pointer",position:"relative"},children:[C("div",{onClick:s,className:U.audioCancel,children:C(ss,{size:20,color:"grey"})}),C("div",{style:{border:`1px solid ${r.divider}`,borderRadius:"5px"},children:C(Ne,{style:{padding:"15px"},blob:e,duration:t})})]}):null,n.length?n.map((a,g)=>{let o=URL.createObjectURL(a);return se("div",{className:U.chatPhotos__item,children:[a.type==="video/quicktime"?C("video",{style:{},src:o}):C("img",{src:o,alt:""}),C("div",{onClick:()=>i(a.name),className:U.chatPhotos__cancel,children:C(ss,{size:20,color:"grey"})})]},g)}):null]})},gt=en;import{useMemo as pn,createRef as Cn,useEffect as pt,useRef as et,useState as Be,useLayoutEffect as fn}from"react";import tt from"./components/message-list/message-list.module.module.css";import os from"./components/avartar/avartar.module.module.css";import{jsx as Qe}from"react/jsx-runtime";var sn=({initials:e,url:t,size:s=35})=>{let{client:n,config:c}=w();return t?Qe("div",{className:os.avatar,style:{height:s,width:s,borderRadius:s},children:Qe("img",{src:t,alt:"avatar",style:{height:"100%",width:"100%",borderRadius:"100%"}})}):Qe("div",{className:os.avatar,style:{height:s,width:s,borderRadius:s,backgroundColor:c.theme.background.disabled},children:Qe("p",{style:{fontSize:35*.5,fontWeight:"bold",textTransform:"capitalize",color:c.theme.text.secondary},children:e})})},ae=sn;import R from"./components/message-item/message-item.module.module.css";import nn from"./components/options-panel/options-panel.module.module.css";import{jsx as qe}from"react/jsx-runtime";var on=e=>{let{setEditDetails:t,message:s,canEdit:n,openEmojiPanel:c,optionsMenuRef:m,mousePosition:i,client:l,conversationId:r,closeOptionsMenu:a,textInputRef:g}=e,o=[{title:"Edit message",onPress:()=>{t({message:s,isEditing:!0}),a()},enabled:n},{title:"Reply",onPress:()=>{t({message:s,isReplying:!0}),a(),g.current?.focus()},enabled:!0},{title:"Add reaction",onPress:()=>{c()},enabled:!0},{title:"Delete",onPress:()=>{l.messageClient(r).deleteMessage(s.messageId,s.to,r)},enabled:n}];return qe("div",{ref:m,className:`${nn.options}`,children:qe("ul",{children:o.map((f,d)=>{if(f.enabled)return qe("li",{onClick:f.onPress,children:qe(x,{size:"sm",text:f.title})},d)})})})},is=on;import{ThreeDots as an}from"react-loader-spinner";import{BsCheck as rn,BsCheckAll as ln,BsClock as as,BsX as cn}from"react-icons/bs";import{MessageStates as Oe}from"softchatjs-core";import{Fragment as gn,jsx as v,jsxs as re}from"react/jsx-runtime";var rs=e=>{let{message:t,index:s,onPress:n,show:c,setEditDetails:m,canEdit:i,showEmojiPanel:l,openEmojiPanel:r,optionsMenuRef:a,emojiPickerRef:g,mousePosition:o,client:f,conversationId:d,closeOptionsMenu:M,scrollToQuote:J,textInputRef:k,recipientId:oe,hideAvartar:P}=e,S=t?.attachedMedia?.length,{config:B}=w(),V=!0;var X=f.chatUserId;let O=t.messageOwner.uid===X&&V,ue=t.messageOwner.uid===X?B.theme?.chatBubble?.right?.bgColor:B.theme?.chatBubble?.left?.bgColor||"#343434",ie=t.messageOwner.uid===X?B.theme?.chatBubble?.right?.messageColor:B.theme?.chatBubble?.left?.messageColor||"white",z=t.messageOwner.uid===X?B.theme?.chatBubble?.right?.messageTimeColor:B.theme?.chatBubble?.left?.messageTimeColor||"grey",D=()=>t.messageState===Oe.SENT?v(rn,{style:{marginTop:"8px",color:"grey"}}):t.messageState===Oe.DELIVERED||t.messageState===Oe.READ?v(ln,{style:{marginTop:"8px",color:"grey"}}):t.messageState===Oe.LOADING?v(as,{style:{marginTop:"8px",color:"grey"}}):t.messageState===Oe.FAILED?v(cn,{style:{marginTop:"8px",color:"red"}}):v(as,{style:{marginTop:"8px",color:"grey"}});return re("div",{className:`${R.conversation}`,onContextMenu:W=>{n(W,s,t)},children:[re("div",{className:`${O?R.conversation__wrapper__alternate:R.conversation__wrapper}`,children:[!O&&v("div",{className:R.conversation__image,children:P?null:v(ae,{initials:t.messageOwner.username.substring(0,1),url:t.messageOwner.profileUrl})}),re("div",{style:{display:"flex",alignItems:"flex-start",flexDirection:"column",justifyContent:"flex-start"},children:[l?v(Ut,{conversationId:d,client:f,emojiPickerRef:g,message:t,recipientId:oe,setShowEmojiPanel:e.setShowEmojiPanel}):null,re("div",{className:R.conversation__text__container,children:[O&&v("div",{className:R.conversation__text__container__reactions,children:v(ct,{textInputRef:k,optionsMenuRef:a,canEdit:i,message:t,setEditDetails:m,openEmojiPanel:r,mousePosition:o,client:f,conversationId:d,closeOptionsMenu:M})}),v("div",{style:{display:"flex",alignItems:"flex-end"},children:re("div",{style:{backgroundColor:ue},className:`${R.conversation__text__wrap} ${S?R.conversation__text__wrap__attach:R.conversation__text__wrap__no__attach} ${P?R.conversation__text__wrap__half__border:`${O?R.conversation__text__wrap__border__alternate:R.conversation__text__wrap__border}`}`,children:[t.quotedMessageId&&v(un,{scrollToQuote:J,message:t?.quotedMessage}),S?v(mn,{attachments:t.attachedMedia}):null,t.message?re("div",{style:{alignItems:"center",paddingLeft:S&&"10px",paddingRight:S&&"10px",justifyContent:"space-between",wordWrap:"break-word"},children:[v(x,{styles:{textAlign:"left",marginRight:"15px",color:ie},size:"sm",text:t?.message}),re("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",marginTop:t?.message?.length>10?"0px":"-25px"},children:[t.lastEdited&&v(x,{styles:{textAlign:"right",marginRight:"5px",color:z,fontSize:"9px"},size:"sm",text:"(Edited)"}),v(x,{size:"xs",styles:{color:z},text:jt(t.createdAt)}),O&&v(gn,{children:D()})]})]}):null]})}),!O&&v("div",{className:R.conversation__text__container__reactions,children:v(ct,{textInputRef:k,optionsMenuRef:a,canEdit:i,message:t,setEditDetails:m,openEmojiPanel:r,mousePosition:o,client:f,conversationId:d,closeOptionsMenu:M})})]}),v("div",{style:{width:"100%",display:"flex",justifyContent:O?"flex-end":"flex-start"},children:v(dn,{reactions:t.reactions,message:t})})]})]}),c?v(is,{textInputRef:k,optionsMenuRef:a,canEdit:i,message:t,setEditDetails:m,openEmojiPanel:r,mousePosition:o,client:f,conversationId:d,closeOptionsMenu:M}):null]})},dn=({reactions:e,message:t})=>{let{client:s}=w(),{conversationId:n}=t,c=s.messageClient(n),m=({emojiId:i})=>{let l=e.filter(r=>r.uid!==i);c.reactToMessage({conversationId:n,messageId:t.messageId,reactions:l,to:"30"})};return v("div",{className:R.emoji,children:e.map((i,l)=>v("div",{onClick:()=>m({emojiId:i.uid}),className:R.emoji__wrap,children:v("p",{children:i.emoji})},l))})},mn=({attachments:e})=>{let{setShowImageModal:t}=_();return v("div",{className:R.attachments,children:e.map((s,n)=>{if(s.type==="image")return v("img",{onClick:()=>t(e),src:s.mediaUrl,className:R.image,alt:"attached-images"},`${n}-attch`);if(s.type==="video")return v("video",{onClick:()=>t(e),src:s.mediaUrl,className:R.image,controls:!0},`${n}-attch`);if(s.type==="audio")return v(Ne,{url:s?.mediaUrl,duration:s?.meta?.audioDurationSec||0,blob:null})})})},un=({message:e,scrollToQuote:t})=>{let s=e?.messageOwner?.username;return re("div",{className:R.quote,onClick:()=>t(e.messageId),children:[re("div",{children:[v(x,{styles:{color:"greenyellow",textAlign:"left"},size:"sm",weight:"bold",text:s?.length>30?`${s?.slice(0,5)}...`:s}),v(x,{size:"xs",text:e?.message,styles:{textAlign:"left"}})]}),v("img",{src:e?.attachedMedia[0]?.mediaUrl,alt:""})]})};var ls=({message:e})=>re("div",{className:R.typing__wrap,children:[v("div",{style:{marginRight:"10px"},children:v(ae,{initials:e.messageOwner.username.substring(0,1),url:e.messageOwner.profileUrl})}),v(an,{visible:!0,height:"20",width:"50",color:"#343434",radius:"9",ariaLabel:"three-dots-loading",wrapperClass:""})]});import hn from"moment";import{jsx as ne,jsxs as Ct}from"react/jsx-runtime";var vn=e=>{let{messages:t=[],setEditDetails:s,recipientTyping:n,mousePosition:c,conversationId:m,client:i,textInputRef:l,setPresentPage:r,presentPage:a,recipientId:g,scrollToKey:o,fetchingMore:f,messagesEndRef:d,renderChatBubble:M,renderChatHeader:J,headerHeightOffset:k,getOlderMessages:oe,customHeight:P}=e,S=et(),[B,V]=Be(!1),[X,O]=Be(!1),[ue,ie]=Be(""),[z,D]=Be(""),W=et(null),A=et(null),[G,Ie]=Be({}),{activeConversation:ge}=_(),{config:$}=w(),[nt,q]=Be(!1),ye=et({}),j=$.theme,be=$?.theme?.text?.primary||"white";var Se=null;function Y(){return window.innerHeight-80-60-k}let ee=(y,h)=>{y.preventDefault(),O(!1),V(!0),ie(h)},xe=y=>{B&&!W.current?.contains(y.target)&&V(!1),X&&!A.current?.contains(y.target)&&O(!1)},Me=y=>{O(!0),ie(y)};pt(()=>{document.addEventListener("mousedown",xe)},[W,A,xe]);let He=y=>{d.current&&d.current.scrollIntoView({behavior:y===!0?"instant":"smooth"})};pt(()=>{t.length>0&&t.map(y=>{Ie(h=>{let I={...h};return I[y.messageId]=Cn(),I})})},[t]),pt(()=>{He()},[ge]);let pe=y=>{try{D(y);let h=G[y];h.current&&(h.current.style.backgroundColor="#282c34",h.current.style.transition="0.5s",setTimeout(()=>{h.current.style.backgroundColor="transparent"},1500),h?.current.scrollIntoView({behavior:"smooth",block:"center"}))}catch(h){console.log(h)}},Ce=t.reduce((y,h)=>{let I=hn(h.createdAt).format("MMMM DD, YYYY"),F=y.find(K=>K.date===I);if(F)F.messages.push(h);else{let K={date:I,messages:[h]};y.push(K)}return y},[]),ot=()=>{if(S.current.scrollTop===0){let y=S.current.scrollHeight;r(I=>I+1);let h=S.current.scrollHeight;S.current.scrollTop=h-y}},ze=y=>{try{let h=S.current,I=h.scrollHeight,F=h.scrollTop,{scrollTop:K}=y.target,ke=Y();K<=0&&oe(()=>{})}catch(h){console.error(h.message)}};fn(()=>{try{if(!o||S.current.scrollTop!==0)return;ye.current[o]&&ye.current[o].scrollIntoView()}catch(y){console.error(y.message)}},[o]);let Re=pn(()=>P?`calc(${P}px - 80px - 60px - ${k}px)`:`calc(100vh - 80px - 60px - ${k}px)`,[P]);return Ct("div",{ref:S,onScroll:ze,className:tt.wrapper,style:{height:Re},children:[f&&ne("div",{className:tt.loading,children:ne(x,{styles:{color:"white"},size:"sm",text:"Loading more..."})}),Ce.map((y,h)=>Ct("div",{className:tt.wrapper__sec,children:[Ct("div",{style:{justifyContent:"center",display:"flex",width:"100%",alignItems:"center"},children:[ne("div",{style:{flex:1,height:".5px",width:"100%",backgroundColor:j?.divider}}),ne("div",{style:{backgroundColor:$?.theme?.background?.secondary||"#1b1d21"},className:tt.wrapper__date,children:ne(x,{styles:{color:be},size:"xs",text:Vt(y.date)})}),ne("div",{style:{flex:1,height:".5px",width:"100%",backgroundColor:j?.divider}})]},`${h}-sec`),y.messages.map((I,F)=>ne("div",{ref:K=>ye.current[I.messageId]=K,children:ne("div",{ref:G[I?.messageId],children:e.renderChatBubble?e.renderChatBubble(I):ne(rs,{hideAvartar:I.messageOwner.uid===y.messages[F+1]?.messageOwner.uid,textInputRef:l,show:B&&ue==I.messageId,showEmojiPanel:X&&ue==I.messageId,index:F,message:I,onPress:K=>ee(K,I.messageId),setEditDetails:s,canEdit:I.from===i?.chatUserId,openEmojiPanel:()=>Me(I.messageId),optionsMenuRef:W,emojiPickerRef:A,mousePosition:c,client:i,conversationId:m,closeOptionsMenu:()=>V(!1),scrollToQuote:pe,recipientId:g,setShowEmojiPanel:O},F)})}))]},h)),n&&ne(ls,{message:Ce[0]?.messages[0]}),ne("div",{ref:d,style:{height:"1px",width:"100%"}})]})},ft=vn;import{useState as bn,useMemo as xn}from"react";import ve from"./components/user-conversations/index.module.module.css";import{useState as yn}from"react";import{jsx as je,jsxs as cs}from"react/jsx-runtime";function ht({connectionStatus:e,theme:t,onTextChange:s}){let[n,c]=yn(""),m=i=>{c(i),s(i)};return cs("div",{style:{width:"100%",padding:"20px"},children:[je("div",{children:e.isConnected?cs("span",{style:{display:"flex",alignItems:"center",color:t.text.primary},children:[je("p",{style:{fontWeight:"bold",fontSize:"26px"},children:"Chats"}),je("span",{style:{marginLeft:10,height:"5px",width:"5px",borderRadius:"5px",backgroundColor:"green"}})]}):je("p",{style:{color:t.text.primary},children:"Connecting..."})}),je("input",{value:n,onChange:i=>m(i.target.value),placeholder:"Search chats",style:{height:"40px",width:"100%",marginTop:"15px",textIndent:"15px",backgroundColor:"transparent",border:`1px solid ${t.divider}`,borderRadius:"10px",color:t.text.primary}})]})}import{IoCloseCircle as Mn}from"react-icons/io5";import{jsx as L,jsxs as le}from"react/jsx-runtime";var ds=({setMainListOpen:e,setShowUserList:t,showUserList:s,userListRef:n,renderConversationList:c,connectionStatus:m,resetState:i})=>{let{client:l,config:r}=w(),{setActiveConversation:a,conversations:g}=_(),[o,f]=bn("");if(c)return L("div",{style:{width:"100%",height:"100%",background:"green",position:"relative"},children:c({conversations:g,onCoversationItemClick:M=>{a(M),e(!1)}})});let d=xn(()=>{try{let M=l.chatUserId;return g.filter(k=>k.conversation.participantList.some(P=>{let S=P.participantDetails.username.toLowerCase(),B=P.participantDetails?.firstname?.toLowerCase()||"",V=P.participantDetails?.lastname?.toLowerCase()||"";return P.participantDetails?.uid!==M&&(S.includes(o.toLowerCase())||B.includes(o.toLowerCase())||V.includes(o.toLowerCase()))}))}catch{return g}},[g,o]);return le("div",{style:{background:r?.theme?.background?.secondary,borderRight:`1px solid ${r.theme.divider}`},className:ve.list,children:[L(ht,{connectionStatus:m,theme:r.theme,onTextChange:M=>f(M)}),d.length===0&&L("div",{className:ve.list__empty,children:L(x,{styles:{textAlign:"center",color:r.theme.text.primary},text:"Start a new conversation."})}),d.map((M,J)=>L(wn,{item:M,onClick:()=>{a(M),e(!1),i()},borderBottom:""},J))]})},wn=({item:e,onClick:t,borderBottom:s})=>{let{client:n,config:c}=w(),{activeConversation:m}=_(),i=e.conversation.participantList.filter(a=>a.participantId!==n.chatUserId),l=c?.theme?.text?.primary||"white",r=()=>e.lastMessage?.attachmentType==="media"?le("div",{className:ve.media,children:[L("img",{src:e.lastMessage.attachedMedia.find(a=>a.type==="image")?.mediaUrl,alt:""}),L(x,{styles:{textAlign:"left",color:l},size:"sm",text:"Media"})]}):L(x,{styles:{textAlign:"left",color:l},size:"sm",text:e.lastMessage?.message?.length>75?e.lastMessage?.message?.substring(0,75)+"...":e.lastMessage?.message});return le("div",{className:ve.item,onClick:t,children:[L("div",{style:{marginRight:"10px"},children:i[0]&&L(ae,{initials:i[0]?.participantDetails?.username?.substring(0,1),size:40,url:i[0]?.participantDetails?.profileUrl})}),le("div",{style:{width:"100%",padding:"20px 0px 20px 0px",borderBottom:s},children:[le("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[le("div",{style:{display:"flex",alignItems:"center"},children:[L(x,{styles:{textAlign:"left",color:l,textTransform:"capitalize",marginRight:"5px"},weight:"bold",text:i[0]?.participantDetails?.username}),e.conversation.conversationType==="admin-chat"&&L(Wt,{size:15,color:c.theme.icon})]}),L(x,{size:"sm",styles:{color:l},text:$t(e.lastMessage?.createdAt)})]}),le("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[r(),e.unread.length>0&&L("div",{className:ve.unread,children:L(x,{size:"xs",text:String(e.unread.length),styles:{color:"black"}})})]})]})]})},ms=({users:e=[],userListRef:t,close:s})=>{let{client:n,config:c}=w(),m=i=>{try{n.newConversation(i,null).create("Hey there \u{1F44B}"),s()}catch(l){console.error(l?.message)}};return le("div",{ref:t,style:{background:c?.theme?.background?.secondary||"#202326"},className:ve.userList,children:[le("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:15},children:[L(x,{styles:{color:c?.theme?.text?.primary||"white"},text:"Users"}),L("button",{onClick:s,style:{backgroundColor:"transparent",border:0,cursor:"pointer"},children:L(Mn,{size:22})})]}),L("div",{className:ve.scrollbar,style:{overflowY:"scroll",height:"300px"},children:e.map((i,l)=>le("div",{onClick:()=>{m(i)},className:ve.userList__wrap,children:[L(ae,{initials:i.username.substring(0,1),url:i.profileUrl}),L("div",{className:ve.userList__user,style:{marginLeft:"6px"},children:L(x,{size:"sm",text:i.username,styles:{color:c?.theme?.text?.primary||"white"}})})]},l))})]})};import Ve from"./components/modals/image.module.module.css";import{GrNext as In,GrPrevious as Ln}from"react-icons/gr";import{useState as Sn}from"react";import{LiaTimesSolid as Rn}from"react-icons/lia";import{jsx as ce,jsxs as us}from"react/jsx-runtime";var vt=()=>{let{showImageModal:e,setShowImageModal:t}=_(),[s,n]=Sn(0);return us("div",{className:Ve.images,children:[ce(Rn,{color:"white",size:35,onClick:()=>{t([])},style:{position:"absolute",top:"20px",right:"20px"}}),ce("div",{className:Ve.images__prev,children:s===0?null:ce("div",{style:{padding:"10px"},children:ce(Ln,{onClick:()=>n(s-1),color:"white",size:35,style:{cursor:"pointer"}})})}),ce("div",{className:Ve.images__center,children:us("div",{className:Ve.images__center__items,children:[e[s].type==="image"&&ce("img",{onClick:c=>{c.stopPropagation()},src:e[s].mediaUrl,alt:""}),e[s].type==="video"&&ce("video",{onClick:c=>{c.stopPropagation()},src:e[s].mediaUrl,controls:!0})]})}),ce("div",{className:Ve.images__next,children:s===e.length-1?null:ce("div",{style:{padding:"10px"},children:ce(In,{onClick:()=>n(s+1),color:"white",size:35,style:{cursor:"pointer"}})})})]})};import gs from"./components/chat/chat.module.module.css";import{MdOutlineClose as kn}from"react-icons/md";import{jsx as st,jsxs as En}from"react/jsx-runtime";var yt=({setMainListOpen:e,renderChatHeader:t,onClose:s,chatUserId:n})=>{let{client:c,config:m}=w(),{activeConversation:i,setActiveConversation:l}=_(),{theme:r}=m,a=()=>{try{let o=i.conversation.participantList.filter(f=>f.participantDetails.uid!==n);return{profileUrl:o[0].participantDetails.profileUrl,title:o[0].participantDetails.firstname||o[0].participantDetails.username}}catch{return{profileUrl:"https://avatar.iran.liara.run/public",title:"No name"}}};return st("div",{style:{backgroundColor:r?.background?.secondary||"#222529"},className:gs.topnav,children:t?t():En("div",{style:{paddingLeft:"10px",display:"flex",justifyContent:"space-between",width:"100%",padding:"15px",alignItems:"center"},children:[st(ae,{initials:a().title.substring(0,1),url:a().profileUrl}),st("div",{className:gs.topnav__menu,style:{},children:st(kn,{color:r?.icon,onClick:()=>{e(!0),l(null),s()},size:22})})]})})};import{useState as Tn,useCallback as _n}from"react";import"./components/navigation/navigation.css";import{Fragment as ps,jsx as de,jsxs as Cs}from"react/jsx-runtime";function bt(e){let{client:t,config:s}=w(),{setActiveConversation:n}=_(),[c,m]=Tn(!1),i=[{label:"Chats",icon:de(Qt,{color:s.theme.icon,size:25}),key:"conversation-list",onClick:()=>{e.onViewChanged("conversation-list"),n(null)},visible:!0},{label:"New chat",icon:de(Gt,{color:s.theme.icon,size:25}),key:"new-chat",onClick:()=>m(!0),visible:e.userList.length>0},{label:"Broadcast lists",icon:de(Yt,{color:s.theme.icon,size:25}),key:"broadcast-lists",onClick:()=>{e.onViewChanged("broadcast-lists"),n(null)},visible:e.enableBroadcasts}];if(e.renderNavbar)return de("div",{style:{height:"100%",maxWidth:"50px",borderRight:`1px solid ${s.theme.divider}`,display:"flex",flexDirection:"column",alignItems:"center"},children:e.renderNavbar(i)});let l=_n(()=>de(ps,{children:i.filter(r=>r.visible).map((r,a)=>de("button",{className:"nav-btn",style:{borderRight:0,borderTop:0,borderBottom:0,cursor:e.connectionStatus.isConnected?"pointer":"progress",borderLeft:e.activeView===r.key?`2px solid ${s.theme.icon}`:`2px solid ${s.theme.background.secondary}`},title:r.label,onClick:()=>e.connectionStatus.isConnected?r.onClick():null,children:r.icon},a))}),[i,s.theme,e.activeView,e.connectionStatus]);return Cs(ps,{children:[Cs("div",{style:{height:"100%",width:"50px",backgroundColor:s.theme.background.secondary,borderRight:`1px solid ${s.theme.divider}`,display:"flex",flexDirection:"column",alignItems:"center",paddingTop:"20px",justifyContent:"space-between"},children:[de("label",{title:"Me",children:de(ae,{url:e.chatUser.profileUrl,size:30,initials:e.chatUser.username.substring(0,1)})}),de("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%"},children:l()})]}),c&&de(ms,{users:e.userList,userListRef:null,close:()=>m(!1)})]})}import{useEffect as Pn,useState as Dn}from"react";import fs from"./components/broadcast-lists/broadcast-lists.module.module.css";import{PiPlusCircle as An}from"react-icons/pi";import{jsx as we,jsxs as $e}from"react/jsx-runtime";function xt(e){let{onCreateBroadcastList:t}=e,{client:s,config:n}=w(),{setActiveConversation:c}=_(),[m,i]=Dn([]),l=a=>{let g=Object.values(a.broadcastListMeta).flat();i(g)},r=()=>{try{let a=s.getBroadcastLists(),g=Object.values(a).flat();i(g)}catch{}};return Pn(()=>(s&&(r(),s.subscribe("broadcast_list_meta_changed",l)),()=>{s.unsubscribe("broadcast_list_meta_changed",l)}),[s]),$e("main",{className:fs.broadcast_container,style:{borderRight:`1px solid ${n.theme.divider}`,backgroundColor:n.theme.background.secondary,padding:"20px"},children:[$e("div",{style:{display:"flex",justifyContent:"space-between",width:"100%",alignItems:"center"},children:[we("p",{style:{fontWeight:"bold",fontSize:"26px"},children:"Broadcast lists"}),we("button",{onClick:()=>t?.(),style:{border:0,backgroundColor:"transparent"},children:we(An,{size:22,color:n.theme.icon})})]}),$e("div",{style:{},children:[m.length===0&&we("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:we(x,{styles:{textAlign:"left",marginRight:"15px",color:n.theme.text.disabled},size:"sm",text:"No broadcast lists available yet"})}),m.length>0&&m.map((a,g)=>$e("div",{className:fs.broadcast_item,onClick:()=>c(a),children:[$e("div",{children:[we(x,{styles:{textAlign:"left",marginRight:"15px",color:n.theme.text.primary},size:"md",text:a.conversation.name}),we(x,{styles:{textAlign:"left",marginRight:"15px",color:n.theme.text.disabled},size:"sm",text:`${a.conversation.participants.length} recipients`})]}),we(Kt,{size:10,color:n.theme.icon})]},g))]})]})}import{jsx as Z,jsxs as Ze}from"react/jsx-runtime";var Bn=e=>{let{headerHeightOffset:t=0,user:s,userList:n=[],onCreateBroadcastList:c,activeConversationId:m,webToken:i,enableBroadcasts:l=!0,height:r,width:a}=e,g=s.uid,{client:o,config:f}=w(),{activeConversation:d,showImageModal:M,setActiveConversation:J,setConversations:k,conversations:oe,connectionStatus:P,setConnectionStatus:S}=_(),[B,V]=H(!1),[X,O]=H(!1),[ue,ie]=H(!1),[z,D]=H([]),[W,A]=H(),[G,Ie]=H(!1),[ge,$]=H(1),[nt,q]=H(!0),[ye,j]=H(!1),[be,Se]=H(""),Y=Fe(null),[ee,xe]=H(0),[Me,He]=H(""),[pe,Ce]=H(!1),[ot,ze]=H(0),[Re,y]=H("conversation-list"),h=Fe(null),{theme:I}=f,[F,K]=H({x:0,y:0}),[ke,p]=H({element:null}),E=Fe(null),T=Fe(null),Ee=Fe(null),Le=()=>{$(1)},Te=u=>{ke.element&&!E.current?.contains(u.target)&&p({element:null}),Ee.current?.contains(u.target)||j(!1)},hs=()=>{try{if(m){let b=o.getConversations()[m];b&&J(b)}}catch(u){console.error(u.message)}};me(()=>{hs()},[m,o,P]),me(()=>{e.user&&i?o.initializeUser(e.user,{notificationConfig:{type:"fcm",token:i}}):o.initializeUser(e.user)},[e.user,i]),me(()=>{let u=()=>{let fe=window.innerWidth,at=window.innerHeight;Ce(fe<1024||at<768)};if(!a||!r)return u(),window.addEventListener("resize",u),()=>window.removeEventListener("resize",u);let b=()=>{if(!h.current)return;let{offsetWidth:fe,offsetHeight:at}=h.current;Ce(fe<1024||at<768)},te=new ResizeObserver(()=>b());return h.current&&(te.observe(h.current),b()),()=>te.disconnect()},[r,a]),me(()=>{document.addEventListener("mousedown",Te)},[E,Te]);let it=u=>{d&&u.message.conversationId===d.conversation.conversationId&&(D(b=>[...b,u.message]),xe(ee+1),setTimeout(()=>{Y?.current?.scrollIntoView({block:"end",behavior:"smooth"})},300))},wt=u=>{d&&d.conversation.conversationId===u.conversationId&&Ie(!0)},It=u=>{Ie(!1)},Lt=u=>{D(b=>b.filter(te=>te.messageId!==u.message.messageId))},St=u=>{D(b=>[...b.map(fe=>fe?.messageId===u?.message?.messageId?{...fe,...u.message}:fe)])},Rt=u=>{S(u)},kt=u=>{let b=Object.values(u.conversationListMeta).flat();b.sort((te,fe)=>new Date(fe.lastMessage?.createdAt).getTime()-new Date(te.l