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