import{G as m,ai as k,I as d,J as u,b as x,M as h,a0 as T,r as v,j as e,a1 as y,a2 as D,T as a,a3 as b,t as i,au as C,V as F,ab as j,at as N,E as A,H as S,e as w,u as P,al as E,am as I,v as L,d as q,D as g}from"./main-D6SjkSWq.js";import{A as B,a as _}from"./account-settings-sidenav-Boqe6eiG.js";import{L as M}from"./external-link-BB1wMD8k.js";import{F as H}from"./formatted-date-BIydE9wI.js";import{C as Q}from"./confirmation-dialog-E4zsogCz.js";import{D as z}from"./dialog-footer-es-AfbvV.js";import{u as K}from"./use-clipboard-B8UhuEe-.js";function O(s){return x.post("access-tokens",s).then(t=>t.data)}function R(s){return m({mutationFn:t=>O(t),onSuccess:()=>{d(u("Token create"))},onError:t=>k(t,s)})}function G(){const s=h(),{formId:t,close:o}=T(),n=R(s),[r,l]=v.useState(),c=e.jsx(C,{form:s,id:t,onSubmit:f=>{n.mutate(f,{onSuccess:p=>{l(p.plainTextToken),j.invalidateQueries({queryKey:["users"]})}})},children:e.jsx(F,{name:"tokenName",label:e.jsx(a,{message:"Token name"}),required:!0,autoFocus:!0})});return e.jsxs(y,{children:[e.jsx(D,{children:e.jsx(a,{message:"Create new token"})}),e.jsx(b,{children:r?e.jsx(J,{plainTextToken:r}):c}),e.jsxs(z,{children:[e.jsx(i,{variant:"text",onClick:o,children:e.jsx(a,{message:"Done"})}),!r&&e.jsx(i,{variant:"flat",color:"primary",type:"submit",form:t,disabled:n.isPending,children:e.jsx(a,{message:"Create"})})]})]})}function J({plainTextToken:s}){const[t,o]=K(s||"",{successDuration:1e3});return e.jsxs(e.Fragment,{children:[e.jsx(N,{readOnly:!0,value:s,autoFocus:!0,onClick:n=>{n.currentTarget.focus(),n.currentTarget.select()},endAppend:e.jsx(i,{variant:"flat",color:"primary",onClick:o,children:t?e.jsx(a,{message:"Copied!"}):e.jsx(a,{message:"Copy"})})}),e.jsxs("div",{className:"mt-14 flex items-center gap-10 text-sm",children:[e.jsx(A,{size:"sm",className:"text-danger"}),e.jsx(a,{message:"Make sure to store the token in a safe place. After this dialog is closed, token will not be viewable anymore."})]})]})}function V({id:s}){return x.delete(`access-tokens/${s}`).then(t=>t.data)}function Y(){return m({mutationFn:s=>V(s),onSuccess:()=>{d(u("Token deleted"))},onError:s=>S(s)})}const Z=""+new URL("secure-files-B4ZUs63v.svg",import.meta.url).href;function re({user:s}){const t=s.tokens||[],{hasPermission:o,user:n}=w(),{api:r}=P();return!(r!=null&&r.integrated)||!o("api.access")?null:e.jsx(B,{id:_.Developers,title:e.jsx(a,{message:"API access tokens"}),titleSuffix:e.jsx(L,{className:M,to:"/api-docs",target:"_blank",children:e.jsx(a,{message:"Documentation"})}),actions:s.id===(n==null?void 0:n.id)?e.jsx(U,{}):null,children:t.length?t.map((l,c)=>e.jsx($,{token:l,isLast:c===t.length-1},l.id)):e.jsx(E,{className:"py-40",image:e.jsx(I,{src:Z}),title:s.id===(n==null?void 0:n.id)?e.jsx(a,{message:"You have no personal access tokens yet"}):e.jsx(a,{message:"User has not created any access tokens yet"})})})}function $({token:s,isLast:t}){return e.jsxs("div",{className:q("flex items-center gap-24",!t&&"mb-12 border-b pb-12"),children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-semibold",children:e.jsx(a,{message:"Name"})}),e.jsx("div",{children:s.name}),e.jsx("div",{className:"mt-10 font-semibold",children:e.jsx(a,{message:"Last used"})}),e.jsx("div",{children:s.last_used_at?e.jsx(H,{date:s.last_used_at}):e.jsx(a,{message:"Never"})})]}),e.jsx(W,{token:s})]})}function U(){return e.jsxs(g,{type:"modal",children:[e.jsx(i,{variant:"flat",color:"primary",children:e.jsx(a,{message:"Create token"})}),e.jsx(G,{})]})}function W({token:s}){const t=Y();return e.jsxs(g,{type:"modal",onClose:o=>{o&&t.mutate({id:s.id},{onSuccess:()=>j.invalidateQueries({queryKey:["users"]})})},children:[e.jsx(i,{size:"xs",variant:"outline",color:"danger",className:"ml-auto flex-shrink-0",children:e.jsx(a,{message:"Delete"})}),e.jsx(Q,{isDanger:!0,title:e.jsx(a,{message:"Delete token?"}),body:e.jsx(a,{message:"This token will be deleted immediately and permanently. Once deleted, it can no longer be used to make API requests."}),confirm:e.jsx(a,{message:"Delete"})})]})}export{re as A};
