import{b as A}from"./chunk-F7TB6D2I.js";import{c as I}from"./chunk-EMAOG2GJ.js";import{a as y,c as k}from"./chunk-BE77QZG7.js";import{C as o,D as m,N as l,R as a,X as r,d as p,i as h,l as u,p as g,ta as i,y as d}from"./chunk-5ONOZUNN.js";var c=class s{#i=i(null);#n=window.self!==window.top;#e=i(this.#n);relayIsEnabled=this.#e.asReadonly();config=this.#i.asReadonly();configLoaded=this.#n?new h:null;isLoading=i(this.#n);parentIframeListner=null;parentOrigin="*";fetchConfig(){this.#t(),this.#n&&(this.#e.set(!0),this.parentIframeListner=new AbortController,this.#s("connected"),window.addEventListener("message",e=>{if(e.data.startsWith("access:")){let t=e.data.replace("access:",""),n=JSON.parse(t);if(!n?.accessToken||!n?.clientId){this.#s("error:invalid-config"),this.#e.set(!1);return}if(typeof n.clientId!="string"){this.#s("error:invalid-config"),this.#e.set(!1);return}if(typeof n.accessToken!="string"){this.#s("error:invalid-config"),this.#e.set(!1);return}console.info("postMessage config set"),this.#i.set(n),this.configLoaded?.next(!0),this.isLoading.set(!1),this.#s("handshake-complete")}},{signal:this.parentIframeListner.signal}))}#s(e){window.parent.postMessage(e,"*")}#t(){this.parentIframeListner&&(this.parentIframeListner.abort(),this.parentIframeListner=null)}setConfig(e){this.#i.set(e)}clearConfig(){this.#i.set(null)}static \u0275fac=function(t){return new(t||s)};static \u0275prov=a({token:s,factory:s.\u0275fac,providedIn:"root"})};var f="PROXY_AUTHED_FAKE_TOKEN",b=class s{#i=r(I);#n=r(k);#e=r(A);#s=r(c);#t=i(null);#r=i(!1);token=this.#t.asReadonly();isLoggingOut=this.#r.asReadonly();login(e){return this.#e.postApiV1AuthLogin({requestBody:{Password:e,RememberMe:!0}}).pipe(o(1),l(t=>t.AccessToken&&this.#t.set(t.AccessToken)))}refreshToken(){return this.#s.relayIsEnabled()?(this.#t.set(f),new p(e=>{e.next({AccessToken:f}),e.complete()})):this.#e.postApiV1AuthRefresh().pipe(o(1),l(e=>e.AccessToken&&this.#t.set(e.AccessToken)))}checkProxyAuthed(){let e=new y({"custom-proxy-check":"true"});return this.#n.get("/api/v1/systeminfo",{headers:e}).pipe(g(()=>(this.#t.set(f),!0)),d(()=>u(!1)))}logout(){this.#r.set(!0),this.#e.postApiV1AuthRefreshLogout().pipe(o(1),m(()=>{this.#r.set(!1),this.#t.set(null),this.#i.navigate(["/login"])})).subscribe()}static \u0275fac=function(t){return new(t||s)};static \u0275prov=a({token:s,factory:s.\u0275fac,providedIn:"root"})};export{c as a,f as b,b as c};
