import{n as e}from"./chunk-QTnfLwEv.js";import{C as t,D as n,E as r,F as i,G as a,L as o,R as s,W as c,Y as l,Z as u,_ as d,et as f,k as p,m,v as h,w as g,x as _}from"./app-D89C2uIa.js";import{t as v}from"./i18n-DlPAX0tK.js";import{t as y}from"./InputLabel-CFA7PxFo.js";import{t as b}from"./PrimaryButton-DV1oaSvW.js";var x={class:`text-lg font-medium text-gray-900 dark:text-gray-100`},S={class:`mt-1 text-sm text-gray-600 dark:text-gray-400`},C={key:0,class:`mt-6 rounded-lg border border-amber-300 bg-amber-50 p-4 dark:border-amber-700 dark:bg-amber-900/20`},w={class:`text-sm font-medium text-amber-800 dark:text-amber-300`},T={class:`mt-2 flex items-center gap-2`},E={class:`flex-1 truncate rounded bg-white px-2 py-1.5 font-mono text-xs text-gray-800 dark:bg-gray-900 dark:text-gray-200`},D={class:`flex-1`},O=[`placeholder`],k={key:1,class:`mt-2 text-sm text-red-600`},A={class:`mt-6 divide-y divide-gray-200 dark:divide-gray-700`},j={class:`text-sm font-medium text-gray-900 dark:text-gray-100`},M={class:`text-xs text-gray-500 dark:text-gray-400`},N=[`onClick`],P={key:0,class:`py-3 text-sm text-gray-500 dark:text-gray-400`},F=p({__name:`AccessTokensForm`,setup(e){let p=l([]),F=l(``),I=l(!1),L=l(``),R=l(null),z=l(!1);function B(){let e=document.cookie.match(/XSRF-TOKEN=([^;]+)/);return e?decodeURIComponent(e[1]):``}async function V(e,t,n){let r=await fetch(t,{method:e,credentials:`same-origin`,headers:{"Content-Type":`application/json`,"X-XSRF-TOKEN":B(),Accept:`application/json`},body:n?JSON.stringify(n):void 0});if(!r.ok)throw Error(`Request failed`);return r.json()}async function H(){try{p.value=await V(`GET`,`/user/tokens`)}catch{}}i(H);async function U(){if(L.value=``,F.value.trim()){I.value=!0;try{let e=await V(`POST`,`/user/tokens`,{name:F.value.trim()});R.value=e.plainTextToken,z.value=!1,p.value.unshift(e.token),F.value=``}catch{L.value=v(`Could not create the token.`)}finally{I.value=!1}}}async function W(e){if(confirm(v(`Revoke “{name}”? Apps using it will stop working.`,{name:e.name})))try{await V(`DELETE`,`/user/tokens/${e.id}`),p.value=p.value.filter(t=>t.id!==e.id)}catch{}}async function G(){if(R.value)try{await navigator.clipboard.writeText(R.value),z.value=!0}catch{}}return(e,i)=>(o(),g(`section`,null,[_(`header`,null,[_(`h2`,x,f(u(v)(`API access tokens`)),1),_(`p`,S,f(u(v)(`Personal tokens let external apps or scripts access the API as you. Treat them like passwords.`)),1)]),R.value?(o(),g(`div`,C,[_(`p`,w,f(u(v)(`Copy your new token now — it won’t be shown again.`)),1),_(`div`,T,[_(`code`,E,f(R.value),1),_(`button`,{type:`button`,class:`rounded-md bg-amber-600 px-3 py-1.5 text-sm font-semibold text-white hover:bg-amber-700`,onClick:G},f(z.value?u(v)(`Copied!`):u(v)(`Copy`)),1)])])):t(``,!0),_(`form`,{class:`mt-6 flex items-end gap-3`,onSubmit:d(U,[`prevent`])},[_(`div`,D,[n(y,{for:`token_name`,value:u(v)(`Token name`)},null,8,[`value`]),a(_(`input`,{id:`token_name`,"onUpdate:modelValue":i[0]||=e=>F.value=e,type:`text`,maxlength:`60`,placeholder:u(v)(`e.g. My script`),class:`mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300`},null,8,O),[[m,F.value]])]),n(b,{disabled:I.value},{default:c(()=>[r(f(u(v)(`Create`)),1)]),_:1},8,[`disabled`])],32),L.value?(o(),g(`p`,k,f(L.value),1)):t(``,!0),_(`ul`,A,[(o(!0),g(h,null,s(p.value,e=>(o(),g(`li`,{key:e.id,class:`flex items-center justify-between py-3`},[_(`div`,null,[_(`div`,j,f(e.name),1),_(`div`,M,f(u(v)(`Created {created} · last used {lastUsed}`,{created:e.created,lastUsed:e.lastUsed})),1)]),_(`button`,{type:`button`,class:`text-sm font-semibold text-red-600 hover:text-red-700`,onClick:t=>W(e)},f(u(v)(`Revoke`)),9,N)]))),128)),p.value.length?t(``,!0):(o(),g(`li`,P,f(u(v)(`No tokens yet.`)),1))])]))}}),I=e({default:()=>L}),L=F;export{I as n,L as t};