import{ch as b,x as B,b3 as C,q as E,ci as I,cj as N,L as y}from"./index-PU-0vjEQ.js";import{r as O,ai as P,F as R,aE as j,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-BmRNukEL.js";function S(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:i}=b(),a=E(),e=O(),o=B(),{t}=P();async function r(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),i(g),e.value="success",o.success({text:t("pages.account.impersonate.success")}),setTimeout(()=>{a.emit(I,null,N.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 D=R({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:i}=S();return j(()=>{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{D as default};
//# sourceMappingURL=impersonate-B2e1Iv3n.js.map
