import{_ as j,j as G,n as B,r as M,a0 as U,i as I,u as T,l as S,w as z,T as L,M as H,a7 as A,o as d,b as u,e as a,a as s,k as f,c as E,f as y,F as N,d as q,t as g,q as V,v as D,m as F,h as p}from"./index.65dec0ff.js";import{a as K,r as W}from"./PlusIcon.06bbd797.js";import{r as O}from"./TrashIcon.24530cad.js";import{r as J}from"./UserIcon.e04fd5af.js";const Q={setup(P,{emit:r}){const h=G(B),e=M(0),i=G(U),w=M([...i.value]);let v=i.value.map(o=>o.group);i.value.map(o=>o.gid);const n=I({showModal:!1,group:"",feedback:{},valid:!1,validateInputs:()=>{var c,_;let o=!0;if(n.feedback.group="",!n.group)n.feedback.group="Group name required.",o=!1;else if(/^[a-z_][a-z0-9_-]*[\$a-z0-9_-]?$/.test(n.group))v.includes(n.group)&&(n.feedback.group="Group already exists.",o=!1);else{const b=[...(c=n.group.match(/^[^a-z_]|[^a-z0-9_-](?=.+)|[^\$a-z0-9_-]$/g))!=null?c:[]];n.feedback.group=`Invalid character${b.length>1?"s":""}: `+b.filter((t,C,k)=>k.indexOf(t)===C).map(t=>`'${t}'`).join(", "),o=!1}n.group.length>32&&(n.feedback.group=((_=n.feedback.group)!=null?_:"")+` Group name too long.`,o=!1),n.valid=o},applyCallback:async()=>{e.value++;try{await T(["groupadd",n.group],{superuser:"try"}).promise(),h.value.constructNotification("Created group",`Successfully created group ${n.group}`,"success"),r("refreshGroups")}catch(o){h.value.constructNotification("Failed to create group",S(o),"error")}finally{n.showModal=!1,setTimeout(()=>{n.group="",n.validateInputs()},300),e.value--}},cancelCallback:()=>{n.showModal=!1}});n.validateInputs();const l=I({showModal:!1,group:null,applyText:"Confirm",confirmationCheck:()=>`delete-${l.group.group}`,confirmationInput:"",confirmed:!1,ask:o=>{l.confirmed=!1,l.group=o,l.confirmationInput="",l.showModal=!0},checkConfirmation:()=>{l.confirmed=l.confirmationCheck()===l.confirmationInput},applyCallback:async()=>{if(l.confirmed){e.value++;try{await T(["groupdel",l.group.group],{superuser:"try"}).promise(),h.value.constructNotification("Deleted group",`Successfully deleted group ${l.group.group}`,"success"),r("refreshGroups")}catch(o){h.value.constructNotification("Failed to delete group",S(o),"error")}finally{l.reset(),e.value--}}l.reset()},cancelCallback:()=>{l.reset()},reset:()=>{l.showModal=!1,setTimeout(()=>{l.confirmationInput="",l.group=null},300)}}),m=I({callback:()=>0,group:(o,c)=>o.group.localeCompare(c.group),gid:(o,c)=>o.gid-c.gid}),x=o=>o.gid>=1e3&&o.gid!==65534&&!o.isPrimary;return z(i,()=>{w.value=[...i.value].sort(m.callback),i.value.map(o=>o.gid),v=i.value.map(o=>o.group)},{immediate:!0}),z(()=>m.callback,()=>{w.value.sort(m.callback)}),{processing:e,groups:i,groupsSorted:w,newGroup:n,deleteConfirmation:l,sorter:m,checkIfCanDelete:x}},components:{Table:L,PlusIcon:K,ModalPopup:H,SortCallbackButton:A,TrashIcon:O,ExclamationCircleIcon:W,UserIcon:J},emits:["refreshGroups"]},R={class:"centered-column p-well h-full overflow-hidden"},X={class:"card h-full overflow-hidden"},Y={class:"flex flex-row gap-2 items-center"},Z=a("span",null,"Groups",-1),$=a("div",{class:"grow"},null,-1),ee={class:"w-20"},oe={class:"flex flex-row flex-nowrap gap-x-2"},te=a("div",{class:"grow"},"Name",-1),ae={class:"w-20 text-right mr-20 overflow-x-visible !pr-7"},ne=a("span",null,"Group ID",-1),le=a("th",null,"Members",-1),re=a("th",null,[a("div",{class:"!sr-only"},"Delete Group")],-1),se=["index"],ie={class:"flex flex-row gap-x-2 items-center"},ce={class:"grow"},de=["title"],ue={class:"text-right !pr-7"},pe={key:0},me={key:1,class:"text-muted"},fe={class:"w-20 text-right"},ge=["disabled","title","onClick"],he=a("label",{class:"text-label block"},"Group Name",-1),_e={key:0,class:"feedback-group"},be=["innerHTML"],Ce={key:0,class:"whitespace-normal mb-3"},ke={class:"whitespace-normal mb-3"},we=F(" This cannot be undone. Type "),ve={class:"font-mono text-sm bg-accent p-1"},ye=F(" below to confirm. ");function xe(P,r,h,e,i,w){var b;const v=p("LoadingSpinner"),n=p("PlusIcon"),l=p("SortCallbackButton"),m=p("UserIcon"),x=p("TrashIcon"),o=p("Table"),c=p("ExclamationCircleIcon"),_=p("ModalPopup");return d(),u(N,null,[a("div",R,[a("div",X,[s(o,{stickyHeaders:"",noShrink:"",noShrinkHeight:"h-full",class:"!border-0"},{header:f(()=>[a("div",Y,[Z,e.processing?(d(),E(v,{key:0,class:"size-icon"})):y("",!0),$,a("button",{onClick:r[0]||(r[0]=t=>e.newGroup.showModal=!0),title:"Create new group"},[s(n,{class:"size-icon icon-default"})])])]),thead:f(()=>[a("tr",null,[a("th",ee,[a("div",oe,[te,s(l,{modelValue:e.sorter.callback,"onUpdate:modelValue":r[1]||(r[1]=t=>e.sorter.callback=t),compareFunc:e.sorter.group,initialFuncIsMine:""},null,8,["modelValue","compareFunc"])])]),a("th",ae,[ne,s(l,{modelValue:e.sorter.callback,"onUpdate:modelValue":r[2]||(r[2]=t=>e.sorter.callback=t),compareFunc:e.sorter.gid,class:"absolute right-0 z-20"},null,8,["modelValue","compareFunc"])]),le,re])]),tbody:f(()=>[(d(!0),u(N,null,q(e.groupsSorted,t=>(d(),u("tr",{index:t.gid},[a("td",ie,[a("span",ce,g(t.group),1),t.isPrimary&&(t.gid>=1e3||t.gid===0)?(d(),u("div",{key:0,title:`${t.primaryMember}'s primary group`},[s(m,{class:"size-icon-sm icon-default"})],8,de)):y("",!0)]),a("td",ue,g(t.gid),1),t.members.length?(d(),u("td",pe,g(t.members.join(", ")),1)):(d(),u("td",me,"No members")),a("td",fe,[a("button",{disabled:!e.checkIfCanDelete(t),title:e.checkIfCanDelete(t)?`Delete group ${t.group}`:"Cannot delete system or primary user groups",onClick:C=>e.deleteConfirmation.ask(t)},[s(x,{class:"size-icon icon-danger"})],8,ge)])],8,se))),256))]),_:1})])]),s(_,{showModal:e.newGroup.showModal,autoWidth:"",headerText:"Create New Group",applyText:"Create",onApply:e.newGroup.applyCallback,onCancel:e.newGroup.cancelCallback,disableContinue:!e.newGroup.valid},{default:f(()=>[he,V(a("input",{type:"text",class:"w-full input-textlike","onUpdate:modelValue":r[3]||(r[3]=t=>e.newGroup.group=t),onInput:r[4]||(r[4]=(...t)=>e.newGroup.validateInputs&&e.newGroup.validateInputs(...t))},null,544),[[D,e.newGroup.group]]),e.newGroup.feedback.group?(d(),u("div",_e,[s(c,{class:"size-icon icon-error"}),a("span",{innerHTML:e.newGroup.feedback.group,class:"text-feedback text-error"},null,8,be)])):y("",!0)]),_:1},8,["showModal","onApply","onCancel","disableContinue"]),s(_,{showModal:e.deleteConfirmation.showModal,onApply:e.deleteConfirmation.applyCallback,onCancel:e.deleteConfirmation.cancelCallback,headerText:`Delete group ${(b=e.deleteConfirmation.group)==null?void 0:b.group}?`,applyText:e.deleteConfirmation.applyText,disableContinue:!e.deleteConfirmation.confirmed,applyDangerous:"",autoWidth:""},{icon:f(()=>[s(c,{class:"size-icon-xl icon-danger"})]),default:f(()=>{var t,C;return[(C=(t=e.deleteConfirmation.group)==null?void 0:t.members)!=null&&C.length?(d(),u("div",Ce," Group member"+g(e.deleteConfirmation.group.members.length>1?"s":"")+": "+g(e.deleteConfirmation.group.members.join(", ")),1)):y("",!0),a("div",ke,[we,a("span",ve,g(e.deleteConfirmation.confirmationCheck()),1),ye]),V(a("input",{type:"text",class:"input-textlike w-full","onUpdate:modelValue":r[5]||(r[5]=k=>e.deleteConfirmation.confirmationInput=k),onInput:r[6]||(r[6]=(...k)=>e.deleteConfirmation.checkConfirmation&&e.deleteConfirmation.checkConfirmation(...k))},null,544),[[D,e.deleteConfirmation.confirmationInput]])]}),_:1},8,["showModal","onApply","onCancel","headerText","applyText","disableContinue"])],64)}var Se=j(Q,[["render",xe]]);export{Se as default};