import{_ as E,r as v,j as f,y as $,n as w,i as y,E as C,z as L,A as P,B as A,L as I,o as k,b as D,e,c as H,f as V,a as N,k as z,m as F,t as K,F as M,u as b,l as O,h as m}from"./index.65dec0ff.js";import{U as R,a as T}from"./UserPassword.7cb447ca.js";import"./PlusIcon.06bbd797.js";const G={setup(B,{emit:g}){var _;const d=v(),o=f($),n=f(w),p=y({user:"",primaryGroup:"",name:"",home:"",shell:(_=o.value.find(s=>/bash/.test(s.path)))!=null?_:C("/bin/bash"),groups:[]});let l=[];const r=v(0),u=f(L);P(()=>u.value=!0),A(()=>u.value=!1);const c=y({onInput:(s,t)=>{s.user!==t.user&&(!s.user&&/^\/home\//.test(s.home)?s.home="":(!s.home||/^\/home\//.test(s.home))&&(s.home=`/home/${s.user}`),s.primaryGroup=s.user)},validateInputs:s=>{let t=!1;const i={};return l.includes(s.user)&&(i.user=`User exists. Go to user editor for ${s.user}`,t=!0),{errors:t,...i}}});return(async()=>{r.value++;try{l=(await b(["getent","passwd"],{superuser:"try"}).promise()).stdout.split(`
`).map(t=>/^\s*$/.test(t)?null:t.split(":")[0]).filter(t=>t!==null)}catch(s){n.value.constructNotification("Failed to get exiting users",`${O(s)}
Be careful not to create an existing user.`,"warning")}finally{r.value--}})(),{userPasswordRef:d,user:p,processing:r,editorHooks:c,createUser:async(s,t)=>{var i;r.value++;try{const x=[],h=[],a=["useradd","-m"];s.name&&a.push("--comment",s.name),s.home&&a.push("--home",s.home),a.push("--user-group"),s.groups.length&&a.push("--groups",s.groups.join(",")),s.shell.path&&a.push("-s",s.shell.path),a.push(s.user),x.push(b(a,{superuser:"try"}).promise());for(const j of x)try{await j}catch(S){h.push(S.errorStringHTML())}h.length?n.value.constructNotification("Error creating user",`${h.join(`
`)}`,"error"):(Object.assign(p,s),n.value.constructNotification("Created user",`${(i=s.name)!=null?i:s.user} was created successfully.`,"success"),g("refreshGroups"),await d.value.setPassword(),cockpit.location.go(`/users/${s.user}`),n.value.constructNotification("Redirected","You were taken to the user editor after creation.","info").addAction("Back to users list",()=>cockpit.location.go("/users")))}finally{r.value--}}}},components:{UserEditor:R,LoadingSpinner:I,UserPassword:T},emits:["refreshGroups"]},Y={class:"flex flex-col centered-column p-well gap-well"},q=e("div",{class:"card sticky top-0 z-10"},[e("div",{class:"card-header flex flex-row flex-wrap items-baseline gap-2"},[e("span",{class:"text-header"},"New User")])],-1),J={class:"card"},Q={class:"card-header flex flex-row space-x-2 items-center"},W=e("h3",{class:"text-header"},"Details",-1),X=e("span",{class:"text-muted"},"(primary group)",-1),Z=e("td",null,null,-1);function U(B,g,d,o,n,p){const l=m("LoadingSpinner"),r=m("UserEditor"),u=m("UserPassword");return k(),D(M,null,[e("div",Y,[q,e("div",J,[e("div",Q,[W,o.processing?(k(),H(l,{key:0,class:"size-icon"})):V("",!0)]),N(r,{user:o.user,createNew:"",hooks:o.editorHooks,onApplyChanges:o.createUser},{primaryGroup:z(({primaryGroup:c})=>[e("tr",null,[e("td",null,[F(K(c!=null?c:"")+" ",1),X]),Z])]),_:1},8,["user","hooks","onApplyChanges"])])]),N(u,{modalOnly:"",newUser:"",user:o.user.user,ref:"userPasswordRef"},null,8,["user"])],64)}var as=E(G,[["render",U]]);export{as as default};