import{n as e}from"./chunk-QTnfLwEv.js";import{$ as t,C as n,D as r,E as i,I as a,J as o,L as s,O as c,P as l,U as u,W as d,X as f,_ as p,m,v as h,w as g,x as _}from"./app-DzVVa1IW.js";import{t as v}from"./i18n-CDNlCXhf.js";import{t as y}from"./InputLabel-CdHjBjgB.js";import{t as b}from"./PrimaryButton-CzdG4Tmv.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=c({__name:`AccessTokensForm`,setup(e){let c=o([]),F=o(``),I=o(!1),L=o(``),R=o(null),z=o(!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{c.value=await V(`GET`,`/user/tokens`)}catch{}}l(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,c.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}`),c.value=c.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,o)=>(a(),g(`section`,null,[_(`header`,null,[_(`h2`,x,t(f(v)(`API access tokens`)),1),_(`p`,S,t(f(v)(`Personal tokens let external apps or scripts access the API as you. Treat them like passwords.`)),1)]),R.value?(a(),g(`div`,C,[_(`p`,w,t(f(v)(`Copy your new token now — it won’t be shown again.`)),1),_(`div`,T,[_(`code`,E,t(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},t(z.value?f(v)(`Copied!`):f(v)(`Copy`)),1)])])):n(``,!0),_(`form`,{class:`mt-6 flex items-end gap-3`,onSubmit:p(U,[`prevent`])},[_(`div`,D,[r(y,{for:`token_name`,value:f(v)(`Token name`)},null,8,[`value`]),d(_(`input`,{id:`token_name`,"onUpdate:modelValue":o[0]||=e=>F.value=e,type:`text`,maxlength:`60`,placeholder:f(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]])]),r(b,{disabled:I.value},{default:u(()=>[i(t(f(v)(`Create`)),1)]),_:1},8,[`disabled`])],32),L.value?(a(),g(`p`,k,t(L.value),1)):n(``,!0),_(`ul`,A,[(a(!0),g(h,null,s(c.value,e=>(a(),g(`li`,{key:e.id,class:`flex items-center justify-between py-3`},[_(`div`,null,[_(`div`,j,t(e.name),1),_(`div`,M,t(f(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)},t(f(v)(`Revoke`)),9,N)]))),128)),c.value.length?n(``,!0):(a(),g(`li`,P,t(f(v)(`No tokens yet.`)),1))])]))}}),I=e({default:()=>L}),L=F;export{I as n,L as t};