import{bL as F,$ as d,bT as k,a1 as e,bU as D,bV as q,bW as W,a3 as m,bX as M,bY as P,bZ as $,b_ as f,aZ as H,M as Y,b$ as Z}from"./App-B8XlOBJo.js";import{i as S,a as O}from"./sentry-common-rTXItwGA.js";import{d as v,br as I,c as V}from"./PrefsViewStore-Cx4TYLp6.js";import"./index-jPDAJ20a.js";import"./main-process-state-jW3BbbTQ.js";import"./index-CQwKdOGl.js";import"./index-D2Vj8hEx.js";import"./report-dialog-DVH6bOL-.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};r.SENTRY_RELEASE={id:"4.2.860"}}catch{}})();try{(function(){var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new r.Error().stack;o&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[o]="46ae21c3-86e7-4c39-97e1-b14edffc14a2",r._sentryDebugIdIdentifier="sentry-dbid-46ae21c3-86e7-4c39-97e1-b14edffc14a2")})()}catch{}const X="_container_q3zaw_1",J="_dropzone_q3zaw_12",K="_smallText_q3zaw_42",Q="_buttons_q3zaw_47",ee="_savingButton_q3zaw_57",te="_avatar_q3zaw_64",ae="_editAvatar_q3zaw_71",re="_loadingAvatar_q3zaw_71",n={container:X,dropzone:J,smallText:K,buttons:Q,savingButton:ee,avatar:te,editAvatar:ae,loadingAvatar:re},z=r=>{v.addToast({text:r,visibleWindowName:v.windowsStore.focusedWindowName},2e3,void 0,!0)},se=F(({accountID:r,groupThreadID:o,onClose:c})=>{const t=v.accountsStore.getAccount(r)?.currentInbox.getThread(o),[b,u]=d.useState(!1),[p,w]=d.useState(t?.title??t?.computedTitle??""),[g,y]=d.useState(t?.description??""),[l,h]=d.useState(t?.imgURL);d.useEffect(()=>{u(!1),w(t?.title||t?.computedTitle||""),y(t?.description||""),h(t?.imgURL)},[t]);const x=p!==t?.title,_=g!==t?.description,T=l!==t?.imgURL,j=x||_||T,E=async()=>{try{await Y(f,{recursive:!0,force:!0})}catch(a){logger.error("Failed to cleanup temp avatar directory",a)}},C=async()=>{await E(),c()},U=async()=>{if(!j)return;const a={};x&&(a.title=p),_&&(a.description=g),T&&(a.imgURL=l);try{u(!0),await t?.updateGroup(a),await E(),c()}catch(s){logger.error(s),z("Failed to update group")}finally{u(!1)}},B=async()=>{const{filePaths:a}=await V.showOpenDialog({properties:["openFile"],filters:[{name:"Images",extensions:["jpg","jpeg","png","gif","webp","bmp","tiff"]}]}),s=a[0];if(!s)return;const i=S.pathToFileURL(s).href;h(i)},A=async a=>{const s=a[0];if(s)try{await $(f,{recursive:!0});const i=O.join(f,s.name),L=await s.arrayBuffer();await H(i,new Uint8Array(L));const N=S.pathToFileURL(i).href;h(N)}catch(i){logger.error("Failed to save dropped avatar file",i),z("Failed to upload image")}},{getRootProps:R,isDragActive:G}=k({onDrop:A,accept:{"image/*":[]},disabled:!t?.canCurrentUserEditAvatar});return t?.isGroup?e.jsxs(D,{children:[e.jsxs("div",{...R(),className:n.container,onClick:I,children:[G&&e.jsx("div",{className:n.dropzone,children:"Drop image here to upload"}),e.jsxs("div",{className:n.avatar,onClick:t.canCurrentUserEditAvatar?B:void 0,children:[l?e.jsx(q,{isGroup:!0,src:l,size:64}):e.jsx(W,{size:64,thread:t}),t.canCurrentUserEditAvatar&&e.jsx("div",{className:n.editAvatar,children:"Edit"})]}),e.jsx("input",{value:p,onChange:a=>{w(a.currentTarget.value)},placeholder:"Group Title",disabled:!t.canCurrentUserEditTitle}),e.jsx("textarea",{value:g,onChange:a=>{y(a.currentTarget.value)},placeholder:"Group Description",disabled:!t.canCurrentUserEditDescription}),e.jsx("span",{className:n.smallText,children:"The group description is visible to members of this group and people invited to this group."}),e.jsxs("div",{className:n.buttons,children:[e.jsx(m,{size:"standard",variant:"muted",onClick:C,disabled:b,children:"Cancel"}),b?e.jsx(ne,{}):e.jsx(m,{size:"standard",variant:"primary",disabled:!j,onClick:U,children:"Save"})]})]}),e.jsx(M,{matchWindowName:!0})]}):e.jsx(D,{children:e.jsx("div",{className:n.container,onClick:I,children:"Group not found"})})}),ne=()=>e.jsx(m,{size:"standard",variant:"primary",disabled:!0,"data-sentry-element":"BrandButton","data-sentry-component":"SavingButton","data-sentry-source-file":"EditGroupModal.tsx",children:e.jsxs("div",{className:n.savingButton,children:["Saving ",e.jsx(P,{"data-sentry-element":"SpinnerIcon","data-sentry-source-file":"EditGroupModal.tsx"})]})});class fe extends Z{constructor(o,c){super(),this.accountID=o,this.groupThreadID=c}get id(){return`edit_group_${this.accountID}_${this.groupThreadID}`}get title(){return"Edit Group"}get windowFeatures(){return{width:313,height:419,resizable:!1,toolbar:!1,center:"parent"}}render(){return e.jsx(se,{accountID:this.accountID,groupThreadID:this.groupThreadID,onClose:()=>this.close(),"data-sentry-element":"EditGroupModal","data-sentry-component":"EditGroupBrowserWindow","data-sentry-source-file":"EditGroupBrowserWindow.tsx"})}onEscapePressed(){this.close()}}export{fe as EditGroupBrowserWindow};
//# sourceMappingURL=EditGroupBrowserWindow-BTtkXGjO.js.map
