import{k as e,bV as r,b7 as a,bq as n,E as s,a7 as t,c1 as l,q as i,S as d,bR as u,bE as c,bo as o,V as g,c0 as p,G as h,aO as m,ba as w,a8 as f,bt as b,x,W as $,dd as y,af as _}from"./index-WdfADTOW.js";import{a as I}from"./FolderTree-CfW3CiDF.js";import{P as k}from"./PublicKeys-Bh1J4OtD.js";import"./index-U4ybYyYy.js";const v=e=>{const r=i();return s(u,{display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"$2",rounded:"$md",shadow:"$md",p:"$2",w:"fit-content",get children(){return[s(c,{mb:"0",get children(){return r(`users.permissions.${e.name}`)}}),s(w,{get checked(){return e.can},onChange:()=>e.onChange(!e.can)})]}})},C=()=>{const C=i(),{params:q,back:S}=e(),{id:T}=q,[j,D]=r({id:0,username:"",password:"",base_path:"",role:0,permission:0,disabled:!1,sso_id:"",allow_ldap:!1}),[z,E]=a(()=>n.get(`/admin/user/get?id=${T}`));T&&(async()=>{const e=await E();b(e,D)})();const[F,P]=a(()=>n.post("/admin/user/"+(T?"update":"create"),j));return s(_,{get loading(){return z()},get children(){return s(t,{w:"$full",alignItems:"start",spacing:"$2",get children(){return[s(l,{get children(){return C("global."+(T?"edit":"add"))}}),s(d,{get when(){return!g.is_guest(j)},get children(){return[s(u,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[s(c,{for:"username",display:"flex",alignItems:"center",get children(){return C("users.username")}}),s(o,{id:"username",get value(){return j.username},onInput:e=>D("username",e.currentTarget.value)})]}}),s(u,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[s(c,{for:"password",display:"flex",alignItems:"center",get children(){return C("users.password")}}),s(o,{id:"password",type:"password",placeholder:"********",get value(){return j.password},onInput:e=>D("password",e.currentTarget.value)})]}})]}}),s(u,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[s(c,{for:"base_path",display:"flex",alignItems:"center",get children(){return C("users.base_path")}}),s(I,{id:"base_path",get value(){return j.base_path},onChange:e=>D("base_path",e),onlyFolder:!0})]}}),s(u,{w:"$full",required:!0,get children(){return[s(c,{display:"flex",alignItems:"center",get children(){return C("users.permission")}}),s(p,{w:"$full",wrap:"wrap",gap:"$2",get children(){return s(h,{each:m,children:(e,r)=>s(v,{name:e,get can(){return g.can(j,r())},onChange:e=>{D("permission",e?j.permission|=1<<r():j.permission&=~(1<<r()))}})})}})]}}),s(u,{w:"fit-content",display:"flex",get children(){return s(w,{css:{whiteSpace:"nowrap"},id:"disabled",onChange:e=>D("disabled",e.currentTarget.checked),color:"$neutral10",fontSize:"$sm",get checked(){return j.disabled},get children(){return C("users.disabled")}})}}),s(u,{w:"fit-content",display:"flex",get children(){return s(w,{css:{whiteSpace:"nowrap"},id:"allow_ldap",onChange:e=>D("allow_ldap",e.currentTarget.checked),color:"$neutral10",fontSize:"$sm",get checked(){return j.allow_ldap},get children(){return C("users.allow_ldap")}})}}),s(f,{get loading(){return F()},onClick:async()=>{const e=await P();b(e,async()=>{x.success(C("global.save_success")),j.username===$().username&&b(await n.get("/me"),y),S()})},get children(){return C("global."+(T?"save":"add"))}}),s(d,{get when(){return T&&!g.is_guest(j)},get children(){return s(k,{isMine:!1,get userId(){return parseInt(T)}})}})]}})}})};export{C as default};
