import{an as m,ap as k,aH as d,x as u,k as x,a2 as h,a7 as T,r as y,j as e,M as v,Q as D,T as a,R as C,B as i,am as b,a3 as F,av as j,aw as N,E as A,ao as S,l as w,g as E,aE as P,aF as I,L,c as q,D as g}from"./main-TIUJvpaR.js";import{A as B,a as _}from"./account-settings-sidenav-N9ABQ3A7.js";import{L as M}from"./external-link-DvqU4uvd.js";import{F as Q}from"./formatted-date-CsxGDhkC.js";import{C as H}from"./confirmation-dialog-Ds1Wl8FN.js";import{D as z}from"./dialog-footer-yCpPZGPO.js";import{u as K}from"./use-clipboard-D3xJiv8M.js";import{s as O}from"./secure-files-DjSbgaf8.js";function R(s){return x.post("access-tokens",s).then(t=>t.data)}function Y(s){return m({mutationFn:t=>R(t),onSuccess:()=>{d(u("Token create"))},onError:t=>k(t,s)})}function $(){const s=h(),{formId:t,close:o}=T(),n=Y(s),[r,c]=y.useState(),l=e.jsx(b,{form:s,id:t,onSubmit:p=>{n.mutate(p,{onSuccess:f=>{c(f.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(v,{children:[e.jsx(D,{children:e.jsx(a,{message:"Create new token"})}),e.jsx(C,{children:r?e.jsx(G,{plainTextToken:r}):l}),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 G({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 J({id:s}){return x.delete(`access-tokens/${s}`).then(t=>t.data)}function V(){return m({mutationFn:s=>J(s),onSuccess:()=>{d(u("Token deleted"))},onError:s=>S(s)})}function ie({user:s}){const t=s.tokens||[],{hasPermission:o,user:n}=w(),{api:r}=E();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(X,{}):null,children:t.length?t.map((c,l)=>e.jsx(W,{token:c,isLast:l===t.length-1},c.id)):e.jsx(P,{className:"py-40",image:e.jsx(I,{src:O}),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 W({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(Q,{date:s.last_used_at}):e.jsx(a,{message:"Never"})})]}),e.jsx(Z,{token:s})]})}function X(){return e.jsxs(g,{type:"modal",children:[e.jsx(i,{variant:"flat",color:"primary",children:e.jsx(a,{message:"Create token"})}),e.jsx($,{})]})}function Z({token:s}){const t=V();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(H,{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{ie as A};
