import{a as D}from"./chunk-OVDSMD55.mjs";import{a as F}from"./chunk-AYAYQ6QO.mjs";import{a as m,b as V,c as x}from"./chunk-LRYH3V3G.mjs";import{a as w}from"./chunk-O5PFQIB5.mjs";import{b as C}from"./chunk-U2QNMZ5J.mjs";import{b as E}from"./chunk-DJRTLRX5.mjs";import{a as _}from"./chunk-QM7X6D7F.mjs";import{useCurrentProfile as ce}from"@baseapp-frontend/authentication";import{IconButton as M}from"@baseapp-frontend/design-system/components/web/buttons";import{CheckMarkIcon as de,CloseIcon as fe}from"@baseapp-frontend/design-system/components/web/icons";import{filterDirtyValues as pe,setFormRelayErrors as ye,useNotification as be}from"@baseapp-frontend/utils";import{zodResolver as ve}from"@hookform/resolvers/zod";import{Box as ge,Typography as he}from"@mui/material";import{useForm as Se}from"react-hook-form";import{usePreloadedQuery as Ie}from"react-relay";import{jsx as a,jsxs as U}from"react/jsx-runtime";function c(e){"@babel/helpers - typeof";return c=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},c(e)}function T(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,o)}return t}function L(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?T(Object(t),!0).forEach(function(o){oe(e,o,t[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):T(Object(t)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(t,o))})}return e}function oe(e,r,t){return(r=ie(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function ie(e){var r=ne(e,"string");return c(r)=="symbol"?r:r+""}function ne(e,r){if(c(e)!="object"||!e)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var o=t.call(e,r||"default");if(c(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function ae(e,r){return me(e)||se(e,r)||ue(e,r)||le()}function le(){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 ue(e,r){if(e){if(typeof e=="string")return G(e,r);var t={}.toString.call(e).slice(8,-1);return t==="Object"&&e.constructor&&(t=e.constructor.name),t==="Map"||t==="Set"?Array.from(e):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?G(e,r):void 0}}function G(e,r){(r==null||r>e.length)&&(r=e.length);for(var t=0,o=Array(r);t<r;t++)o[t]=e[t];return o}function se(e,r){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var o,n,d,u,s=[],l=!0,f=!1;try{if(d=(t=t.call(e)).next,r===0){if(Object(t)!==t)return;l=!1}else for(;!(l=(o=d.call(t)).done)&&(s.push(o.value),s.length!==r);l=!0);}catch(b){f=!0,n=b}finally{try{if(!l&&t.return!=null&&(u=t.return(),Object(u)!==u))return}finally{if(f)throw n}}return s}}function me(e){if(Array.isArray(e))return e}var Oe=function(r){var t=r.profileId,o=r.queryRef,n=r.roomId,d=r.onCancellation,u=r.onRemovalFromGroup,s=r.onValidSubmission,l=be(),f=l.sendToast,b=Ie(w,o),k=b.chatRoom,S=_(k),N=S.avatar,B=S.title;C({profileId:t,connections:[],onRemoval:u});var i=Se({defaultValues:V(B||"",N),resolver:ve(x),mode:"onBlur"}),z=i.control,I=i.setValue,Q=i.watch,W=i.getFieldState,$=i.clearErrors,q=i.trigger,H=i.handleSubmit,v=i.formState,K=v.isValid,J=v.isDirty,X=v.dirtyFields,Y=E(),O=ae(Y,2),Z=O[0],j=O[1],ee=H(function(p){if(n){var y=pe({values:p,dirtyFields:X}),R=p.image,A={};"image"in y&&(R?A.image=R:y.deleteImage=!0,delete y.image),Z({variables:{input:L({roomId:n,profileId:t},y),connections:[]},uploadables:A,onCompleted:function(g){var h,P=g==null||(h=g.chatRoomUpdate)===null||h===void 0?void 0:h.errors;P?(f("Something went wrong",{type:"error"}),ye(i,P)):s()}})}}),re=function(){$(m.image),I(m.image,null,{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},te=!K||!J;return U(ge,{children:[U(D,{children:[a(M,{onClick:d,"aria-label":"cancel editing group",children:a(fe,{sx:{fontSize:"24px"}})}),a(he,{component:"span",variant:"subtitle2",sx:{textAlign:"center"},children:"Edit Group"}),a(M,{"aria-label":"Edit group",disabled:te,isLoading:j,onClick:function(){ee()},children:a(de,{sx:{fontSize:"24px"}})})]}),a(F,{control:z,FORM_VALUE:m,handleRemoveImage:re,imageError:W(m.image).error,isMutationInFlight:j,setValue:I,trigger:q,watch:Q})]})},je=function(r){var t=ce(),o=t.currentProfile;return o!=null&&o.id?a(Oe,L({profileId:o.id},r)):null},Ue=je;export{Ue as a};
//# sourceMappingURL=chunk-Q5N4RKKF.mjs.map