import{cd as B,v as C,a$ as I,n as N,ce as R,cf as b,L as v}from"./index-BGo1APpE.js";import{r as E,aj as O,F as P,aR as $,P as i,Q as j,R as l,X as F,_ as y,W as k,a1 as h,a2 as T,a0 as V,e as x}from"./vendor-sJIIH5Cr.js";function M(){const{setTokenType:n,setAccessToken:c,setExpiresAt:s,setRefreshToken:p}=B(),a=N(),e=E(),o=C(),{t}=O();async function r(A){e.value="loading";try{const{error:u,data:m}=await I("/connect/token").post(new URLSearchParams({grant_type:"impersonate",scope:"offline_access",user_id:A}),"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:L,errors:w}=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(R,null,b.ALL)},1e3)):(o.error({text:t("pages.account.impersonate.error")}),v.error(r.name,L,w),e.value="error")}}catch(u){o.error({text:t("pages.account.impersonate.error")}),v.error(r.name,u),e.value="error"}}return{impersonate:r,status:e}}const Q=P({__name:"impersonate",props:{userId:{}},setup(n){const c=n,{status:s,impersonate:p}=M();return $(()=>{p(c.userId)}),(a,e)=>{const o=i("VcTypography"),t=i("VcLoaderOverlay"),r=i("VcAlert");return l(),j("div",null,[F(o,{tag:"h1"},{default:h(()=>[T(V(a.$t("pages.account.impersonate.title")),1)]),_:1}),x(s)==="loading"?(l(),y(t,{key:0,"no-bg":""})):k("",!0),x(s)==="error"?(l(),y(r,{key:1,color:"danger",class:"mt-4",icon:""},{default:h(()=>[T(V(a.$t("pages.account.impersonate.error")),1)]),_:1})):k("",!0)])}}});export{Q as default};
//# sourceMappingURL=impersonate-CmJ7vZSp.js.map
