import{az as w,b8 as $,J as v,L as x,aF as i,aG as r,aH as t,o as l,bg as B,bF as F,r as I,aV as m,aW as d,cw as N,aP as A,c8 as h,ah as D,E as U,cm as _,cn as z,M as k,bf as E,bc as S,bm as c,cA as q}from"./index-D2rF_80D.js";const G={class:"text-body-2 mb-2 text-grey-darken-1"},J=w({__name:"CreateTokenDialog",props:{modelValue:{type:Boolean},userId:{}},emits:["update:modelValue","created"],setup(V,{emit:C}){const{t:s}=$(),y=V,p=C,f=v(!1),o=v(""),a=v(""),b=()=>{o.value="",a.value="",requestAnimationFrame(()=>{p("update:modelValue",!1)})},g=async()=>{f.value=!0;try{const e=await S.createToken(o.value,y.userId);e?(c.success(s("auth.token_created")),a.value=e,p("created")):c.error(s("auth.token_create_failed"))}catch(e){c.error(e.message||s("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 q(a.value)?c.success(s("auth.token_copied")):c.error(s("auth.token_copy_failed"))};return(e,n)=>(r(),i(E,{"model-value":V.modelValue,"max-width":"500","onUpdate:modelValue":n[2]||(n[2]=u=>p("update:modelValue",u))},{default:t(()=>[l(B,null,{default:t(()=>[l(F,{class:I(["text-h6 pa-6",{"pb-0":a.value,"pb-4":!a.value}])},{default:t(()=>[m(d(a.value?o.value:e.$t("auth.create_token")),1)]),_:1},8,["class"]),l(N,{class:"px-6 pb-2"},{default:t(()=>[a.value?(r(),A(D,{key:1},[U("p",G,d(e.$t("auth.copy_new_token_hint")),1),l(h,{modelValue:a.value,"onUpdate:modelValue":n[1]||(n[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(),i(h,{key:0,modelValue:o.value,"onUpdate:modelValue":n[0]||(n[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(),i(_,{key:1,class:"px-6 pb-6 pt-0"},{default:t(()=>[l(k,{color:"primary",variant:"tonal",onClick:b},{default:t(()=>[m(d(e.$t("close")),1)]),_:1})]),_:1})):(r(),i(_,{key:0,class:"pa-6 pt-4"},{default:t(()=>[l(z),l(k,{variant:"text",onClick:b},{default:t(()=>[m(d(e.$t("cancel")),1)]),_:1}),l(k,{color:"primary",variant:"flat",loading:f.value,disabled:!o.value,onClick:g},{default:t(()=>[m(d(e.$t("create")),1)]),_:1},8,["loading","disabled"])]),_:1}))]),_:1})]),_:1},8,["model-value"]))}});export{J as _};
