import { Template } from 'meteor/templating';
import './Admin.html';

Template.Admin.toggleMenu = function($sidebar) {
	let $sidebars = $('nav.leftSidebarContainer');
	
	for(let i = 0; i < $sidebars.length; i++) {
		if($sidebars[i] == $sidebar[0]) {
			$sidebar.toggleClass('menuShow');
		}
		else {
			$($sidebars[i]).toggleClass('menuHide');
		}
	}
};

Template.Admin.events({
	"click .signOut": function(event, template) {
		AccountsTemplates.logout();
	},
	// General Menu
	"click .generalSidebar .leftSidebarMenuButton": function(event, template) {
		event.preventDefault();
		Template.Admin.toggleMenu($('nav.generalSidebar'));
	},
	"click .generalSidebar .leftSidebar a": function(event, template) {
		Template.Admin.toggleMenu($('nav.generalSidebar'));
	},
	"click .generalSidebar .leftSidebar a .subMenu": function(event, template) {
		Template.Admin.toggleMenu($('nav.generalSidebar'));
	},
	// Graphs Menu
	"click .graphsSidebar .leftSidebarMenuButton": function(event, template) {
		event.preventDefault();
		Template.Admin.toggleMenu($('nav.graphsSidebar'));
	},
	"click .graphsSidebar .leftSidebar a": function(event, template) {
		Template.Admin.toggleMenu($('nav.graphsSidebar'));
	},
	"click .graphsSidebar .leftSidebar a .subMenu": function(event, template) {
		Template.Admin.toggleMenu($('nav.graphsSidebar'));
	},
	// Settings Menu
	"click .settingsSidebar .leftSidebarMenuButton": function(event, template) {
		event.preventDefault();
		Template.Admin.toggleMenu($('nav.settingsSidebar'));
	},
	"click .settingsSidebar .leftSidebar a": function(event, template) {
		Template.Admin.toggleMenu($('nav.settingsSidebar'));
	},
	"click .settingsSidebar .leftSidebar a .subMenu": function(event, template) {
		Template.Admin.toggleMenu($('nav.settingsSidebar'));
	}
});