import{a as Q}from"./chunk-CDU3DYZZ.mjs";import{a as J}from"./chunk-ME2XYUDS.mjs";import{a as Z}from"./chunk-VIR7TRAW.mjs";import{a as s,b as Y}from"./chunk-S7YMICUW.mjs";import{b as G}from"./chunk-K4NCOIN3.mjs";import{b as X}from"./chunk-MH2NYWHW.mjs";import{a as K}from"./chunk-UB5P4QTT.mjs";import{a as z}from"./chunk-53ZWLU5C.mjs";import{useCallback as Ee,useEffect as $e,useMemo as ke,useState as re,useTransition as oe}from"react";import{LoadingState as Ne}from"@baseapp-frontend/design-system/components/web/displays";import{Searchbar as De}from"@baseapp-frontend/design-system/components/web/inputs";import{Box as j,CircularProgress as Ve,Tab as L,Tabs as Be,Typography as Me}from"@mui/material";import{useForm as Fe}from"react-hook-form";import{Virtuoso as qe}from"react-virtuoso";import{jsx as i,jsxs as x}from"react/jsx-runtime";function b(e){"@babel/helpers - typeof";return b=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},b(e)}function ee(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(u){return Object.getOwnPropertyDescriptor(e,u).enumerable})),r.push.apply(r,o)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ee(Object(r),!0).forEach(function(o){je(e,o,r[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ee(Object(r)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))})}return e}function je(e,t,r){return(t=Le(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Le(e){var t=xe(e,"string");return b(t)=="symbol"?t:t+""}function xe(e,t){if(b(e)!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var o=r.call(e,t||"default");if(b(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function C(e,t){return we(e)||Ie(e,t)||Ae(e,t)||Oe()}function Oe(){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,t){if(e){if(typeof e=="string")return te(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?te(e,t):void 0}}function te(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,o=Array(t);r<t;r++)o[r]=e[r];return o}function Ie(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var o,u,f,h,d=[],m=!0,p=!1;try{if(f=(r=r.call(e)).next,t===0){if(Object(r)!==r)return;m=!1}else for(;!(m=(o=f.call(r)).done)&&(d.push(o.value),d.length!==t);m=!0);}catch(g){p=!0,u=g}finally{try{if(!m&&r.return!=null&&(h=r.return(),Object(h)!==h))return}finally{if(p)throw u}}return d}}function we(e){if(Array.isArray(e))return e}var He=function(t){var r,o,u=t.targetRef,f=t.Searchbar,h=f===void 0?De:f,d=t.SearchbarProps,m=d===void 0?{}:d,p=t.ChatRoomItem,g=p===void 0?J:p,O=t.ChatRoomItemProps,A=O===void 0?{}:O,I=t.EmptyChatRoomsState,ne=I===void 0?Q:I,w=t.VirtuosoProps,ae=w===void 0?{}:w,ie=re(s.active),E=C(ie,2),v=E[0],se=E[1],ue=re(!0),$=C(ue,2),le=$[0],k=$[1],ce=oe(),N=C(ce,2),de=N[0],me=N[1],y=X(u==null||(r=u.me)===null||r===void 0?void 0:r.profile),l=y.data,fe=y.loadNext,he=y.isLoadingNext,pe=y.hasNext,R=y.refetch,ve=oe(),D=C(ve,2),V=D[0],B=D[1],P=Fe({defaultValues:{search:""}}),ye=P.control,be=P.reset,ge=P.watch,S=v===s.archived,M=v===s.unread,F=ge("search"),Se=function(a){var c=a.target.value||"";B(function(){R({q:c,unreadMessages:M,archived:S},{fetchPolicy:"network-only"})})},Ce=function(){B(function(){be(),R({q:"",unreadMessages:M,archived:S},{fetchPolicy:"network-only"})})},Re=function(a,c){se(c),me(function(){k(!1),R({q:F,unreadMessages:c===s.unread,archived:c===s.archived},{fetchPolicy:"network-only"})})};$e(function(){k(!0)},[l]);var q=K(),H=q.id,U=q.setChatRoom,W=ke(function(){var n;return(l==null||(n=l.chatRooms)===null||n===void 0||(n=n.edges)===null||n===void 0?void 0:n.filter(function(a){return a?.node}).map(function(a){return a?.node}))||[]},[l==null||(o=l.chatRooms)===null||o===void 0?void 0:o.edges]);G({profileId:l.id,connections:[]});var Pe=Ee(function(n){return n?i(g,T({roomRef:n,isCardSelected:H===n.id,handleClick:function(){U({id:n.id})},isInArchivedTab:S},A)):null},[H,U,A,g,S]),_e=function(){return he?i(Ne,{sx:{paddingTop:3,paddingBottom:1},CircularProgressProps:{size:15},"aria-label":"loading more rooms"}):i(j,{sx:{paddingTop:3}})},_=function(a){return x(j,{display:"grid",gap:1,gridTemplateColumns:"1fr min-content",alignItems:"center",children:[i(Me,{variant:"subtitle2",color:"text.primary",children:Y[a]}),de&&v===a&&i(Ve,{size:15})]})},Te=function(){var a=!V&&W.length===0;if(a)return F?i(z,{}):i(ne,{})};return x(Z,{children:[i(j,{sx:{paddingX:{xs:1.5,sm:2.5},paddingTop:2},children:i(h,T({name:"search",control:ye,onChange:Se,onClear:Ce,isPending:V},m),v)}),x(Be,{value:v,onChange:Re,centered:!0,variant:"fullWidth",sx:{paddingX:{xs:0,sm:2.5},paddingTop:2},children:[i(L,{label:_(s.active),value:s.active}),i(L,{label:_(s.unread),value:s.unread}),i(L,{label:_(s.archived),value:s.archived})]}),Te(),le&&i(qe,T({data:W,overscan:1,itemContent:function(a,c){return Pe(c)},style:{scrollbarWidth:"none"},components:{Footer:_e},endReached:function(){pe&&fe(5)}},ae))]})},ot=He;export{ot as a};
//# sourceMappingURL=chunk-3L7XZGTM.mjs.map