import { Inject , Injectable , InjectionToken } from '@angular/core' ; import { Router , RoutesRecognized } from '@angular/router' ; import { Platform } from '@angular/cdk/platform' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { filter } from 'rxjs/operators' ; import * as _ from 'lodash' ; export const FUSE_CONFIG = new InjectionToken ( 'fuseCustomConfig' ) ; @ Injectable ( { providedIn : 'root' } ) export class FuseConfigService { private _configSubject : BehaviorSubject < any > ; private readonly _defaultConfig : any ; param { Platform } _platform param { Router } _router param _config constructor ( private _platform , private _router , @ Inject ( FUSE_CONFIG ) private _config ) { this . _defaultConfig = _config ; this . _init ( ) ; } /**
     * Set and get the config
     */ set config ( value ) { let config = this . _configSubject . getValue ( ) ; config = _ . merge ( { } , config , value ) ; this . _configSubject . next ( config ) ; } get config ( ) : any | Observable < any > { return this . _configSubject . asObservable ( ) ; } returns { any } get defaultConfig ( ) : any { return this . _defaultConfig ; } private private _init ( ) { /**
         * Disable custom scrollbars if browser is mobile
         */ if ( this . _platform . ANDROID || this . _platform . IOS ) { this . _defaultConfig . customScrollbars = false ; } this . _configSubject = new BehaviorSubject ( _ . cloneDeep ( this . _defaultConfig ) ) ; this . _router . events . pipe ( filter ( event => event instanceof RoutesRecognized ) ) . subscribe ( ( ) => { if ( ! _ . isEqual ( this . _configSubject . getValue ( ) . layout , this . _defaultConfig . layout ) ) { const config = _ . cloneDeep ( this . _configSubject . getValue ( ) ) ; config . layout = _ . cloneDeep ( this . _defaultConfig . layout ) ; this . _configSubject . next ( config ) ; } } ) ; } param value param { { emitEvent : boolean } } opts setConfig ( value , opts = { emitEvent : true } ) { let config = this . _configSubject . getValue ( ) ; config = _ . merge ( { } , config , value ) ; if ( opts . emitEvent === true ) { this . _configSubject . next ( config ) ; } } returns { Observable < any > } getConfig ( ) { return this . _configSubject . asObservable ( ) ; } /**
     * Reset to the default config
     */ resetToDefaults ( ) { this . _configSubject . next ( _ . cloneDeep ( this . _defaultConfig ) ) ; } }