import{ay as $,bN as w,J as v,L as x,aI as c,aA as r,aG as t,o as l,aS as B,bg as N,r as I,bh as p,aN as d,c3 as A,az as D,bH as h,ah as F,E as S,bV as _,bW as U,M as k,aP as z,aW as i,c7 as E}from"./index-BRUnowC8.js";import{V as W}from"./VDialog-Bh3mGVOy.js";const q={class:"text-body-2 mb-2 text-grey-darken-1"},J=$({__name:"CreateTokenDialog",props:{modelValue:{type:Boolean},userId:{}},emits:["update:modelValue","created"],setup(V,{emit:C}){const{t:n}=w(),y=V,m=C,f=v(!1),o=v(""),a=v(""),b=()=>{o.value="",a.value="",requestAnimationFrame(()=>{m("update:modelValue",!1)})},g=async()=>{f.value=!0;try{const e=await z.createToken(o.value,y.userId);e?(i.success(n("auth.token_created")),a.value=e,m("created")):i.error(n("auth.token_create_failed"))}catch(e){i.error(e.message||n("auth.token_create_failed"))}finally{f.value=!1}};x(()=>y.modelValue,e=>{e||(o.value="",a.value="")});const T=async()=>{if(!a.value)return;await E(a.value)?i.success(n("auth.token_copied")):i.error(n("auth.token_copy_failed"))};return(e,s)=>(r(),c(W,{"model-value":V.modelValue,"max-width":"500","onUpdate:modelValue":s[2]||(s[2]=u=>m("update:modelValue",u))},{default:t(()=>[l(B,null,{default:t(()=>[l(N,{class:I(["text-h6 pa-6",{"pb-0":a.value,"pb-4":!a.value}])},{default:t(()=>[p(d(a.value?o.value:e.$t("auth.create_token")),1)]),_:1},8,["class"]),l(A,{class:"px-6 pb-2"},{default:t(()=>[a.value?(r(),D(F,{key:1},[S("p",q,d(e.$t("auth.copy_new_token_hint")),1),l(h,{modelValue:a.value,"onUpdate:modelValue":s[1]||(s[1]=u=>a.value=u),readonly:"",variant:"outlined",density:"comfortable",class:"mb-2","append-inner-icon":"mdi-content-copy","onClick:appendInner":T},null,8,["modelValue"])],64)):(r(),c(h,{key:0,modelValue:o.value,"onUpdate:modelValue":s[0]||(s[0]=u=>o.value=u),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?(r(),c(_,{key:1,class:"px-6 pb-6 pt-0"},{default:t(()=>[l(k,{color:"primary",variant:"tonal",onClick:b},{default:t(()=>[p(d(e.$t("close")),1)]),_:1})]),_:1})):(r(),c(_,{key:0,class:"pa-6 pt-4"},{default:t(()=>[l(U),l(k,{variant:"text",onClick:b},{default:t(()=>[p(d(e.$t("cancel")),1)]),_:1}),l(k,{color:"primary",variant:"flat",loading:f.value,disabled:!o.value,onClick:g},{default:t(()=>[p(d(e.$t("create")),1)]),_:1},8,["loading","disabled"])]),_:1}))]),_:1})]),_:1},8,["model-value"]))}});export{J as _};
