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