#include "main.h" 
#ifndef _MENU_H_
#define _MENU_H_ 

class Menu
{
	public:
		Menu(std::string name, int menuNo, int direction, char trigger, std::string *items, int itemCount);
		~Menu();
		void draw();
		void nextItem();
		void prevItem(); 
		int getSelectedItem(); 
		void setSelectedItem();
		void setPosX(int x); 
		void setPosY(int y);
		int getPosX(); 
		int getPosY();
		void setMenuBarBegX(int x); // it must be indicated from menu bar so that we can print the box on the right place
		void setMenuBarBegY(int y); // it must be indicated from menu bar so that we can print the box on the right place
		void setMenuBarSizeX(int x); // it must be indicated from menu bar so that we can print the box on the right place
		std::string getName();
		int getNameLenght();
		int getLongestItemLenght();
		char getTrigger();
		void drawBox(); 
		void drawItems();
		int getBoxBegY();
		int getBoxBegX();
		void eraseBox();
		bool isBoxCreated();
	
	private:
		WINDOW * menuItemsWin;
		std::string name;
		std::string *items; 
		int menuNo, currPos, direction= 0;
		int posX, xSize, menuBarBegX = 0;
		int posY, ySize, menuBarBegY = 0;	
		int menuBarSizeX = 0; 
		int selected_item = 0;
		int itemCount = 0; 
		int itemLenght = 0;
		char trigger;
		bool boxIsCreated = false; 
};

Menu::Menu(std::string name, int menuNo, int direction, char trigger, std::string *items, int itemCount)
{
	this->name = name;				//Name of the menu 
	this->menuNo = menuNo;			//No of the menu so that we can index it with the menuBar.handdleTrigger option. 
	this->direction = direction;	//Direction o the menu Bar Horizontal = 0, vertical = 1 
	this->trigger = trigger;		//The trigger for the given menu 
	this->items = items;			//Items present in thei menu
	this->itemCount = itemCount;	//Nouber of item present in this menu
	
	//To be sure
	xSize = 0; 
	ySize = 0;
	selected_item = -1; // No menus are selected a the beggining
	boxIsCreated = false; 
	
	// Vertical Alignment	
	if(direction)
	{	
	}
	else // Horizontal Alignment -> The Deffault 
	{
	}	
	
}

Menu::~Menu() 
{
	werase(menuItemsWin);
	wclear(menuItemsWin);
	wrefresh(menuItemsWin);
	boxIsCreated = false; 
}

void Menu::eraseBox()
{
	werase(menuItemsWin);
	wclear(menuItemsWin);
	wrefresh(menuItemsWin);
	boxIsCreated = false; 
}

void Menu::setPosX(int x)
{
	this->posX = x;	
}
 
void Menu::setPosY(int y)
{
	this->posY = y;	
}

int Menu::getPosX()
{
	return posX;	
}
 
int Menu::getPosY()
{
	return posY;	
}

void Menu::setMenuBarBegX(int x)
{
	this->menuBarBegX = x;
}

void Menu::setMenuBarBegY(int y)
{
	this->menuBarBegY = y;
}

void Menu::setMenuBarSizeX(int x) 
{
	this->menuBarSizeX = x;
}
std::string Menu::getName()
{
	return name;
}

int Menu::getNameLenght()
{
	return name.length();
}

int Menu::getLongestItemLenght()
{
	return xSize;
}

char Menu::getTrigger()
{
	return trigger;
}

int Menu::getBoxBegX()
{
	// Vertical Alignment	
	if(direction)
	{	
		return menuBarSizeX+posX+menuBarBegX-1;
	}
	else // Horizontal Alignment -> The Deffault 
	{
		return menuBarSizeX+posX+menuBarBegX-1;
	}	
	return -1; 
}

int Menu::getBoxBegY()
{
	// Vertical Alignment	
	if(direction)
	{	
		return posY+menuBarBegY-1;
	}
	else // Horizontal Alignment -> The Deffault 
	{
		return posY+menuBarBegY-1;
	}	
	return -1; 
}


bool Menu::isBoxCreated()
{
	return boxIsCreated;
}


void Menu::drawBox()
{
	// Creates a box with caclulated dimention xSize & ySize and user given position
	/*menuItemsWin = newwin(20, 20, getBoxBegY(), getBoxBegX()); 
	boxIsCreated = true;
	box(menuItemsWin ,0,0);	//Here we can define other cahr insterad of 0,0
	mvwprintw(menuItemsWin,1,1,"PosY:%d PosX:%d",getBoxBegY(), getBoxBegX());
	wrefresh(menuItemsWin);	//Refresh so that we can see it
*/
	}

void Menu::drawItems()
{

}

#endif
