"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk4KEG43XPjs = require('./chunk-4KEG43XP.js');var _chunkGRYTR266js = require('./chunk-GRYTR266.js');var _chunkWPQ3YJU3js = require('./chunk-WPQ3YJU3.js');var _chunkIPFDVV5Wjs = require('./chunk-IPFDVV5W.js');var _chunkOB3KKIKAjs = require('./chunk-OB3KKIKA.js');var _chunkKOEBCSNMjs = require('./chunk-KOEBCSNM.js');var _chunkZPUIVRPUjs = require('./chunk-ZPUIVRPU.js');var _chunkGIHJUTMQjs = require('./chunk-GIHJUTMQ.js');var _chunkL4PBARWDjs = require('./chunk-L4PBARWD.js');var _react = require('react');var _buttons = require('@baseapp-frontend/design-system/components/web/buttons');var _icons = require('@baseapp-frontend/design-system/components/web/icons');var _images = require('@baseapp-frontend/design-system/components/web/images');var _utils = require('@baseapp-frontend/utils');var _zod = require('@hookform/resolvers/zod');var _material = require('@mui/material');var _reacthookform = require('react-hook-form');var _jsxruntime = require('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?_chunkKOEBCSNMjs.a:A,I=e.GroupChatMembersListProps,u=I===void 0?{}:I,R=e.existingMembers,q=R===void 0?[]:R,J=_utils.useNotification.call(void 0, ),Q=J.sendToast,v=_chunkGIHJUTMQjs.b.call(void 0, m),g=v.data.allProfiles,X=v.loadNext,Y=v.isLoadingNext,Z=v.hasNext,tt=v.refetch,d=_reacthookform.useForm.call(void 0, {defaultValues:_chunkZPUIVRPUjs.b,resolver:_zod.zodResolver.call(void 0, _chunk4KEG43XPjs.a),mode:"onBlur"}),x=d.setValue,j=d.watch,et=d.getFieldState,rt=d.handleSubmit,ot=d.formState.isDirty,it=d.reset,nt=_chunkL4PBARWDjs.b.call(void 0, ),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 _optionalChain([_, 'optionalAccess', _2 => _2.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"}),_utils.setFormRelayErrors.call(void 0, d,w)):(f(),it())}})}}),y=j(_chunkZPUIVRPUjs.a.participants),ut=_react.useMemo.call(void 0, function(){return _optionalChain([g, 'optionalAccess', _3 => _3.edges, 'access', _4 => _4.filter, 'call', _5 => _5(function(i){return _optionalChain([i, 'optionalAccess', _6 => _6.node])&&_optionalChain([i, 'optionalAccess', _7 => _7.node, 'access', _8 => _8.id])!==l}), 'access', _9 => _9.map, 'call', _10 => _10(function(i){return _optionalChain([i, 'optionalAccess', _11 => _11.node])})])||[]},[g,l]),dt=!ot||et(_chunkZPUIVRPUjs.a.participants).invalid,ct=function(n){x(_chunkZPUIVRPUjs.a.participants,[].concat(vt(y),[n]),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},mt=function(n){x(_chunkZPUIVRPUjs.a.participants,y.filter(function(a){return _optionalChain([a, 'optionalAccess', _12 => _12.id])!==_optionalChain([n, 'optionalAccess', _13 => _13.id])}),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},P=y.length===0;return _jsxruntime.jsxs.call(void 0, _material.Box,{children:[_jsxruntime.jsxs.call(void 0, _chunkOB3KKIKAjs.a,{children:[_jsxruntime.jsx.call(void 0, _buttons.IconButton,{onClick:M,"aria-label":"cancel adding member",children:_jsxruntime.jsx.call(void 0, _images.Iconify,{icon:"eva:arrow-ios-back-fill",width:24})}),_jsxruntime.jsx.call(void 0, _material.Typography,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"Add Member"}),_jsxruntime.jsx.call(void 0, _buttons.IconButton,{"aria-label":"Add Member",disabled:dt||b,isLoading:lt||b,onClick:function(){st()},children:_jsxruntime.jsx.call(void 0, _icons.CheckMarkIcon,{sx:{fontSize:"24px"}})})]}),_jsxruntime.jsx.call(void 0, K,O({FORM_VALUE:_chunkZPUIVRPUjs.a,setValue:x,watch:j,currentParticipants:y,connections:ut,refetch:tt,SearchbarContainer:_chunkGRYTR266js.a,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?_jsxruntime.jsx.call(void 0, _chunkIPFDVV5Wjs.a,{profile:n,handleAddMember:ct,handleRemoveMember:mt,isBeingAdded:y.some(function(a){return _optionalChain([a, 'optionalAccess', _14 => _14.id])===_optionalChain([n, 'optionalAccess', _15 => _15.id])}),isExistingMember:q.some(function(a){return _optionalChain([a, 'optionalAccess', _16 => _16.id])===_optionalChain([n, 'optionalAccess', _17 => _17.id])})}):null}},(r=_optionalChain([u, 'optionalAccess', _18 => _18.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=_optionalChain([u, 'optionalAccess', _19 => _19.MembersListProps]))!==null&&o!==void 0?o:{}),ProfileCard:_chunkWPQ3YJU3js.a},u))]})},Yt= exports.a =wt;exports.a = Yt;
//# sourceMappingURL=chunk-QQRZR2QV.js.map