import{by as b,w as N,aT as B,o as C,cO as E,bE as I,L as y}from"./index-BZco6cza.js";import{r as O,ag as P,F as R,aN as F,P as i,Q as M,R as l,X as S,_ as v,W as k,a1 as h,a2 as T,a0 as V,e as x}from"./vendor-DJC-2VPc.js";function $(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:p}=b(),a=C(),e=O(),o=N(),{t}=P();async function r(w){e.value="loading";try{const{error:u,data:m}=await B("/connect/token").post(new URLSearchParams({grant_type:"impersonate",scope:"offline_access",user_id:w}),"application/x-www-form-urlencoded").json();if(!m.value||u.value)e.value="error";else{const{access_token:d,token_type:f,expires_in:_,refresh_token:g,error:A,errors:L}=m.value;d&&f&&_&&g?(c(d),s(_),n(f),p(g),e.value="success",o.success({text:t("pages.account.impersonate.success")}),setTimeout(()=>{a.emit(E,null,I.ALL)},1e3)):(o.error({text:t("pages.account.impersonate.error")}),y.error(r.name,A,L),e.value="error")}}catch(u){o.error({text:t("pages.account.impersonate.error")}),y.error(r.name,u),e.value="error"}}return{impersonate:r,status:e}}const Q=R({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:p}=$();return F(()=>{p(c.userId)}),(a,e)=>{const o=i("VcTypography"),t=i("VcLoaderOverlay"),r=i("VcAlert");return l(),M("div",null,[S(o,{tag:"h1"},{default:h(()=>[T(V(a.$t("pages.account.impersonate.title")),1)]),_:1}),x(s)==="loading"?(l(),v(t,{key:0,"no-bg":""})):k("",!0),x(s)==="error"?(l(),v(r,{key:1,color:"danger",class:"mt-4",icon:""},{default:h(()=>[T(V(a.$t("pages.account.impersonate.error")),1)]),_:1})):k("",!0)])}}});export{Q as default};
//# sourceMappingURL=impersonate-B1_Ty-h_.js.map
