import{cl as b,b2 as B,x as C,q as I,cm as N,cn as E,L as y}from"./index-8PssKxKU.js";import{ai as O,r as P,F as R,aD as D,P as u,Q as F,R as l,X as M,_ as v,W as k,a1 as h,a2 as T,a0 as x,e as V}from"./vendor-DWvj1jit.js";function S(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:i}=b(),a=I(),e=P(),o=C(),{t}=O();async function r(A){e.value="loading";try{const{error:p,data:m}=await B("/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),i(g),e.value="success",o.success({text:t("pages.account.impersonate.success")}),setTimeout(()=>{a.emit(N,null,E.ALL)},1e3)):(o.error({text:t("pages.account.impersonate.error")}),y.error(r.name,L,w),e.value="error")}}catch(p){o.error({text:t("pages.account.impersonate.error")}),y.error(r.name,p),e.value="error"}}return{impersonate:r,status:e}}const q=R({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:i}=S();return D(()=>{i(c.userId)}),(a,e)=>{const o=u("VcTypography"),t=u("VcLoaderOverlay"),r=u("VcAlert");return l(),F("div",null,[M(o,{tag:"h1"},{default:h(()=>[T(x(a.$t("pages.account.impersonate.title")),1)]),_:1}),V(s)==="loading"?(l(),v(t,{key:0,"no-bg":""})):k("",!0),V(s)==="error"?(l(),v(r,{key:1,color:"danger",class:"mt-4",icon:""},{default:h(()=>[T(x(a.$t("pages.account.impersonate.error")),1)]),_:1})):k("",!0)])}}});export{q as default};
//# sourceMappingURL=impersonate-CFIz7LwZ.js.map
