import{C as f}from"./CrudView-DB2mMVy_.js";import{r as n,c as p,z as d,aP as b,a as g,ac as w,ae as y,D as v,p as I,e as _,u as a,af as s}from"./jwt-decode.esm-DyyavT6h.js";import{b as u}from"./router-BhKBgDIv.js";import{M}from"./member-C1t1_1eu.js";import"./tables-sMYALme4.js";import{F as z}from"./folder-5kS-NUoS.js";import{a as c}from"./ant-design-BcUCxDq-.js";import"./DocsButton.vue_vue_type_script_setup_true_lang-BZXWm6NO.js";import"./constants-BEk-t5le.js";import"./url-CaxRUwff.js";import"./PhDotsThreeVertical.vue-BXrShwWD.js";import"./index-DdqJ9EQR.js";import"./ts.worker-Do44s_XH.js";import"./record-Dva_8M1P.js";import"./string-C33uYcCb.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[e]="9d122816-a679-4701-ae54-abc548f2cada",r._sentryDebugIdIdentifier="sentry-dbid-9d122816-a679-4701-ae54-abc548f2cada")}catch{}})();class C{members=n([]);selectedMember=n(null);draftMember=n(null);table=p(()=>this.makeCrudViewTable());loading=n(!1);creationFields=n(null);authorEmail;organizationId;api;handlers;currentMember=n(null);constructor({authorEmail:e,organizationId:t,api:i,handlers:l}){this.authorEmail=e,this.organizationId=t,this.api=i,this.handlers=l}async fetchState(){this.loading.value=!0,await this.fetchMembers(),await this.fetchCreationFields(),this.setCurrentMember(),this.loading.value=!1}setCurrentMember(){this.currentMember.value=this.members.value.find(e=>e.email===this.authorEmail)??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(i=>({label:i.name,value:i.id}))}];this.creationFields.value=t}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()};async removeMember(e){if(u.getAuthor()?.claims.email===e.email){await c("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 c(`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:b,label:"Remove access",onClick:()=>this.removeMember(e),dangerous:!0}]}]}))}}}const J=g({__name:"EditorsView",setup(r){const e=w(),t=y(),i=e.params.organizationId,l=new M,h=new z,m=u.getAuthor()?.claims.email;if(!m)throw new Error("Author email is not available");const o=new C({organizationId:i,api:{member:l,folder:h},authorEmail:m,handlers:{onSelfRemove:()=>{t.push("organizations")}}});return v(async()=>{await o.fetchState()}),o.fetchState(),(k,x)=>(_(),I(f,{"entity-name":"editor",loading:a(o).loading.value,title:a(s).translate("i18n_editorsview_title"),description:a(s).translate("i18n_editorsview_description"),"empty-title":a(s).translate("i18n_editorsview_empty_title"),table:a(o).table.value,"create-button-text":a(s).translate("i18n_editorsview_invite_button"),fields:a(o).creationFields.value||void 0,create:a(o).confirmAddMember},null,8,["loading","title","description","empty-title","table","create-button-text","fields","create"]))}});export{J as default};
//# sourceMappingURL=EditorsView-Dsxul-h6.js.map
