import{a as k}from"./chunk-XQML45PF.mjs";import{a as B}from"./chunk-VUPE7HCP.mjs";import{a as V}from"./chunk-WSOAFMXJ.mjs";import{a as N}from"./chunk-PJUFVCZA.mjs";import{a as G}from"./chunk-OVDSMD55.mjs";import{a as U}from"./chunk-ZJGJJJ63.mjs";import{a as p,b as F}from"./chunk-Z54XQJNN.mjs";import{b as D}from"./chunk-GX4RCPNI.mjs";import{b as E}from"./chunk-QT7GKZLD.mjs";import{useMemo as xt}from"react";import{IconButton as $}from"@baseapp-frontend/design-system/components/web/buttons";import{CheckMarkIcon as St}from"@baseapp-frontend/design-system/components/web/icons";import{Iconify as Ct}from"@baseapp-frontend/design-system/components/web/images";import{setFormRelayErrors as Ot,useNotification as Lt}from"@baseapp-frontend/utils";import{zodResolver as It}from"@hookform/resolvers/zod";import{Box as Rt,Typography as jt}from"@mui/material";import{useForm as Tt}from"react-hook-form";import{jsx as c,jsxs as W}from"react/jsx-runtime";function h(t){"@babel/helpers - typeof";return h=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h(t)}function H(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(m){return Object.getOwnPropertyDescriptor(t,m).enumerable})),r.push.apply(r,o)}return r}function O(t){for(var e=1;e<arguments.length;e++){var r=arguments[e]!=null?arguments[e]:{};e%2?H(Object(r),!0).forEach(function(o){pt(t,o,r[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(r,o))})}return t}function pt(t,e,r){return(e=ft(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ft(t){var e=bt(t,"string");return h(e)=="symbol"?e:e+""}function bt(t,e){if(h(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var o=r.call(t,e||"default");if(h(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function vt(t){return Mt(t)||ht(t)||z(t)||yt()}function yt(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ht(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Mt(t){if(Array.isArray(t))return L(t)}function At(t,e){return _t(t)||Pt(t,e)||z(t,e)||gt()}function gt(){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 z(t,e){if(t){if(typeof t=="string")return L(t,e);var r={}.toString.call(t).slice(8,-1);return r==="Object"&&t.constructor&&(r=t.constructor.name),r==="Map"||r==="Set"?Array.from(t):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?L(t,e):void 0}}function L(t,e){(e==null||e>t.length)&&(e=t.length);for(var r=0,o=Array(e);r<e;r++)o[r]=t[r];return o}function Pt(t,e){var r=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(r!=null){var o,m,M,f,l=[],s=!0,b=!1;try{if(M=(r=r.call(t)).next,e===0){if(Object(r)!==r)return;s=!1}else for(;!(s=(o=M.call(r)).done)&&(l.push(o.value),l.length!==e);s=!0);}catch(A){b=!0,m=A}finally{try{if(!s&&r.return!=null&&(f=r.return(),Object(f)!==f))return}finally{if(b)throw m}}return l}}function _t(t){if(Array.isArray(t))return t}var wt=function(e){var r,o,m=e.allProfilesRef,M=e.onClose,f=e.handleSubmitSuccess,l=e.profileId,s=e.roomId,b=e.isPending,A=e.GroupChatMembersList,K=A===void 0?U:A,I=e.GroupChatMembersListProps,u=I===void 0?{}:I,R=e.existingMembers,q=R===void 0?[]:R,J=Lt(),Q=J.sendToast,v=D(m),g=v.data.allProfiles,X=v.loadNext,Y=v.isLoadingNext,Z=v.hasNext,tt=v.refetch,d=Tt({defaultValues:F,resolver:It(k),mode:"onBlur"}),x=d.setValue,j=d.watch,et=d.getFieldState,rt=d.handleSubmit,ot=d.formState.isDirty,it=d.reset,nt=E(),T=At(nt,2),at=T[0],lt=T[1],st=rt(function(i){if(s){var n=i.participants,a=(n||[]).map(function(_){return _?.id});at({variables:{input:{roomId:s,profileId:l,addParticipants:a},connections:[]},onCompleted:function(S){var C,w=S==null||(C=S.chatRoomUpdate)===null||C===void 0?void 0:C.errors;w?(Q("Something went wrong",{type:"error"}),Ot(d,w)):(f(),it())}})}}),y=j(p.participants),ut=xt(function(){return g?.edges.filter(function(i){return i?.node&&i?.node.id!==l}).map(function(i){return i?.node})||[]},[g,l]),dt=!ot||et(p.participants).invalid,ct=function(n){x(p.participants,[].concat(vt(y),[n]),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},mt=function(n){x(p.participants,y.filter(function(a){return a?.id!==n?.id}),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},P=y.length===0;return W(Rt,{children:[W(G,{children:[c($,{onClick:M,"aria-label":"cancel adding member",children:c(Ct,{icon:"eva:arrow-ios-back-fill",width:24})}),c(jt,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"Add Member"}),c($,{"aria-label":"Add Member",disabled:dt||b,isLoading:lt||b,onClick:function(){st()},children:c(St,{sx:{fontSize:"24px"}})})]}),c(K,O({FORM_VALUE:p,setValue:x,watch:j,currentParticipants:y,connections:ut,refetch:tt,SearchbarContainer:B,connectionsLoadNext:X,connectionsHasNext:Z,connectionsIsLoadingNext:Y,ConnectionsListProps:O({VirtuosoProps:{style:{height:"100%",maxHeight:P?"calc(100vh - 72px - 57px - 69px)":"calc(100vh - 72px - 57px - 69px - 130px)"}},title:"",removeTitle:P,renderItem:function(n){return n?c(N,{profile:n,handleAddMember:ct,handleRemoveMember:mt,isBeingAdded:y.some(function(a){return a?.id===n?.id}),isExistingMember:q.some(function(a){return a?.id===n?.id})}):null}},(r=u?.ConnectionsListProps)!==null&&r!==void 0?r:{}),MembersListProps:O({removeTitle:P,title:"",NormalListProps:{sx:{display:"flex",justifyContent:"start",alignItems:"center",padding:P?0:"12px",scrollbarWidth:"none"}}},(o=u?.MembersListProps)!==null&&o!==void 0?o:{}),ProfileCard:V},u))]})},Yt=wt;export{Yt as a};
//# sourceMappingURL=chunk-P2QH2MWZ.mjs.map