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