import{n as s,b as t,p as e,m as a,c as o}from"./p-2c9dd7c4.js";import{a as r}from"./p-7ad92407.js";import{w as i}from"./p-5347b880.js";import{B as n,f as c,u as d,U as l}from"./p-7062880e.js";import{S as m,a as f,Q as u}from"./p-f3effa5d.js";const h=new class{async getEditorProfiles(){return await n.instance.url("users/editors").get().json()}async assignRole(s,t){const e={command:{assignRole:t}};return n.instance.url(`users/${s}`).post(e).badRequest((()=>{throw new Error("Failed to execute user command")})).res()}};let w=class extends f{constructor(){super({editorProfiles:[],selectedEditor:s,editorLoading:!1,showRemoveEditorDialog:!1})}setEditorLoading(s){this.update((t=>{t.editorLoading=s}))}selectEditor(s){this.update((e=>{e.selectedEditor=t(s)}))}showRemoveEditorDialog(s){this.update((t=>{t.showRemoveEditorDialog=s}))}};w=function(s,t,e,a){var o,r=arguments.length,i=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,e):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(s,t,e,a);else for(var n=s.length-1;n>=0;n--)(o=s[n])&&(i=(r<3?o(i):r>3?o(t,e,i):o(t,e))||i);return r>3&&i&&Object.defineProperty(t,e,i),i}([m({name:"role-management",resettable:!0,producerFn:c})],w);const p=new w,E=new class extends u{constructor(s){super(s),this.store=s,this.editorProfiles$=this.select((s=>s.editorProfiles)),this.editorLoading$=this.select((s=>s.editorLoading)),this.showRemoveEditorDialog$=this.select((s=>s.showRemoveEditorDialog)),this.selectedEditor$=this.select((s=>s.selectedEditor))}}(p),g=new class{async getBasicProfileByEmail(s){const t=await d.getBasicProfileByEmail(s);return e(t,a((s=>s)))}async getEditorProfiles(){const s=(await h.getEditorProfiles()).map(l.toDomain);p.update((t=>{t.editorProfiles=s}))}async removeSelectedEditor(){p.showRemoveEditorDialog(!1),p.setEditorLoading(!0);const s=r(E.getValue().selectedEditor);await h.assignRole(s.basicProfile.profileId,"user"),await this.getEditorProfiles(),p.setEditorLoading(!1)}showRemoveEditorDialog(s){p.selectEditor(s),p.showRemoveEditorDialog(!0)}async addEditorByEmail(s){p.setEditorLoading(!0);const t=await i(this.getBasicProfileByEmail(s),300);return o(t)&&(await h.assignRole(t.value.profileId,"accountEditor"),await this.getEditorProfiles()),p.setEditorLoading(!1),t}};export{g as a,E as b,p as r}