#include "main.h" 
#include "terminal.h"
#include "menu.h"
#include <cstring>

#define HORIZONTAL 0
#define VERTICAL 1
#define LINK_MAIN 1

int main(int argv, char ** argc)
{
	//Variables
	int xMax, yMax = 0; 
	char pressed; 
	
	Item devices[3] = { 
		Item("Stm32f042",'q'),
		Item("Stm32g441",'w'),
		Item("Raspberry",'e'),
	}; 

	Item mainMenu[3] = { 
		Item("Devices",'d'),
		Item("Configrations",'c'),
		Item("Help",'h'),
	}; 
	
	Terminal terminal = Terminal();
	Menu menu = Menu("Main", mainMenu, 0, 0, LINK_MAIN, HORIZONTAL, 5,5,3); 
	Menu menuDevices = Menu("Devices", devices, 1, 1, LINK_MAIN, VERTICAL, 5,5,3); 

	init_pair(2, COLOR_CYAN, COLOR_BLACK);
	xMax = terminal.getXMax();	
	yMax = terminal.getYMax();	

	attron(COLOR_PAIR(2));
	terminal.draw(1,yMax-2,"Press x to Exit");
	attroff(COLOR_PAIR(2));	
	
	terminal.endDraw(); 	

	while(pressed != 'x')
	{
		menu.printMenu();
		pressed = terminal.getKey();	
		menu.handleTrigger(pressed);
		if(menu.isActive())
		{
			terminal.draw(1,yMax-4,"Main Menu Is   Active");
			terminal.endDraw();		
		}
		else
		{
			terminal.draw(1,yMax-4,"Main Menu is Inactive");
		}
		
		terminal.endDraw();		
	}
	
	terminal.endDraw(); 	
	terminal.draw(1,yMax-3,"The window should be deleted");
	terminal.tearDown();
		
	return 0;
}
