import{c as $,T as w}from"./index-HFEfURXv.js";import{a as x,s as B,t as D,p as h,_ as b,$ as F,q as v,r as I,i as u}from"./vuetify-ffr1lJCG.js";import{d as N,r as k,w as U,D as c,e as d,E as t,H as l,ab as q,Z as m,_ as i,b as A,F as E,f as S}from"./lucide-sS6c3snl.js";import{u as z}from"./vue-i18n-h4EBIvPF.js";const H={class:"text-body-2 mb-2 text-grey-darken-1"},K=N({__name:"CreateTokenDialog",props:{modelValue:{type:Boolean},userId:{}},emits:["update:modelValue","created"],setup(V,{emit:C}){const{t:n}=z(),y=V,p=C,f=k(!1),o=k(""),a=k(""),_=()=>{o.value="",a.value="",requestAnimationFrame(()=>{p("update:modelValue",!1)})},T=async()=>{f.value=!0;try{const e=await $.createToken(o.value,y.userId);e?(u.success(n("auth.token_created")),a.value=e,p("created")):u.error(n("auth.token_create_failed"))}catch(e){u.error(e.message||n("auth.token_create_failed"))}finally{f.value=!1}};U(()=>y.modelValue,e=>{e||(o.value="",a.value="")});const g=async()=>{if(!a.value)return;await w(a.value)?u.success(n("auth.token_copied")):u.error(n("auth.token_copy_failed"))};return(e,s)=>(d(),c(I,{"model-value":V.modelValue,"max-width":"500","onUpdate:modelValue":s[2]||(s[2]=r=>p("update:modelValue",r))},{default:t(()=>[l(x,null,{default:t(()=>[l(B,{class:q(["text-h6 pa-6",{"pb-0":a.value,"pb-4":!a.value}])},{default:t(()=>[m(i(a.value?o.value:e.$t("auth.create_token")),1)]),_:1},8,["class"]),l(D,{class:"px-6 pb-2"},{default:t(()=>[a.value?(d(),A(E,{key:1},[S("p",H,i(e.$t("auth.copy_new_token_hint")),1),l(h,{modelValue:a.value,"onUpdate:modelValue":s[1]||(s[1]=r=>a.value=r),readonly:"",variant:"outlined",density:"comfortable",class:"mb-2","append-inner-icon":"mdi-content-copy","onClick:appendInner":g},null,8,["modelValue"])],64)):(d(),c(h,{key:0,modelValue:o.value,"onUpdate:modelValue":s[0]||(s[0]=r=>o.value=r),label:e.$t("auth.token_name"),variant:"outlined",density:"comfortable",hint:e.$t("auth.token_name_hint"),"persistent-hint":"",autofocus:""},null,8,["modelValue","label","hint"]))]),_:1}),a.value?(d(),c(b,{key:1,class:"px-6 pb-6 pt-0"},{default:t(()=>[l(v,{color:"primary",variant:"tonal",onClick:_},{default:t(()=>[m(i(e.$t("close")),1)]),_:1})]),_:1})):(d(),c(b,{key:0,class:"pa-6 pt-4"},{default:t(()=>[l(F),l(v,{variant:"text",onClick:_},{default:t(()=>[m(i(e.$t("cancel")),1)]),_:1}),l(v,{color:"primary",variant:"flat",loading:f.value,disabled:!o.value,onClick:T},{default:t(()=>[m(i(e.$t("create")),1)]),_:1},8,["loading","disabled"])]),_:1}))]),_:1})]),_:1},8,["model-value"]))}});export{K as _};
