import{j as e,S as l,h as u,r as x,H as b,aB as C,a1 as v}from"./vendor-ClLR6ncd.js";import{d as w}from"./Cancel-BcN7wjUl.js";import{d as I}from"./Add-CLrXAvOx.js";import{E,q as P,d as k,ar as j,i as c,o as S,L,T as m}from"./index-OtVJl4GC.js";import{E as T}from"./Messages-BRmQDxrZ.js";import{S as M}from"./SyncingMessage-Y9_Q8a92.js";import{a as Q}from"./TypographyWithTooltip-BFAG3Va9.js";import{a as D}from"./index-DY-IkI-n.js";import{C as B}from"./CreateDialogContext-Buan56-U.js";import"./lodash-ZyeDnt0e.js";import{O as N}from"./OptionallyDenseMuiTable-D7b58l1V.js";import{T as K}from"./TableContainer-CN5gAdqf.js";import{a as O,T as p,b as a,c as A}from"./TableRow-CGDSOtFZ.js";import"./usePrevious-BP64N3hu.js";import"./DialogContent-DR8Wx7Lo.js";import"./DialogTitle-i0lt2jWQ.js";const d=()=>["user",P().username,"tokens"];function R(){const t=d();return k(s=>c({url:"/token",params:{token:s},method:"delete"}),{onSuccess:()=>{j.invalidateQueries(t)}})}function W(){const t=d();return k(({expiresIn:s,idleTimeout:r})=>c({url:"/token",params:{expiresIn:s,idleTimeout:r}}),{onSuccess:()=>{j.invalidateQueries(t)}})}function F(){const t=d();return E(t,()=>c({url:"/token/list"}),{refetchInterval:5e3})}function G({str:t}){return t===null?"-":e.jsx(Q,{value:t,originalValue:t})}const $={maxWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},h=[{label:"Token ID",key:"token"},{label:"Label",key:"description"},{label:"Expires",key:"expiresAt"},{label:"Last Used",key:"touchedAt"},{label:"Idle Timeout",key:"idleTimeout"}].map(t=>({...t,sx:$,Component:G}));function q({tokens:t}){const s=R();return e.jsxs(e.Fragment,{children:[e.jsx(T,{error:s.error,resetError:s.reset}),e.jsx(K,{component:C,children:e.jsxs(N,{sx:{tableLayout:"fixed"},children:[e.jsx(O,{children:e.jsxs(p,{children:[h.map(({label:r,sx:n})=>e.jsx(a,{sx:n,children:r},r)),e.jsx(a,{sx:{width:"100px"},children:"Revoke"})]})}),e.jsx(A,{sx:{width:1},children:t.map(r=>e.jsxs(p,{sx:{"&:last-child td, &:last-child th":{border:0}},children:[h.map(({key:n,label:i,Component:o,sx:y})=>e.jsx(a,{sx:y,children:o?e.jsx(o,{str:r[n]}):r[n]},i)),e.jsx(a,{sx:{width:"100px"},children:e.jsx(v,{disabled:s.isLoading,onClick:()=>s.mutate(r.token),children:e.jsx(w,{})})})]},r.token))})]})})]})}const{useDialogContext:f,DialogContextProvider:H}=B(),V=t=>t.openParameter;function _(){const t=f(),s=W(),r=x.useCallback(i=>{t.setOpenParameter(o=>({...o,expiresIn:i}))},[t]),n=x.useCallback(i=>{t.setOpenParameter(o=>({...o,idleTimeout:i}))},[t]);return e.jsx(D,{mutationParameterBuilder:V,dialogContext:t,mutation:s,submitTitle:"Create",dialogBodyMessage:s.isIdle?e.jsxs(l,{spacing:1,children:[e.jsx(u,{children:"Provide timeout parameters (in seconds) for the new token. Leave the box empty to disable either of the timeouts."}),e.jsx(m,{value:t.openParameter.expiresIn,setter:r,label:"Expires in"}),e.jsx(m,{value:t.openParameter.idleTimeout,setter:n,label:"Idle timeout"})]}):s.isError?`Generating token failed: ${s.error}`:s.isSuccess?`New token: "${s.data}". You will not be able to see it again, so make sure to save it before closing this message.`:s.isLoading?"Generating token...":""})}function U(){const t=f();return e.jsx(b,{startIcon:e.jsx(I,{}),onClick:()=>t.open(g),children:"New token"})}const g={expiresIn:"",idleTimeout:""};function de(){const t=F(),s=S();return t.isLoading?e.jsx("div",{style:{display:"flex",alignItems:"center",flexGrow:1},children:e.jsx(L,{})}):e.jsxs(l,{spacing:s,children:[e.jsxs(l,{direction:"row",justifyContent:"space-between",children:[e.jsxs(l,{direction:"row",spacing:4,children:[e.jsx(u,{variant:"h4",children:"Tokens"}),e.jsx(M,{isFetching:t.isFetching,entityKind:"tokens"})]}),e.jsxs(H,{initParameterValue:g,children:[e.jsx(_,{}),e.jsx(U,{})]})]}),t.isError?e.jsx(T,{error:t.error,resetError:()=>{}}):t.data.length===0?e.jsx(u,{children:"There are no tokens"}):e.jsx(q,{tokens:t.data})]})}export{de as default};
