import{p as a,c as E,o as l,b as P,w as m,z as e,k as w,f as t,P as S,U as T,e as c,h as b,A as B,V as C,g as f,F as A,s as L,j as O,N as U}from"./vue-CSzJdJby.js";import{V as N,D as F}from"./datatables.net-vue3-B28JL-vi.js";import{_ as H}from"./DeleteDialog-GXib_x-K.js";import{$ as M}from"./jquery-BALIvAru.js";import{_ as R}from"./Error-BXO_ADNF.js";import{_ as X}from"./ModalDialog-BxAzqKGJ.js";import"./highlight.js-CWp04Ajj.js";import"./bootstrap.esm-BOBBXxos.js";const z={class:"modal-body container pb-3"},J={class:"row gy-3"},W={class:"col-12"},q={class:"col-12 overflow-auto",style:{"max-height":"20rem"}},G={key:0,class:"col-12"},I={class:"text-center"},K={key:0,class:"fa fa-spinner fa-spin loader"},Q={key:1,class:"row text-secondary mx-auto p-4"},Y={class:"list-group","data-testid":"members"},Z={class:"list-group-item d-flex justify-content-between align-items-center"},ee=["onClick","disabled"],te={key:0,class:"fa fa-check text-success"},se={__name:"AddMemberDialog",props:["groupname"],emits:["added"],setup(p,{expose:g,emit:$}){const _=p,i=a(null);let h=null;function y(){h=`/json/groups/${_.groupname}/members`,i.value.show()}g({open:y});const x=$,v=a(null),o=a(!0),d=a([]);a([]);function j(){o.value=!0,M.ajax({url:"/json/users",success:r=>{d.value=r.map(n=>({name:n.name,active:n.active,member:n.groups.includes(_.groupname)}))},error:r=>{v.value.fromXHR(r)}}).always(()=>{o.value=!1})}const s=a(""),k=E(()=>{let r=s.value.toLowerCase();return d.value.filter(n=>r?n.name.toLowerCase().includes(r):!0)});function D(r){o.value=!0,M.ajax({url:h,method:"POST",contentType:"application/json",data:JSON.stringify({username:r}),success:n=>{i.value.hide(),x("added",n)},error:n=>{v.value.fromXHR(n)}}).always(()=>{o.value=!1})}function V(){s.value="",o.value=!0}return(r,n)=>(l(),P(X,{ref_key:"root",ref:i,id:"modalAddMember",title:"Add Member",onOpening:j,onClosed:V},{default:m(()=>[e("div",z,[w(R,{ref_key:"error",ref:v},null,512),t(),e("div",J,[e("div",W,[S(e("input",{class:"form-control",type:"search",placeholder:"Search username...","onUpdate:modelValue":n[0]||(n[0]=u=>s.value=u)},null,512),[[T,s.value]])]),t(),e("div",q,[o.value?(l(),c("div",G,[e("p",I,[t(`
              Waiting for server.
              `),o.value?(l(),c("i",K)):b("",!0)])])):b("",!0),t(),k.value.length==0?(l(),c("div",Q,"No member matches filter.")):b("",!0),t(),e("ul",Y,[(l(!0),c(A,null,B(k.value,u=>(l(),c("li",Z,[e("button",{class:"btn btn-link",type:"button",onClick:C(_e=>D(u.name),["prevent"]),disabled:o.value||!u.active||u.member},f(u.name),9,ee),t(),u.member?(l(),c("i",te)):b("",!0)]))),256))])])])])]),_:1},512))}},oe={class:"row"},ne={class:"col h5"},ae={key:0,class:"row"},re=e("div",{class:"col text-center"},[e("i",{class:"fa fa-spinner fa-spin loader"}),t(),e("span",null,"Loading...")],-1),le=[re],ce={class:"row"},ie=e("thead",null,[e("tr",null,[e("th",null,"Username"),t(),e("th",null,"Profile"),t(),e("th")])],-1),ue=["onClick"],de=e("i",{class:"fa fa-trash-o"},null,-1),me=[de],fe={class:"fs-5 text-center"},pe={__name:"MembersPage",props:["environment"],setup(p){N.use(F);const g=p,$=a(null),_=a(null),i=a(!0),h=a(""),y=a([]),x=[{width:"auto"},{width:"10rem",className:"text-secondary text-center",orderable:!1,searchable:!1},{width:"4rem",className:"text-center",orderable:!1,searchable:!1}],v={layout:{topStart:"search",topEnd:{buttons:[{className:"btn btn-sm btn-success",text:"Add Member",attr:{"data-testid":"add"},action:()=>{_.value.open()}}]}}};L(()=>{h.value=`${g.environment}/dba`,o()});function o(){i.value=!0,M.ajax({url:`/json/environments/${g.environment}/members`,success:function(d){y.value=d},error:window.showError}).always(()=>{i.value=!1})}return(d,j)=>(l(),c(A,null,[e("div",oe,[e("h5",ne,"Environment "+f(p.environment)+"'s Members",1)]),t(),i.value?(l(),c("div",ae,le)):b("",!0),t(),e("div",ce,[w(O(N),{class:"table table-striped table-bordered table-hover",data:y.value,columns:x,options:v},{"column-0":m(({rowData:s})=>[t(f(s.username),1)]),"column-1":m(({rowData:s})=>[t(f(s.profile),1)]),"column-2":m(({rowData:s})=>[e("button",{type:"button",class:"btn btn-outline-secondary btn-sm buttonDelete m-1",title:"Delete",onClick:C(k=>d.$refs.deleteModal.open(`/json/groups/${s.groupname}/members/${s.username}`),["prevent"])},me,8,ue)]),default:m(()=>[ie,t(),t(),t()]),_:1},8,["data"])]),t(),w(H,{ref_key:"deleteModal",ref:$,title:"Exclude user",noreload:!0,onDone:o},{default:m(({resource:s})=>[e("p",fe,[t(`
      Please confirm the exclusion of user `),e("strong",null,f(s.username),1),t(" from "+f(p.environment)+`.
    `,1)])]),_:1},512),t(),w(se,{ref_key:"addModal",ref:_,groupname:h.value,onAdded:o},null,8,["groupname"])],64))}};U({components:{memberspage:pe}}).mount("#members-app");
