/**
 * @since Thu Dec 07 2017
 * @author Charles Gouldmann - Klean
 */


import { Component, OnInit } from '@angular/core';

import { TransferState, makeStateKey } from '@angular/platform-browser'

// Services
import { MenuService }      from '@k-services/svc.menu'
import { HelperService }    from '@k-services/svc.helper'

// Services
import { MenuInlinePrimaryComponent } from '@k-core/modules/menu/components/inline/primary/cmp.menu-inline-primary'
import { Router } from '@angular/router';
import { AppHelper } from '@k-settings/app-helper';
import { UserService } from '@k-core/modules/User/services/svc.user';

@Component({
	selector: 'menu-inline-primary',
	templateUrl: './tpl.menu-inline-primary.pug',
	styleUrls: ['./sty.menu-inline-primary.scss']
})
export class MenuInlinePrimaryKidComponent extends MenuInlinePrimaryComponent implements OnInit {

	constructor(
		_menuService: MenuService,
		_helper: HelperService,
		state: TransferState,
		_user: UserService,
		private _router: Router
	) {
		super(_menuService, _helper, state, _user)
	}

	/**
	 * Fix for Angular `component of null` error, if redirecting to its own path, I've made a simple checker that sends routerlinks to
	 * AppHelper off to a blank page, before spawning in on the correct page. This gives an awkward reload, but the fix doesn't seem to
	 * be implemented before 7.x.x. The core issue stems from us using a catch-all filter, but to fix that, would require alot more work
	 * than adding a hack like this, and this is still mostly performant, although there will be a request to the CMS page "blank" on
	 * first request, after which, this page will be cached.
	 * 
	 * @param string 
	 */
	redirector(string) {
		
		if(string.includes(AppHelper.configurator)) {

			this._router.navigate(['/blank'])
			setTimeout(() => {
				this._router.navigate([string])
			}, 1)
		}
	}
}
