import{aP as b,y as B,aw as C,r as I,c5 as N,aX as P,L as y}from"./index-Dqv5IkpS.js";import{r as E,Z as M,K as O,ap as S,S as i,L as R,M as l,V as X,P as v,a7 as k,T as h,X as T,W as V,b as x}from"./vendor-bSWkQivH.js";function $(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:p}=b(),a=I(),e=E(),o=B(),{t:r}=M();async function t(L){e.value="loading";try{const{error:u,data:m}=await C("/connect/token").post(new URLSearchParams({grant_type:"impersonate",scope:"offline_access",user_id:L}),"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:w,errors:A}=m.value;d&&f&&_&&g?(c(d),s(_),n(f),p(g),e.value="success",o.success({text:r("pages.account.impersonate.success")}),setTimeout(()=>{a.emit(N,null,P.ALL)},1e3)):(o.error({text:r("pages.account.impersonate.error")}),y.error(t.name,w,A),e.value="error")}}catch(u){o.error({text:r("pages.account.impersonate.error")}),y.error(t.name,u),e.value="error"}}return{impersonate:t,status:e}}const F=O({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:p}=$();return S(()=>{p(c.userId)}),(a,e)=>{const o=i("VcTypography"),r=i("VcLoaderOverlay"),t=i("VcAlert");return l(),R("div",null,[X(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{F as default};
//# sourceMappingURL=impersonate-CxY2XYKr.js.map
