import{bH as N,w as b,aR as B,o as C,cL as I,bN as M,L as y}from"./index-GCDRvGOr.js";import{r as O,$ as R,M as E,aM as $,U as i,N as P,O as l,X as S,R as v,a8 as k,V as h,Z as T,Y as V,e as x}from"./vendor-CsGITfgk.js";function U(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:p}=N(),a=C(),e=O(),o=b(),{t}=R();async function r(L){e.value="loading";try{const{error:u,data:m}=await B("/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:t("pages.account.impersonate.success")}),setTimeout(()=>{a.emit(I,null,M.ALL)},1e3)):(o.error({text:t("pages.account.impersonate.error")}),y.error(r.name,w,A),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 F=E({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:p}=U();return $(()=>{p(c.userId)}),(a,e)=>{const o=i("VcTypography"),t=i("VcLoaderOverlay"),r=i("VcAlert");return l(),P("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{F as default};
//# sourceMappingURL=impersonate-DLGdGeW6.js.map
