import{j as _,bV as k,b9 as p,bq as d,D as e,ah as v,c0 as F,o as f,S as h,bR as i,bE as l,I as m,a5 as c,b$ as S,R as q,aW as D,bc as b,K as E,bt as g,r as L,a6 as M,d9 as P,ao as R}from"./index-CNZMR1GT.js";import{a as T}from"./FolderTree-CTh3_qOS.js";import{P as U}from"./PublicKeys-T_ouY8oQ.js";import"./index-DsSWFirV.js";const K=r=>{const o=f();return e(i,{display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"$2",rounded:"$md",shadow:"$md",p:"$2",w:"fit-content",get children(){return[e(l,{mb:"0",get children(){return o("users.permissions.".concat(r.name))}}),e(b,{get checked(){return r.can},onChange:()=>r.onChange(!r.can)})]}})},H=()=>{const r=f(),{params:o,back:w}=_(),{id:n}=o,[t,a]=k({id:0,username:"",password:"",base_path:"",role:0,permission:0,disabled:!1,sso_id:""}),[$,y]=p(()=>d.get("/admin/user/get?id=".concat(n)));n&&(async()=>{const s=await y();g(s,a)})();const[x,I]=p(()=>d.post("/admin/user/".concat(n?"update":"create"),t));return e(R,{get loading(){return $()},get children(){return e(v,{w:"$full",alignItems:"start",spacing:"$2",get children(){return[e(F,{get children(){return r("global.".concat(n?"edit":"add"))}}),e(h,{get when(){return!c.is_guest(t)},get children(){return[e(i,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[e(l,{for:"username",display:"flex",alignItems:"center",get children(){return r("users.username")}}),e(m,{id:"username",get value(){return t.username},onInput:s=>a("username",s.currentTarget.value)})]}}),e(i,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[e(l,{for:"password",display:"flex",alignItems:"center",get children(){return r("users.password")}}),e(m,{id:"password",type:"password",placeholder:"********",get value(){return t.password},onInput:s=>a("password",s.currentTarget.value)})]}})]}}),e(i,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[e(l,{for:"base_path",display:"flex",alignItems:"center",get children(){return r("users.base_path")}}),e(T,{id:"base_path",get value(){return t.base_path},onChange:s=>a("base_path",s),onlyFolder:!0})]}}),e(i,{w:"$full",required:!0,get children(){return[e(l,{display:"flex",alignItems:"center",get children(){return r("users.permission")}}),e(S,{w:"$full",wrap:"wrap",gap:"$2",get children(){return e(q,{each:D,children:(s,u)=>e(K,{name:s,get can(){return c.can(t,u())},onChange:C=>{C?a("permission",t.permission|=1<<u()):a("permission",t.permission&=~(1<<u()))}})})}})]}}),e(i,{w:"fit-content",display:"flex",get children(){return e(b,{css:{whiteSpace:"nowrap"},id:"disabled",onChange:s=>a("disabled",s.currentTarget.checked),color:"$neutral10",fontSize:"$sm",get checked(){return t.disabled},get children(){return r("users.disabled")}})}}),e(E,{get loading(){return x()},onClick:async()=>{const s=await I();g(s,async()=>{L.success(r("global.save_success")),t.username===M().username&&g(await d.get("/me"),P),w()})},get children(){return r("global.".concat(n?"save":"add"))}}),e(h,{get when(){return n&&!c.is_guest(t)},get children(){return e(U,{isMine:!1,get userId(){return parseInt(n)}})}})]}})}})};export{H as default};
