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

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

import { AppHelper }		from '@k-settings/app-helper'
import { store } 	from '@k-settings/app-setup.js'

@Component({
	selector: 'menu-cover',
	templateUrl: './tpl.menu-cover.pug',
	styleUrls: ['./sty.menu-cover.scss']
})
export class MenuCoverComponent implements OnInit {

	constructor(
		private _menuService: MenuService,
		private _helper: HelperService
	) { 
		_menuService.state$.subscribe((result) => {
			this.state = result;
		})
	}

	// Vars
	navigation 			= []
	categories 			= []
	categoryLabel		= AppHelper.categories
	menuName 			= 'primary-' + store
	state: boolean
	secondaryNav: any


	// Events
	ngOnInit() {
		this.getMenuAndCategories();
		this.getSecondaryNav()
	}

	// Functions

	/**
	 * Call menu service close function
	 */
	closeMenu() {
		this._menuService.close();
	}


	/**
	 * Get the nav items and categories from menuservice
	 */
	getMenuAndCategories() {

		this._menuService.getMenu(this.menuName).then((result) => {
			if(result) {
				this.navigation = result
			}
		});
			

		// Get categories 
		this._menuService.getMenuCategories().then(result => {
			this.categories = result
		})
	}

	/**
	 * Get the secondary header navs
	 */
	getSecondaryNav() {
		this._menuService.getMenu('header-secondary').then((result) => {
            this.secondaryNav = result
        })
	}

}