import{n as I,b as L,g as v,d as j,c as r,o,w as e,a as l,e as O,m as y,t as s,f as u,q as V,l as m,N as U,i as B}from"./index-CTxlYqj4.js";import{d as h}from"./domains-HueJ9pRR.js";import{c as $,V as q,a as G,b as H}from"./VCard-DRptUN8Y.js";import{V as F}from"./VDataTableVirtual-B6iCEfal.js";import{V as A,d as C}from"./VAvatar-x_79C0tA.js";import{V as J}from"./VAutocomplete-CfnbXRi6.js";import{V as K,a as D}from"./VRow-B-csPNw7.js";const P={class:"headline"},Q={key:0,class:"headline"},W={key:1,class:"headline"},X={key:0},oe={__name:"DomainAdminList",props:{domain:{type:Object,default:()=>{}},dialogMode:{type:Boolean,default:!1}},emits:["close"],setup(c,{emit:M}){const x=I(),{$gettext:a}=L(),f=c,R=M,p=v([]),_=v([]),S=v([{title:a("Username"),value:"username"},{title:a("Name"),value:"name"},{title:"",value:"actions",align:"end",sortable:!1}]),k=v(!1),d=v(null);function w(){_.value.push({}),k.value=!0}function E(){k.value=!1,R("close")}function g(n){h.getDomainAdministrators(n.pk).then(t=>{_.value=t.data})}function N(){U.getAll({role:[B.RESELLER,B.DOMAIN_ADMIN],page_size:50}).then(n=>{p.value=n.data.results.filter(t=>_.value.find(i=>i.id===t.pk)===void 0)})}function T(){h.addDomainAdministrator(f.domain.pk,d.value.pk).then(()=>{g(f.domain),p.value=p.value.filter(n=>n.pk!==d.value.pk),d.value=null,k.value=!1,x.displayNotification({msg:a("Administrator added")})})}function z(n){h.removeDomainAdministrator(f.domain.pk,n.id).then(()=>{g(f.domain),N(),x.displayNotification({msg:a("Administrator removed")})})}return j(()=>{g(f.domain),N()}),(n,t)=>(o(),r(H,null,{default:e(()=>[l($,null,{default:e(()=>[O("span",P,[c.dialogMode?(o(),y("div",Q,s(u(a)("Administrators of"))+" "+s(c.domain.name),1)):(o(),y("div",W,s(u(a)("Administrators")),1))])]),_:1}),l(q,null,{default:e(()=>[l(F,{headers:S.value,items:_.value},{"item.username":e(({item:i})=>[i.id?(o(),y("span",X,s(i.username),1)):(o(),r(J,{key:1,modelValue:d.value,"onUpdate:modelValue":t[0]||(t[0]=b=>d.value=b),label:u(a)("Select an account"),items:p.value,variant:"outlined","item-title":"username",class:"mt-5","return-object":""},{append:e(()=>[d.value?(o(),r(A,{key:0,variant:"text",color:"primary",size:"x-large",onClick:T},{default:e(()=>[l(C,null,{default:e(()=>t[1]||(t[1]=[m("mdi-content-save")])),_:1,__:[1]})]),_:1})):V("",!0)]),_:1},8,["modelValue","label","items"]))]),"item.name":e(({item:i})=>[m(s(i.first_name)+" "+s(i.last_name),1)]),"item.actions":e(({item:i})=>[i.id?(o(),r(A,{key:0,variant:"text",color:"red",title:u(a)("Remove this administrator"),size:"x-large",onClick:b=>z(i)},{default:e(()=>[l(C,null,{default:e(()=>t[2]||(t[2]=[m("mdi-delete-outline")])),_:1,__:[2]})]),_:2},1032,["title","onClick"])):V("",!0)]),_:2},1032,["headers","items"])]),_:1}),l(G,null,{default:e(()=>[l(K,null,{default:e(()=>[l(D,{align:c.dialogMode?"left":"right"},{default:e(()=>[k.value?V("",!0):(o(),r(A,{key:0,color:"primary",variant:"outlined",onClick:w},{default:e(()=>[l(C,{small:""},{default:e(()=>t[3]||(t[3]=[m("mdi-plus")])),_:1,__:[3]}),m(" "+s(u(a)("Add administrator")),1)]),_:1}))]),_:1},8,["align"]),c.dialogMode?(o(),r(D,{key:0,align:"right"},{default:e(()=>[l(A,{color:"grey darken-1",variant:"text",onClick:E},{default:e(()=>[m(s(u(a)("Close")),1)]),_:1})]),_:1})):V("",!0)]),_:1})]),_:1})]),_:1}))}};export{oe as _};
