var b=Object.defineProperty;var g=(i,e,t)=>e in i?b(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>(g(i,typeof e!="symbol"?e+"":e,t),t);import{C as w}from"./CrudView.f8f7347d.js";import{r as s,c as y,Z as d,er as v,d as I,ei as _,ec as M,U as z,a as C,u as o,o as k,i as c}from"./jwt-decode.esm.b9bb33e7.js";import{l as h}from"./router.135b49e3.js";import{M as x}from"./member.a66ab498.js";import"./tables.d6f8baad.js";import{F as A}from"./folder.c07afb46.js";import{a as f}from"./ant-design.5ec0b6b3.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.264a92d9.js";import"./constants.0deee127.js";import"./url.7fa35693.js";import"./PhDotsThreeVertical.vue.e9b1faec.js";import"./index.b57ea477.js";import"./index.cb46e99b.js";import"./record.c01e7f08.js";import"./string.04644599.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[e]="52f57eb9-dfcf-4604-a3f7-9f299ac952ac",i._sentryDebugIdIdentifier="sentry-dbid-52f57eb9-dfcf-4604-a3f7-9f299ac952ac")}catch{}})();class E{constructor({authorEmail:e,organizationId:t,api:r,handlers:l}){a(this,"members",s([]));a(this,"selectedMember",s(null));a(this,"draftMember",s(null));a(this,"table",y(()=>this.makeCrudViewTable()));a(this,"loading",s(!1));a(this,"creationFields",s(null));a(this,"authorEmail");a(this,"organizationId");a(this,"api");a(this,"handlers");a(this,"currentMember",s(null));a(this,"confirmAddMember",async e=>{const t=d.object({email:d.string().email(),folders:d.string().array().optional()}).parse(e);await this.api.member.create({organizationId:this.organizationId,email:t.email.trim(),folderIds:t.folders}),await this.fetchState()});this.authorEmail=e,this.organizationId=t,this.api=r,this.handlers=l}async fetchState(){this.loading.value=!0,await this.fetchMembers(),await this.fetchCreationFields(),this.setCurrentMember(),this.loading.value=!1}setCurrentMember(){var e;this.currentMember.value=(e=this.members.value.find(t=>t.email===this.authorEmail))!=null?e:null}async fetchMembers(){this.members.value=await this.api.member.list(this.organizationId)}async fetchCreationFields(){const e=await this.api.folder.list(this.organizationId),t=[{key:"email",label:"Email",type:"text",placeholder:"Enter email"},{key:"folders",label:"Folders",type:"select",mode:"multiple",tooltip:"Select folders this member can access",placeholder:"Search and select folders...",options:e.map(r=>({label:r.name,value:r.id}))}];this.creationFields.value=t}async removeMember(e){var r;if(((r=h.getAuthor())==null?void 0:r.claims.email)===e.email){await f("Removing your own access will block you from this organization. Are you sure?",{okText:"Remove",cancelText:"Cancel"})&&(await this.api.member.delete({organizationId:this.organizationId,authorId:e.authorId}),this.handlers.onSelfRemove());return}await f(`Are you sure you want to remove ${e.email} access?`,{okText:"Remove",cancelText:"Cancel"})&&(await this.api.member.delete({organizationId:this.organizationId,authorId:e.authorId}),await this.fetchMembers())}makeCrudViewTable(){return{columns:[{title:"Email",align:"center"},{title:"",align:"right"}],rows:this.members.value.map(e=>({key:e.email,cells:[{type:"text",text:e.email},{type:"actions",actions:[{icon:v,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const N=I({__name:"EditorsView",setup(i){var u;const e=_(),t=M(),r=e.params.organizationId,l=new x,p=new A,m=(u=h.getAuthor())==null?void 0:u.claims.email;if(!m)throw new Error("Author email is not available");const n=new E({organizationId:r,api:{member:l,folder:p},authorEmail:m,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return z(async()=>{await n.fetchState()}),n.fetchState(),(F,R)=>(k(),C(w,{"entity-name":"editor",loading:o(n).loading.value,title:o(c).translate("i18n_editorsview_title"),description:o(c).translate("i18n_editorsview_description"),"empty-title":o(c).translate("i18n_editorsview_empty_title"),table:o(n).table.value,"create-button-text":o(c).translate("i18n_editorsview_invite_button"),fields:o(n).creationFields.value||void 0,create:o(n).confirmAddMember},null,8,["loading","title","description","empty-title","table","create-button-text","fields","create"]))}});export{N as default};
//# sourceMappingURL=EditorsView.580cabb0.js.map
