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