import{a as q}from"./chunk-ABQQTONH.mjs";import{a as J}from"./chunk-P2QH2MWZ.mjs";import{a as X,b as Y}from"./chunk-R5PIY5CX.mjs";import{a as K}from"./chunk-OVDSMD55.mjs";import{a as Q}from"./chunk-AYAYQ6QO.mjs";import{a as W}from"./chunk-ZJGJJJ63.mjs";import{a as f}from"./chunk-Z54XQJNN.mjs";import{b as H}from"./chunk-K4NCOIN3.mjs";import{b as $}from"./chunk-QT7GKZLD.mjs";import{a as B}from"./chunk-O5PFQIB5.mjs";import{a as z}from"./chunk-K5BDVSIZ.mjs";import{a as k}from"./chunk-AZ65ECT7.mjs";import{useMemo as De,useState as Ne,useTransition as Ue}from"react";import{useCurrentProfile as ke}from"@baseapp-frontend/authentication";import{IconButton as re}from"@baseapp-frontend/design-system/components/web/buttons";import{CheckMarkIcon as $e,CloseIcon as Be}from"@baseapp-frontend/design-system/components/web/icons";import{useResponsive as ze}from"@baseapp-frontend/design-system/hooks/web";import{filterDirtyValues as He,setFormRelayErrors as Qe,useNotification as We}from"@baseapp-frontend/utils";import{zodResolver as qe}from"@hookform/resolvers/zod";import{Box as Ke,Typography as Je}from"@mui/material";import{useForm as Xe}from"react-hook-form";import{usePaginationFragment as Ye,usePreloadedQuery as Ze}from"react-relay";import{jsx as a,jsxs as te}from"react/jsx-runtime";function y(r){"@babel/helpers - typeof";return y=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},y(r)}function Z(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(r);e&&(o=o.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,o)}return t}function M(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Z(Object(t),!0).forEach(function(o){Ee(r,o,t[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):Z(Object(t)).forEach(function(o){Object.defineProperty(r,o,Object.getOwnPropertyDescriptor(t,o))})}return r}function Ee(r,e,t){return(e=je(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function je(r){var e=we(r,"string");return y(e)=="symbol"?e:e+""}function we(r,e){if(y(r)!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var o=t.call(r,e||"default");if(y(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function O(r,e){return Ve(r)||Te(r,e)||Ge(r,e)||Fe()}function Fe(){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 Ge(r,e){if(r){if(typeof r=="string")return ee(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?ee(r,e):void 0}}function ee(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,o=Array(e);t<e;t++)o[t]=r[t];return o}function Te(r,e){var t=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(t!=null){var o,s,g,u,m=[],d=!0,b=!1;try{if(g=(t=t.call(r)).next,e===0){if(Object(t)!==t)return;d=!1}else for(;!(d=(o=g.call(t)).done)&&(m.push(o.value),m.length!==e);d=!0);}catch(c){b=!0,s=c}finally{try{if(!d&&t.return!=null&&(u=t.return(),Object(u)!==u))return}finally{if(b)throw s}}return m}}function Ve(r){if(Array.isArray(r))return r}var er=function(e){var t,o=e.profileId,s=e.allProfilesRef,g=e.queryRef,u=e.roomId,m=e.GroupChatMembersList,d=m===void 0?W:m,b=e.GroupChatMembersListProps,c=b===void 0?{}:b,oe=e.onCancellation,ie=e.onRemovalFromGroup,ne=e.onValidSubmission,ae=We(),le=ae.sendToast,ue=Ne(!1),L=O(ue,2),x=L[0],h=L[1],se=ze("down","sm"),me=Ze(B,g),E=me.chatRoom,j=k(E),de=j.avatar,ce=j.title;H({profileId:o,connections:[],onRemoval:ie});var v=Ye(z,E),S=v.data,pe=v.loadNext,fe=v.isLoadingNext,be=v.hasNext,P=v.refetch,R=De(function(){var i;return S==null||(i=S.participants)===null||i===void 0||(i=i.edges)===null||i===void 0?void 0:i.map(function(n){var p;return(n==null||(p=n.node)===null||p===void 0?void 0:p.profile)&&n.node.profile})},[S]),l=Xe({defaultValues:X(ce||"",de),resolver:qe(Y),mode:"onBlur"}),ve=l.control,_=l.setValue,w=l.watch,ye=l.getFieldState,ge=l.clearErrors,he=l.trigger,Se=l.handleSubmit,A=l.formState,Pe=A.isValid,Me=A.isDirty,Re=A.dirtyFields,_e=$(),F=O(_e,2),Ae=F[0],G=F[1],Ce=Se(function(i){if(u){var n=He({values:i,dirtyFields:Re}),p=i.image,N={};"image"in n&&(p?N.image=p:n.deleteImage=!0,delete n.image),delete n.participants,Ae({variables:{input:M({roomId:u,profileId:o},n),connections:[]},uploadables:N,onCompleted:function(C){var I,U=C==null||(I=C.chatRoomUpdate)===null||I===void 0?void 0:I.errors;U?(le("Something went wrong",{type:"error"}),Qe(l,U)):ne()}})}}),Ie=function(){ge(f.image),_(f.image,null,{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},Oe=!Pe||!Me,Le=Ue(),T=O(Le,2),V=T[0],xe=T[1],D=function(){h(!1),xe(function(){P?.({})})};return se&&x?a(J,{allProfilesRef:s,onClose:function(){return h(!1)},handleSubmitSuccess:D,profileId:o,roomId:u,isPending:V,existingMembers:R}):te(Ke,{children:[a(q,{open:x,allProfilesRef:s,onClose:function(){return h(!1)},handleSubmitSuccess:D,profileId:o,roomId:u,isPending:V,existingMembers:R}),te(K,{children:[a(re,{onClick:oe,"aria-label":"cancel editing group",children:a(Be,{sx:{fontSize:"24px"}})}),a(Je,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"Edit Group"}),a(re,{"aria-label":"Edit group",disabled:Oe,isLoading:G,onClick:function(){Ce()},children:a($e,{sx:{fontSize:"24px"}})})]}),a(Q,{control:ve,FORM_VALUE:f,handleRemoveImage:Ie,imageError:ye(f.image).error,isMutationInFlight:G,setValue:_,trigger:he,watch:w}),a(d,M({FORM_VALUE:f,setValue:_,watch:w,currentParticipants:R,refetch:P,membersLoadNext:pe,membersHasNext:be,membersIsLoadingNext:fe,MembersListProps:M({allowAddMember:!0,onAddMemberClick:function(){return h(!0)}},(t=c?.MembersListProps)!==null&&t!==void 0?t:{})},c))]})},rr=function(e){var t=ke(),o=t.currentProfile;return o!=null&&o.id?a(er,M({profileId:o.id},e)):null},Mr=rr;export{Mr as a};
//# sourceMappingURL=chunk-IZQOD55O.mjs.map