var f=Object.defineProperty;var p=(a,e,t)=>e in a?f(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var i=(a,e,t)=>(p(a,typeof e!="symbol"?e+"":e,t),t);import{C as g}from"./CrudView.2e1c5ca0.js";import{f as n,g as c,ep as b,d as w,e4 as y,e3 as I,c as v,u as l,o as M}from"./index.f8cd7fc7.js";import{a as h}from"./gateway.2a9fa462.js";import{M as z}from"./member.a6d1cba8.js";import"./columns.e632bef5.js";import{a as u}from"./ant-design.b5fe3672.js";import"./router.a76e8604.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.b64ebf34.js";import"./url.f92805c8.js";import"./PhDotsThreeVertical.vue.f6f771e3.js";import"./Badge.cf0f74ab.js";import"./index.a3fcd32d.js";import"./index.016130f1.js";import"./popupNotifcation.6f672802.js";import"./record.89b5c58a.js";import"./string.e821e86d.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]="394b8b16-134d-4472-898c-ed65e9588625",a._sentryDebugIdIdentifier="sentry-dbid-394b8b16-134d-4472-898c-ed65e9588625")}catch{}})();class C{constructor({authorEmail:e,organizationId:t,api:o,handlers:s}){i(this,"members",n([]));i(this,"selectedMember",n(null));i(this,"draftMember",n(null));i(this,"creationFields",c(()=>this.getCreationFields()));i(this,"table",c(()=>this.makeCrudViewTable()));i(this,"loading",n(!1));i(this,"authorEmail");i(this,"organizationId");i(this,"api");i(this,"handlers");i(this,"currentMember",n(null));i(this,"confirmAddMember",async e=>{await this.api.create({organizationId:this.organizationId,email:e.email.trim(),teams:e.teams}),await this.fetchState()});this.authorEmail=e,this.organizationId=t,this.api=o,this.handlers=s}async fetchState(){this.loading.value=!0,await this.fetchMembers(),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.list(this.organizationId)}async removeMember(e){var o;if(((o=h.getAuthor())==null?void 0:o.claims.email)===e.email){await u("Removing your own access will block you from this organization. Are you sure?",{okText:"Remove",cancelText:"Cancel"})&&(await this.api.delete({organizationId:this.organizationId,authorId:e.authorId}),this.handlers.onSelfRemove());return}await u(`Are you sure you want to remove ${e.email} access?`,{okText:"Remove",cancelText:"Cancel"})&&(await this.api.delete({organizationId:this.organizationId,authorId:e.authorId}),await this.fetchMembers())}getCreationFields(){return[{key:"email",label:"Email",type:"text"}]}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:b,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const J=w({__name:"EditorsView",setup(a){var d;const e=y(),t=I(),o=e.params.organizationId,s=new z,m=(d=h.getAuthor())==null?void 0:d.claims.email;if(!m)throw new Error("Author email is not available");const r=new C({organizationId:o,api:s,authorEmail:m,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return r.fetchState(),(k,E)=>(M(),v(g,{"entity-name":"editor",loading:l(r).loading.value,title:"Editors",description:"Manage people who can edit projects within your organization","empty-title":"No editors yet",table:l(r).table.value,"create-button-text":"Invite Editor",fields:l(r).creationFields.value,create:l(r).confirmAddMember},null,8,["loading","table","fields","create"]))}});export{J as default};
//# sourceMappingURL=EditorsView.c7c244f5.js.map
