import{a as W}from"./chunk-TJ675KEK.mjs";import{a as B}from"./chunk-WSOAFMXJ.mjs";import{a as $}from"./chunk-PJUFVCZA.mjs";import{a as H}from"./chunk-L3KHO22A.mjs";import{a as G}from"./chunk-ZJGJJJ63.mjs";import{a as f,b as k}from"./chunk-Z54XQJNN.mjs";import{b as V}from"./chunk-GX4RCPNI.mjs";import{b as N}from"./chunk-QT7GKZLD.mjs";import{useMemo as xe,useRef as Ee}from"react";import{ConfirmDialog as we}from"@baseapp-frontend/design-system/components/web/dialogs";import{setFormRelayErrors as Ie,useNotification as je}from"@baseapp-frontend/utils";import{zodResolver as De}from"@hookform/resolvers/zod";import{LoadingButton as Te}from"@mui/lab";import{useForm as Ue}from"react-hook-form";import{jsx as C}from"react/jsx-runtime";function L(e){"@babel/helpers - typeof";return L=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},L(e)}function X(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(d){return Object.getOwnPropertyDescriptor(e,d).enumerable})),r.push.apply(r,o)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?X(Object(r),!0).forEach(function(o){he(e,o,r[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):X(Object(r)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))})}return e}function he(e,t,r){return(t=Me(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Me(e){var t=ge(e,"string");return L(t)=="symbol"?t:t+""}function ge(e,t){if(L(e)!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var o=r.call(e,t||"default");if(L(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Le(e){return Ce(e)||Ae(e)||K(e)||Pe()}function Pe(){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 Ae(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Ce(e){if(Array.isArray(e))return w(e)}function _e(e,t){return Re(e)||Oe(e,t)||K(e,t)||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 K(e,t){if(e){if(typeof e=="string")return w(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)?w(e,t):void 0}}function w(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 Oe(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var o,d,P,p,v=[],l=!0,b=!1;try{if(P=(r=r.call(e)).next,t===0){if(Object(r)!==r)return;l=!1}else for(;!(l=(o=P.call(r)).done)&&(v.push(o.value),v.length!==t);l=!0);}catch(_){b=!0,d=_}finally{try{if(!l&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(b)throw d}}return v}}function Re(e){if(Array.isArray(e))return e}var Fe=function(t){var r,o,d=t.allProfilesRef,P=t.onClose,p=t.handleSubmitSuccess,v=t.open,l=t.profileId,b=t.roomId,_=t.isPending,I=t.GroupChatMembersList,z=I===void 0?G:I,j=t.GroupChatMembersListProps,s=j===void 0?{}:j,q=t.existingMembers,J=je(),Q=J.sendToast,S=Ee(null),y=V(d),A=y.data.allProfiles,Y=y.loadNext,Z=y.isLoadingNext,ee=y.hasNext,te=y.refetch,u=Ue({defaultValues:k,resolver:De(H),mode:"onBlur"}),O=u.setValue,D=u.watch,re=u.getFieldState,oe=u.handleSubmit,ne=u.formState.isDirty,T=u.reset,ie=N(),U=_e(ie,2),ae=U[0],F=U[1],le=oe(function(i){if(b){var a=i.participants,n=(a||[]).map(function(c){return c?.id});ae({variables:{input:{roomId:b,profileId:l,addParticipants:n},connections:[]},onCompleted:function(M){var m,g=M==null||(m=M.chatRoomUpdate)===null||m===void 0?void 0:m.errors;g?(Q("Something went wrong",{type:"error"}),Ie(u,g)):(p(),T())}})}}),h=D(f.participants),se=xe(function(){return A?.edges.filter(function(i){return i?.node&&i?.node.id!==l}).map(function(i){return i?.node})||[]},[A,l]),ue=!ne||re(f.participants).invalid,de=function(a){O(f.participants,[].concat(Le(h),[a]),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},ce=function(a){O(f.participants,h.filter(function(n){return n?.id!==a?.id}),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},me=function(){P(),T()},fe=function(a){var n=S.current;if(n){n.style.cursor="grabbing",n.style.userSelect="none";var c=a.pageX-n.offsetLeft,M=n.scrollLeft,m=function(ve){var x,be=ve.pageX-n.offsetLeft,ye=be-c;(x=S.current)===null||x===void 0||x.scrollTo({left:M-ye,behavior:"auto"})},g=function(){n.style.cursor="grab",n.style.removeProperty("user-select"),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",g)}},R=h.length===0;return C(we,{title:"Add Members",customMaxWidth:480,DialogContentProps:{sx:{padding:0,typography:"body1",color:"text.primary"}},content:C(z,E({FORM_VALUE:f,setValue:O,watch:D,currentParticipants:h,connections:se,refetch:te,SearchbarContainer:W,connectionsLoadNext:Y,connectionsHasNext:ee,connectionsIsLoadingNext:Z,ConnectionsListProps:E({VirtuosoProps:{style:{height:"100vh",maxHeight:"500px"}},title:"",removeTitle:R,renderItem:function(a){return a?C($,{profile:a,handleAddMember:de,handleRemoveMember:ce,isBeingAdded:h.some(function(n){return n?.id===a?.id}),isExistingMember:q.some(function(n){return n?.id===a?.id})}):null}},(r=s?.ConnectionsListProps)!==null&&r!==void 0?r:{}),MembersListProps:E({removeTitle:R,title:"",NormalListProps:{sx:{display:"flex",justifyContent:"start",alignItems:"center",padding:R?0:"12px",scrollbarWidth:"none"},ref:S,onMouseDown:fe}},(o=s?.MembersListProps)!==null&&o!==void 0?o:{}),ProfileCard:B},s)),action:C(Te,{onClick:function(){return le()},disabled:F||ue,loading:F||_,children:"Confirm"}),onClose:me,open:v})},Ze=Fe;export{Ze as a};
//# sourceMappingURL=chunk-ABQQTONH.mjs.map