import{a as Y}from"./chunk-7JB42AK2.mjs";import{a as Z}from"./chunk-KQ2WNRT4.mjs";import{a as c,b as rr,c as er}from"./chunk-DN6J5BDG.mjs";import{a as tr,b as or,c as ir}from"./chunk-LXXVQNZH.mjs";import{a as X}from"./chunk-AYAYQ6QO.mjs";import{b as Q}from"./chunk-ZCHJJU3B.mjs";import{b as J}from"./chunk-NQHWNGH7.mjs";import{a as $}from"./chunk-UB5P4QTT.mjs";import{useMemo as te,useTransition as oe}from"react";import{useCurrentProfile as ie}from"@baseapp-frontend/authentication";import{IconButton as lr}from"@baseapp-frontend/design-system/components/web/buttons";import{CheckMarkIcon as ne,CloseIcon as ae}from"@baseapp-frontend/design-system/components/web/icons";import{Searchbar as le}from"@baseapp-frontend/design-system/components/web/inputs";import{filterDirtyValues as ue,setFormRelayErrors as se,useNotification as de}from"@baseapp-frontend/utils";import{zodResolver as ce}from"@hookform/resolvers/zod";import{Box as P,Typography as R,useTheme as fe}from"@mui/material";import{useForm as ur}from"react-hook-form";import{ConnectionHandler as me}from"relay-runtime";import{jsx as a,jsxs as p,Fragment as ve}from"react/jsx-runtime";function x(r){"@babel/helpers - typeof";return x=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},x(r)}function nr(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);e&&(i=i.filter(function(f){return Object.getOwnPropertyDescriptor(r,f).enumerable})),t.push.apply(t,i)}return t}function L(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?nr(Object(t),!0).forEach(function(i){zr(r,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):nr(Object(t)).forEach(function(i){Object.defineProperty(r,i,Object.getOwnPropertyDescriptor(t,i))})}return r}function zr(r,e,t){return(e=Kr(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function Kr(r){var e=$r(r,"string");return x(e)=="symbol"?e:e+""}function $r(r,e){if(x(r)!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var i=t.call(r,e||"default");if(x(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Jr(r){return Yr(r)||Xr(r)||sr(r)||Qr()}function Qr(){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 Xr(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function Yr(r){if(Array.isArray(r))return V(r)}function ar(r,e){return ee(r)||re(r,e)||sr(r,e)||Zr()}function Zr(){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 sr(r,e){if(r){if(typeof r=="string")return V(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)?V(r,e):void 0}}function V(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,i=Array(e);t<e;t++)i[t]=r[t];return i}function re(r,e){var t=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(t!=null){var i,f,b,y,m=[],v=!0,g=!1;try{if(b=(t=t.call(r)).next,e===0){if(Object(t)!==t)return;v=!1}else for(;!(v=(i=b.call(t)).done)&&(m.push(i.value),m.length!==e);v=!0);}catch(I){g=!0,f=I}finally{try{if(!v&&t.return!=null&&(y=t.return(),Object(y)!==y))return}finally{if(g)throw f}}return m}}function ee(r){if(Array.isArray(r))return r}var he=function(e){var t=e.allProfilesRef,i=e.ProfileCard,f=i===void 0?Z:i,b=e.ProfileCardProps,y=b===void 0?{}:b,m=e.Searchbar,v=m===void 0?le:m,g=e.SearchbarProps,I=g===void 0?{}:g,D=e.ConnectionsList,dr=D===void 0?Y:D,F=e.ConnectionsListProps,cr=F===void 0?{}:F,fr=e.onValidSubmission,mr=e.onBackButtonClicked,A=fe(),vr=de(),hr=vr.sendToast,C=Q(t),_=C.data.allProfiles,pr=C.loadNext,br=C.isLoadingNext,yr=C.hasNext,E=C.refetch,gr=oe(),N=ar(gr,2),k=N[0],B=N[1],j=ur({defaultValues:{search:""}}),Cr=j.control,Sr=j.reset,Pr=j.watch,s=ur({defaultValues:rr,resolver:ce(er),mode:"onBlur"}),xr=s.control,O=s.setValue,U=s.watch,Ar=s.getFieldState,_r=s.clearErrors,Or=s.handleSubmit,w=s.formState,Ir=w.isValid,jr=w.isDirty,wr=w.dirtyFields,Tr=s.trigger,Mr=ie(),u=Mr.currentProfile,Lr=J(),G=ar(Lr,2),Rr=G[0],H=G[1],Vr=$(),Dr=Vr.setChatRoom,Fr=Or(function(o){var n=ue({values:o,dirtyFields:wr}),l=o.title,Wr=o.participants,T=o.image,qr=(Wr||[]).map(function(z){return z.id}),q={};c.image in n&&T&&typeof T!="string"&&(q.image=T),Rr({variables:{input:{title:l,isGroup:!0,profileId:u?.id,participants:qr},connections:[me.getConnectionID(u?.id,"roomsList_chatRooms",{unreadMessages:!1,archived:!1,q:""})]},uploadables:q,onCompleted:function(h){var M,K=h==null||(M=h.chatRoomCreate)===null||M===void 0?void 0:M.errors;if(K)hr("Something went wrong",{type:"error"}),se(s,K);else{var d;Dr({id:h==null||(d=h.chatRoomCreate)===null||d===void 0||(d=d.room)===null||d===void 0||(d=d.node)===null||d===void 0?void 0:d.id}),fr()}}})}),Er=function(n){var l=n.target.value||"";B(function(){E({q:l})})},Nr=function(){B(function(){Sr(),E({q:""})})},S=U(c.participants),kr=te(function(){return _?.edges.filter(function(o){return o?.node&&o?.node.id!==u?.id&&!S.some(function(n){var l;return n?.id===(o==null||(l=o.node)===null||l===void 0?void 0:l.id)})}).map(function(o){return o?.node})||[]},[_,S,u?.id]),Br=function(n){O(c.participants,[].concat(Jr(S),[n]),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},Ur=function(n){O(c.participants,S.filter(function(l){return l?.id!==n?.id}),{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},W=function(n){var l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;return n?a(f,L({profile:n,handleAddMember:Br,handleRemoveMember:Ur,isMember:l},y)):null},Gr=function(){_r(c.image),O(c.image,null,{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},Hr=!Ir||!jr||H;return p(ve,{children:[p(P,{children:[p(or,{children:[a(lr,{onClick:mr,"aria-label":"cancel group creation",children:a(ae,{sx:{fontSize:"24px"}})}),a(R,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"New Group"}),a(lr,{"aria-label":"Create group",disabled:Hr,onClick:function(){Fr()},children:a(ne,{sx:{fontSize:"24px"}})})]}),a(X,{control:xr,FORM_VALUE:c,handleRemoveImage:Gr,imageError:Ar(c.image).error,isMutationInFlight:H,setValue:O,trigger:Tr,watch:U})]}),p(ir,{children:[a(tr,{children:a(v,L({name:"search",onChange:Er,onClear:Nr,control:Cr,isPending:k},I))}),p(P,{height:"100%",width:"100%",children:[p(P,{role:"list","aria-label":"Selected group members",children:[a(R,{variant:"subtitle2",color:"text.primary",sx:{padding:A.spacing(2),borderBottom:"1px solid ".concat(A.palette.divider)},children:"Members"}),a(P,{maxHeight:250,overflow:"auto",sx:{scrollbarWidth:"none"},children:S.map(function(o){return W(o,!0)})})]}),a(P,{role:"list","aria-label":"Available contacts",sx:{padding:A.spacing(2),borderBottom:"1px solid ".concat(A.palette.divider)},children:a(R,{variant:"subtitle2",color:"text.primary",children:"Connections"})}),a(dr,L({profiles:kr,renderItem:W,loadNext:pr,hasNext:yr,isLoadingNext:br,isPending:k,searchValue:Pr("search")},cr))]})]})]})},Ve=he;export{Ve as a};
//# sourceMappingURL=chunk-UVDEBY6A.mjs.map