import{a as B,b as H}from"./chunk-EVF5EHGL.mjs";import{a as G}from"./chunk-3SU3GQEU.mjs";import{a as N}from"./chunk-ZJGJJJ63.mjs";import{a as u,b as U,c as k}from"./chunk-Z54XQJNN.mjs";import{b as V}from"./chunk-GX4RCPNI.mjs";import{b as D}from"./chunk-SQFWWN4R.mjs";import{a as w}from"./chunk-UB5P4QTT.mjs";import{useMemo as Rt}from"react";import{useCurrentProfile as Et}from"@baseapp-frontend/authentication";import{IconButton as q}from"@baseapp-frontend/design-system/components/web/buttons";import{CheckMarkIcon as St,CloseIcon as Lt}from"@baseapp-frontend/design-system/components/web/icons";import{filterDirtyValues as It,setFormRelayErrors as Mt,useNotification as jt}from"@baseapp-frontend/utils";import{zodResolver as Ft}from"@hookform/resolvers/zod";import{Box as Tt,Typography as xt}from"@mui/material";import{useForm as wt}from"react-hook-form";import{ConnectionHandler as Dt}from"relay-runtime";import{jsx as s,jsxs as M,Fragment as Vt}from"react/jsx-runtime";function g(t){"@babel/helpers - typeof";return g=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(r){return typeof r}:function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},g(t)}function z(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);r&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),e.push.apply(e,o)}return e}function yt(t){for(var r=1;r<arguments.length;r++){var e=arguments[r]!=null?arguments[r]:{};r%2?z(Object(e),!0).forEach(function(o){bt(t,o,e[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):z(Object(e)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(e,o))})}return t}function bt(t,r,e){return(r=ht(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function ht(t){var r=gt(t,"string");return g(r)=="symbol"?r:r+""}function gt(t,r){if(g(t)!="object"||!t)return t;var e=t[Symbol.toPrimitive];if(e!==void 0){var o=e.call(t,r||"default");if(g(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(t)}function _t(t,r){return At(t)||Pt(t,r)||Ct(t,r)||Ot()}function Ot(){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 Ct(t,r){if(t){if(typeof t=="string")return K(t,r);var e={}.toString.call(t).slice(8,-1);return e==="Object"&&t.constructor&&(e=t.constructor.name),e==="Map"||e==="Set"?Array.from(t):e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?K(t,r):void 0}}function K(t,r){(r==null||r>t.length)&&(r=t.length);for(var e=0,o=Array(r);e<r;e++)o[e]=t[e];return o}function Pt(t,r){var e=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(e!=null){var o,c,m,p,v=[],d=!0,_=!1;try{if(m=(e=e.call(t)).next,r===0){if(Object(e)!==e)return;d=!1}else for(;!(d=(o=m.call(e)).done)&&(v.push(o.value),v.length!==r);d=!0);}catch(P){_=!0,c=P}finally{try{if(!d&&e.return!=null&&(p=e.return(),Object(p)!==p))return}finally{if(_)throw c}}return v}}function At(t){if(Array.isArray(t))return t}var Gt=function(r){var e=r.allProfilesRef,o=r.GroupChatMembersList,c=o===void 0?N:o,m=r.GroupChatMembersListProps,p=m===void 0?{}:m,v=r.onValidSubmission,d=r.onBackButtonClicked,_=jt(),P=_.sendToast,y=V(e),O=y.data.allProfiles,W=y.loadNext,J=y.isLoadingNext,Q=y.hasNext,X=y.refetch,a=wt({defaultValues:U,resolver:Ft(k),mode:"onBlur"}),Y=a.control,A=a.setValue,R=a.watch,Z=a.getFieldState,$=a.clearErrors,tt=a.handleSubmit,E=a.formState,rt=E.isValid,et=E.isDirty,ot=E.dirtyFields,it=a.trigger,nt=Et(),n=nt.currentProfile,at=D(),j=_t(at,2),lt=j[0],F=j[1],ut=w(),st=ut.setChatRoom,ct=tt(function(i){var b=It({values:i,dirtyFields:ot}),h=i.title,pt=i.participants,L=i.image,vt=(pt||[]).map(function(C){return C?.id}),T={};u.image in b&&L&&typeof L!="string"&&(T.image=L),lt({variables:{input:{title:h,isGroup:!0,profileId:n?.id,participants:vt},connections:[Dt.getConnectionID(n?.id,"roomsList_chatRooms",{unreadMessages:!1,archived:!1,q:""})]},uploadables:T,onCompleted:function(f){var I,x=f==null||(I=f.chatRoomCreate)===null||I===void 0?void 0:I.errors;if(x)P("Something went wrong",{type:"error"}),Mt(a,x);else{var l;st({id:f==null||(l=f.chatRoomCreate)===null||l===void 0||(l=l.room)===null||l===void 0||(l=l.node)===null||l===void 0?void 0:l.id}),v()}}})}),S=R(u.participants),dt=Rt(function(){return O?.edges.filter(function(i){return i?.node&&i?.node.id!==n?.id&&!S.some(function(b){var h;return b?.id===(i==null||(h=i.node)===null||h===void 0?void 0:h.id)})}).map(function(i){return i?.node})||[]},[O,S,n?.id]),ft=function(){$(u.image),A(u.image,null,{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},mt=!rt||!et||F;return M(Vt,{children:[M(Tt,{children:[M(B,{children:[s(q,{onClick:d,"aria-label":"cancel group creation",children:s(Lt,{sx:{fontSize:"24px"}})}),s(xt,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"New Group"}),s(q,{"aria-label":"Create group",disabled:mt,onClick:function(){ct()},children:s(St,{sx:{fontSize:"24px"}})})]}),s(G,{control:Y,FORM_VALUE:u,handleRemoveImage:ft,imageError:Z(u.image).error,isMutationInFlight:F,setValue:A,trigger:it,watch:R})]}),s(c,yt({FORM_VALUE:u,setValue:A,watch:R,currentParticipants:S,connections:dt,refetch:X,connectionsLoadNext:W,connectionsHasNext:Q,connectionsIsLoadingNext:J,ProfilesContainer:H},p))]})},rr=Gt;export{rr as a};
//# sourceMappingURL=chunk-SDMBQ3ZM.mjs.map