import{bL as z,$ as d,bT as F,a1 as e,bU as G,bV as k,bW as W,a3 as f,bX as P,bY as $,bZ as H,b_ as h,aZ as Y,M as Z,b$ as O}from"./App-CSvRzCsn.js";import{i as D,a as V}from"./sentry-common-2nFGZClv.js";import{d as v,bp as S,c as X}from"./PrefsViewStore-B9QxYjkz.js";import"./index-jPDAJ20a.js";import"./main-process-state-jW3BbbTQ.js";import"./index-CZYymlJf.js";import"./index-F0fMEJXd.js";import"./report-dialog-DCdDPy0Y.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:{},n=new r.Error().stack;n&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[n]="f527689e-a07a-4a29-a50d-f9beec747386",r._sentryDebugIdIdentifier="sentry-dbid-f527689e-a07a-4a29-a50d-f9beec747386")})()}catch{}const q="EditGroupModal-module__container",J="EditGroupModal-module__dropzone",K="EditGroupModal-module__smallText",Q="EditGroupModal-module__buttons",ee="EditGroupModal-module__savingButton",te="EditGroupModal-module__avatar",ae="EditGroupModal-module__editAvatar",re="EditGroupModal-module__loadingAvatar",s={container:q,dropzone:J,smallText:K,buttons:Q,savingButton:ee,avatar:te,editAvatar:ae,loadingAvatar:re},I=r=>{v.addToast({text:r,visibleWindowName:v.windowsStore.focusedWindowName},2e3,void 0,!0)},oe=z(({accountID:r,groupThreadID:n,onClose:c})=>{const t=v.accountsStore.getAccount(r)?.currentInbox.getThread(n),[b,u]=d.useState(!1),[p,y]=d.useState(t?.title??t?.computedTitle??""),[g,w]=d.useState(t?.description??""),[l,m]=d.useState(t?.imgURL);d.useEffect(()=>{u(!1),y(t?.title||t?.computedTitle||""),w(t?.description||""),m(t?.imgURL)},[t]);const x=p!==t?.title,E=g!==t?.description,T=l!==t?.imgURL,j=x||E||T,_=async()=>{try{await Z(h,{recursive:!0,force:!0})}catch(a){logger.error("Failed to cleanup temp avatar directory",a)}},C=async()=>{await _(),c()},U=async()=>{if(!j)return;const a={};x&&(a.title=p),E&&(a.description=g),T&&(a.imgURL=l);try{u(!0),await t?.updateGroup(a),await _(),c()}catch(o){logger.error(o),I("Failed to update group")}finally{u(!1)}},B=async()=>{const{filePaths:a}=await X.showOpenDialog({properties:["openFile"],filters:[{name:"Images",extensions:["jpg","jpeg","png","gif","webp","bmp","tiff"]}]}),o=a[0];if(!o)return;const i=D.pathToFileURL(o).href;m(i)},A=async a=>{const o=a[0];if(o)try{await H(h,{recursive:!0});const i=V.join(h,o.name),L=await o.arrayBuffer();await Y(i,new Uint8Array(L));const N=D.pathToFileURL(i).href;m(N)}catch(i){logger.error("Failed to save dropped avatar file",i),I("Failed to upload image")}},{getRootProps:R,isDragActive:M}=F({onDrop:A,accept:{"image/*":[]},disabled:!t?.canCurrentUserEditAvatar});return t?.isGroup?e.jsxs(G,{children:[e.jsxs("div",{...R(),className:s.container,onClick:S,children:[M&&e.jsx("div",{className:s.dropzone,children:"Drop image here to upload"}),e.jsxs("div",{className:s.avatar,onClick:t.canCurrentUserEditAvatar?B:void 0,children:[l?e.jsx(k,{isGroup:!0,src:l,size:64}):e.jsx(W,{size:64,thread:t}),t.canCurrentUserEditAvatar&&e.jsx("div",{className:s.editAvatar,children:"Edit"})]}),e.jsx("input",{value:p,onChange:a=>{y(a.currentTarget.value)},placeholder:"Group Title",disabled:!t.canCurrentUserEditTitle}),e.jsx("textarea",{value:g,onChange:a=>{w(a.currentTarget.value)},placeholder:"Group Description",disabled:!t.canCurrentUserEditDescription}),e.jsx("span",{className:s.smallText,children:"The group description is visible to members of this group and people invited to this group."}),e.jsxs("div",{className:s.buttons,children:[e.jsx(f,{size:"standard",variant:"muted",onClick:C,disabled:b,children:"Cancel"}),b?e.jsx(se,{}):e.jsx(f,{size:"standard",variant:"primary",disabled:!j,onClick:U,children:"Save"})]})]}),e.jsx(P,{matchWindowName:!0})]}):e.jsx(G,{children:e.jsx("div",{className:s.container,onClick:S,children:"Group not found"})})}),se=()=>e.jsx(f,{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:s.savingButton,children:["Saving ",e.jsx($,{"data-sentry-element":"SpinnerIcon","data-sentry-source-file":"EditGroupModal.tsx"})]})});class he extends O{constructor(n,c){super(),this.accountID=n,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(oe,{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{he as EditGroupBrowserWindow};
//# sourceMappingURL=EditGroupBrowserWindow-BdheI3C4.js.map
