import{o as S,p as v,q as P,t as m}from"./chunk-2YE7XEKS.js";import{I as r,Ld as g,R as e,_ as u,ba as p,ca as f,da as s,k as h,ka as d,pa as a,r as l,w as n,y as c}from"./chunk-UNHECMG2.js";var N=(()=>{class o{constructor(){this.router=a(m),this.viewportScroller=a(g),this.scrollPositions={},this.previousRoute=null,this.currentRoute=this.getInitialActivatedRouteSnapshot(),this.currentScrollPosition=[0,0],this.destroy$=new h,this.activationEnd$=this.router.events.pipe(r($)),this.navigationEnd$=this.router.events.pipe(r(y)),this.navigationStart$=this.router.events.pipe(r(R)),this.scrollPosition$=this.navigationStart$.pipe(n(this.getScrollPosition.bind(this))),this.route$=this.activationEnd$.pipe(e(1)).pipe(c(t=>[l(t),this.navigationEnd$.pipe(p(()=>this.activationEnd$.pipe(e(1))))]),f(),n(t=>t.snapshot),u(1)),this.scrollPosition$.pipe(s(this.destroy$)).subscribe(t=>this.currentScrollPosition=t),this.route$.pipe(s(this.destroy$)).subscribe(t=>{this.previousRoute=this.currentRoute,this.currentRoute=t})}ngOnDestroy(){this.destroy$.next()}restore(){if(!this.currentRoute||!this.requiresStoring(this.currentRoute))return;if(this.previousRoute&&this.shouldStoreFor(this.currentRoute,this.previousRoute)){let i=this.getPath(this.currentRoute);this.scrollToPosition(this.scrollPositions[i]||[0,0])}let t=this.currentRoute;this.route$.pipe(e(1),s(this.destroy$),r(i=>this.shouldStoreFor(t,i))).subscribe(()=>{let i=this.getPath(t);this.scrollPositions[i]=this.currentScrollPosition})}getScrollPosition(){return this.viewportScroller.getScrollPosition()}scrollToPosition(t){this.viewportScroller.scrollToPosition(t)}getPath(t){return t?"/"+t.pathFromRoot.map(i=>i.routeConfig&&i.routeConfig.path).filter(i=>i).join("/"):"/"}requiresStoring(t){return!!(t&&t.routeConfig&&t.routeConfig.data&&Array.isArray(t.routeConfig.data.restoreScrollPositionFrom)&&t.routeConfig.data.restoreScrollPositionFrom.length>0)}shouldStoreFor(t,i){return(t&&t.routeConfig&&t.routeConfig.data&&Array.isArray(t.routeConfig.data.restoreScrollPositionFrom)?t.routeConfig.data.restoreScrollPositionFrom:[]).includes(this.getPath(i))}getInitialActivatedRouteSnapshot(){let t=this.router.routerState.snapshot.root;for(;t.firstChild;)t=t.firstChild;return t}static{this.\u0275fac=function(i){return new(i||o)}}static{this.\u0275prov=d({token:o,factory:o.\u0275fac,providedIn:"root"})}}return o})();function $(o){return o instanceof P}function R(o){return o instanceof S}function y(o){return o instanceof v}export{N as a};
