import{a as N}from"./chunk-J7VT6ZFM.mjs";import{a as E}from"./chunk-CDPIEDTG.mjs";import{b as $}from"./chunk-E6EXMZU2.mjs";import{b as A}from"./chunk-27TIXLPX.mjs";import{a as G}from"./chunk-4LJMYL4Z.mjs";import{a as L}from"./chunk-UB5P4QTT.mjs";import{b as R}from"./chunk-A5QFDUFT.mjs";import{useCallback as de,useEffect as ve,useMemo as F,useRef as fe}from"react";import{useCurrentProfile as ce}from"@baseapp-frontend/authentication";import{LoadingState as me}from"@baseapp-frontend/design-system/components/web/displays";import{Box as ge}from"@mui/material";import{usePaginationFragment as pe}from"react-relay";import{Virtuoso as ye}from"react-virtuoso";import{jsx as y}from"react/jsx-runtime";function b(e){"@babel/helpers - typeof";return b=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},b(e)}function T(e,r){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(d){return Object.getOwnPropertyDescriptor(e,d).enumerable})),o.push.apply(o,n)}return o}function C(e){for(var r=1;r<arguments.length;r++){var o=arguments[r]!=null?arguments[r]:{};r%2?T(Object(o),!0).forEach(function(n){oe(e,n,o[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):T(Object(o)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(o,n))})}return e}function oe(e,r,o){return(r=te(r))in e?Object.defineProperty(e,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[r]=o,e}function te(e){var r=ne(e,"string");return b(r)=="symbol"?r:r+""}function ne(e,r){if(b(e)!="object"||!e)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var n=o.call(e,r||"default");if(b(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function ie(e,r){return le(e)||ue(e,r)||ae(e,r)||se()}function se(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ae(e,r){if(e){if(typeof e=="string")return D(e,r);var o={}.toString.call(e).slice(8,-1);return o==="Object"&&e.constructor&&(o=e.constructor.name),o==="Map"||o==="Set"?Array.from(e):o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?D(e,r):void 0}}function D(e,r){(r==null||r>e.length)&&(r=e.length);for(var o=0,n=Array(r);o<r;o++)n[o]=e[o];return n}function ue(e,r){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var n,d,f,c,m=[],v=!0,g=!1;try{if(f=(o=o.call(e)).next,r===0){if(Object(o)!==o)return;v=!1}else for(;!(v=(n=f.call(o)).done)&&(m.push(n.value),m.length!==r);v=!0);}catch(M){g=!0,d=M}finally{try{if(!v&&o.return!=null&&(c=o.return(),Object(c)!==c))return}finally{if(g)throw d}}return m}}function le(e){if(Array.isArray(e))return e}var be=function(r){var o,n,d,f,c=r.roomRef,m=r.VirtuosoProps,v=r.MessagesGroup,g=v===void 0?N:v,M=r.MessagesGroupProps,I=M===void 0?{}:M,h=pe(G,c),t=h.data,U=h.loadNext,k=h.isLoadingNext,O=h.hasNext,H=(o=t==null||(n=t.allMessages)===null||n===void 0?void 0:n.totalCount)!==null&&o!==void 0?o:0,V=fe(null),a=F(function(){var s;return(t==null||(s=t.allMessages)===null||s===void 0?void 0:s.edges.filter(function(i){return i?.node}).map(function(i){return i?.node}))||[]},[t==null||(d=t.allMessages)===null||d===void 0?void 0:d.edges]),S=Number(a?.length)-1,x=Math.max(H-a.length,0),B=ce(),u=B.currentProfile,K=L(),X=K.id,z=A(),W=ie(z,1),Y=W[0],q=function(){var i,p;if(!(t!=null&&(i=t.unreadMessages)!==null&&i!==void 0&&i.count))return null;var P=a.filter(function(l){return l?.messageType===R.user});return(p=P.find(function(l,ee){var j,_=P?.[ee+1],re=!!_;return(l==null||(j=l.profile)===null||j===void 0?void 0:j.id)!==u?.id&&!(l!=null&&l.isRead)&&(!re||_?.isRead)}))===null||p===void 0?void 0:p.id},w=F(q,[X,u]);ve(function(){var s;((t==null||(s=t.unreadMessages)===null||s===void 0?void 0:s.count)!==0||t!=null&&t.unreadMessages.markedUnread)&&Y({variables:{input:{roomId:t?.id,profileId:u?.id}}})},[t?.id,t==null||(f=t.unreadMessages)===null||f===void 0?void 0:f.count,u]),$(t.id,u?.id);var J=function(){return k?y(me,{sx:{height:50},CircularProgressProps:{size:15},"aria-label":"loading more messages"}):y(ge,{sx:{height:50}})},Q=function(){return a.length===0?null:y("div",{className:"h-2"})},Z=de(function(s){var i=a.length-1-(s-x),p=a[i];return y(g,C({allMessages:a,message:p,messageIndex:i,isGroup:t?.isGroup,allMessagesLastIndex:S,firstUnreadMessageId:w,hasNext:O},I))},[a,S,x,O,t?.isGroup,w,g,I]);return y(ye,C({ref:V,firstItemIndex:x,style:{overflowX:"hidden"},initialTopMostItemIndex:S,data:a,itemContent:Z,startReached:function(){O&&U(E)},components:{Header:J,Footer:Q},increaseViewportBy:{top:100,bottom:0},followOutput:"smooth"},m))},Re=be;export{Re as a};
//# sourceMappingURL=chunk-6T5DLBVQ.mjs.map