import type { Url } from '@tinkoff/url' ; import type { Router , NavigationRoute , NavigateOptions , UpdateCurrentRouteOptions , HistoryOptions , } from '@tinkoff/router' ; import type { COMPONENT_REGISTRY_TOKEN } from '@tramvai/tokens-common' ; import type { PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router' ; import { isFileSystemPageComponent } from '@tramvai/experiments' ; type PageServiceInterface = typeof PAGE_SERVICE_TOKEN ; export class PageService implements PageServiceInterface { private router : Router ; private componentRegistry : typeof COMPONENT_REGISTRY_TOKEN ; constructor ( { router , componentRegistry } ) { this . router = router ; this . componentRegistry = componentRegistry ; } getCurrentRoute ( ) { return this . router . getCurrentRoute ( ) ; } getCurrentUrl ( ) { return this . router . getCurrentUrl ( ) ; } getConfig ( ) { return this . getCurrentRoute ( ) ?. config ?? { } ; } getContent ( ) { return this . getConfig ( ) . content ?? { } ; } getMeta ( ) { return this . getConfig ( ) . meta ?? { } ; } navigate ( options ) { return this . router . navigate ( options ) ; } updateCurrentRoute ( options ) { return this . router . updateCurrentRoute ( options ) ; } back ( options ? ) { return this . router . back ( options ) ; } forward ( ) { return this . router . forward ( ) ; } go ( to , options ? ) { return this . router . go ( to , options ) ; } addComponent ( name , component ) { const group = this . getComponentsGroupName ( ) ; return this . componentRegistry . add ( name , component , group ) ; } getComponent ( name ) { const group = this . getComponentsGroupName ( ) ; return this . componentRegistry . get ( name , group ) ; } resolveComponentFromConfig ( property ) { const configName = `${ property }Component` ; const defaultComponent = `${ property }Default` ; const componentName = this . getConfig ( ) [ configName ] ?? defaultComponent ; return this . getComponent ( componentName ) || this . getComponent ( defaultComponent ) ; } private getComponentsGroupName ( ) { const { bundle , pageComponent } = this . getConfig ( ) ; const group = isFileSystemPageComponent ( pageComponent ) ? pageComponent : bundle ; return group ; } }