import{X as e,b7 as t,bq as r,E as n,ao as s,c1 as a,a6 as i,c0 as l,dp as g,a8 as u,q as d,bt as c,x as o,S as h,bV as w,aQ as p,aX as $,aR as m,aS as k,bu as y,aT as x,aU as f,bR as S,bE as _,bo as b,bW as A,aW as v,a7 as z,a1 as C,F as I}from"./index-WdfADTOW.js";const M=[{name:"title",textAlign:"left",w:"calc(35% - 110px)"},{name:"fingerprint",textAlign:"left",w:"calc(65% - 110px)"},{name:"last_used",textAlign:"right",w:"140px"},{name:"operation",textAlign:"right",w:"80px"}],O=w=>{const p=d(),[$,m]=e(!1),[k,y]=w.isMine?t(()=>r.post(`/me/sshkey/delete?id=${w.id}`)):t(()=>r.post(`/admin/user/sshkey/delete?uid=${w.userId}&id=${w.id}`)),x={whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};return n(h,{get when(){return!$()},get children(){return n(s,{w:"$full",p:"$2",get children(){return[n(a,{get w(){return M[0].w},size:"sm",get textAlign(){return M[0].textAlign},css:x,get children(){return w.title}}),n(i,{get w(){return M[1].w},size:"sm",get textAlign(){return M[1].textAlign},css:x,get children(){return w.fingerprint}}),n(i,{get w(){return M[2].w},size:"sm",get textAlign(){return M[2].textAlign},css:x,get children(){return`${(e=new Date(w.last_used_time)).getFullYear().toString()}/${(e.getMonth()+1).toString().padStart(2,"0")}/${e.getDate().toString().padStart(2,"0")} ${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}`;var e}}),n(l,{get w(){return M[3].w},gap:"$1",get children(){return[n(g,{}),n(u,{size:"sm",colorScheme:"danger",get loading(){return k()},onClick:async()=>{const e=await y();c(e,()=>{o.success(p("global.delete_success")),m(!0)})},get children(){return p("global.delete")}})]}})]}})}})},T=o=>{const T=d(),[W,X]=e([]),[q,D]=o.isMine?t(()=>r.get("/me/sshkey/list")):t(()=>r.get(`/admin/user/sshkey/list?uid=${o.userId}`)),[E,F]=w({title:"",key:""}),[R,j]=t(()=>r.post("/me/sshkey/add",E)),{isOpen:B,onOpen:H,onClose:P}=p(),Q=async()=>{const e=await D();c(e,e=>{X(e.content)})};Q();const U=e=>({fontWeight:"bold",fontSize:"$sm",color:"$neutral11",textAlign:e.textAlign});return n(z,{w:"$full",alignItems:"start",spacing:"$2",get children(){return[n(l,{w:"$full",get children(){return[n(a,{get children(){return T("users.ssh_keys.heading")}}),n(h,{get when(){return o.isMine},get children(){return[n(g,{}),n(u,{get loading(){return q()},onClick:H,get children(){return T("global.add")}}),n($,{get opened(){return B()},onClose:P,scrollBehavior:"inside",get children(){return[n(m,{}),n(k,{get children(){return[n(y,{}),n(x,{get children(){return T("users.ssh_keys.add_heading")}}),n(f,{get children(){return[n(S,{mb:"$4",get children(){return[n(_,{for:"add_title",get children(){return T("users.ssh_keys.title")}}),n(b,{id:"add_title",get value(){return E.title},onInput:e=>F("title",e.currentTarget.value)})]}}),n(S,{get children(){return[n(_,{for:"add_key",get children(){return T("users.ssh_keys.key")}}),n(A,{id:"add_key",get value(){return E.key},onInput:e=>F("key",e.currentTarget.value)})]}})]}}),n(v,{get children(){return n(u,{get loading(){return R()},onClick:async()=>{const e=await j();c(e,()=>{F("title",""),F("key",""),Q(),P()})},get children(){return T("global.add")}})}})]}})]}})]}})]}}),n(z,{w:"$full",overflowX:"auto",shadow:"$md",rounded:"$lg",spacing:"$1",p:"$1",get children(){return[n(s,{class:"title",w:"$full",p:"$2",get children(){return[n(i,I({get w(){return M[0].w}},()=>U(M[0]),{get children(){return T(`users.ssh_keys.${M[0].name}`)}})),n(i,I({get w(){return M[1].w}},()=>U(M[1]),{get children(){return T(`users.ssh_keys.${M[1].name}`)}})),n(i,I({get w(){return M[2].w}},()=>U(M[2]),{get children(){return T(`users.ssh_keys.${M[2].name}`)}})),n(i,I({get w(){return M[3].w}},()=>U(M[3]),{get children(){return T(`users.ssh_keys.${M[3].name}`)}}))]}}),C(()=>W().map(e=>n(O,I(o,e))))]}})]}})};export{T as P};
