var b=Object.defineProperty;var g=(a,e,t)=>e in a?b(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var i=(a,e,t)=>(g(a,typeof e!="symbol"?e+"":e,t),t);import{C as w}from"./CrudView.ca91f805.js";import{r as s,c as y,Z as m,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 d}from"./jwt-decode.esm.32f71954.js";import{l as h}from"./router.29e08ea4.js";import{M as x}from"./member.91dd2bc0.js";import"./tables.94d324c3.js";import{F as A}from"./folder.bd31d9bc.js";import{a as f}from"./ant-design.a8b36151.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.c50f6a0a.js";import"./constants.b5d83622.js";import"./url.79cc02c3.js";import"./PhDotsThreeVertical.vue.e305b3a2.js";import"./index.c59ca45b.js";import"./index.2400150a.js";import"./record.41c9caee.js";import"./string.ff0b4ef9.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[e]="6517d48b-bc94-4195-9f3a-14987c49f84f",a._sentryDebugIdIdentifier="sentry-dbid-6517d48b-bc94-4195-9f3a-14987c49f84f")}catch{}})();class E{constructor({authorEmail:e,organizationId:t,api:r,handlers:l}){i(this,"members",s([]));i(this,"selectedMember",s(null));i(this,"draftMember",s(null));i(this,"table",y(()=>this.makeCrudViewTable()));i(this,"loading",s(!1));i(this,"creationFields",s(null));i(this,"authorEmail");i(this,"organizationId");i(this,"api");i(this,"handlers");i(this,"currentMember",s(null));i(this,"confirmAddMember",async e=>{const t=m.object({email:m.string().email(),folders:m.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(a){var u;const e=_(),t=M(),r=e.params.organizationId,l=new x,p=new A,c=(u=h.getAuthor())==null?void 0:u.claims.email;if(!c)throw new Error("Author email is not available");const n=new E({organizationId:r,api:{member:l,folder:p},authorEmail:c,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(d).translate("i18n_editorsview_title"),description:o(d).translate("i18n_editorsview_description"),"empty-title":o(d).translate("i18n_editorsview_empty_title"),table:o(n).table.value,"create-button-text":o(d).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.3f4d1241.js.map
