import { Injectable } from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {debug} from '../utility';

@Injectable({
    providedIn: 'root'
})
export class NavigationService {
    protected refreshCount = 0;
    public readonly sidebarRefresh$: BehaviorSubject<[number, boolean]> = new BehaviorSubject<[number, boolean]>([this.refreshCount, true]);
    public readonly navigationRequest$: BehaviorSubject<string> = new BehaviorSubject<string>('');

    requestSidebarRefresh({ quiet = false }) {
        this.refreshCount += 1;
        this.sidebarRefresh$.next([this.refreshCount, quiet]);
    }

    requestNavigation(pageId: string) {
        debug('Requesting page navigation:', pageId);
        debug('Page navigation trace', new Error());

        this.navigationRequest$.next(pageId);
    }
}
