//File Main.cpp - contains main function

#include <iostream>
#include <iomanip>
#include <list>

using namespace std;

#include "Recipe.h"
#include "Parser.h"
#include "MenuFunctions.h"

void main() {
	string xmlStartTag = "<xml>";
    string xmlEndTag = "</xml>";
	list<Recipe> recipes;
	string spiceSelected = "any";
	string ratingSelected = "any";
	string fileName;
	bool isFileChanged = false;
	int userSelection = 0;
	
	cout << "Welcome to the Spice of Life Browser!\nEnter name of file (ex. aLaCarteData.txt): ";
	cin >> fileName;
	
	cout << "Working... " << endl;
	Parser parser(fileName);

	cout << "... " << parser.getRecipes().size() << " recipes loaded.";
	recipes = parser.getRecipes();
	
	while(userSelection != 8){
		cout << "\n\nMenu Options:" << endl;
		cout << "\t1. Find Contributor" << endl;
		cout << "\t2. Select Spice" << endl;
		cout << "\t3. Select Rating" << endl;
		cout << "\t4. List Recipe Names" << endl;
		cout << "\t5. Display Recipe" << endl;
		cout << "\t6. Enter New Recipe" << endl;
		cout << "\t7. Save" << endl;
		cout << "\t8. Exit" << endl;
		
		cout << "Enter selection (ex. 1): " << endl;
		cin >> userSelection;
		while(getchar()!='\n');
		cout << endl;
		
		switch (userSelection){
			case 1:
				FindContributor(recipes);
				break;
			case 2:
				spiceSelected = SelectSpice();
				break;
			case 3:
				ratingSelected = SelectRating();
				break;
			case 4:
				ListRecipeNames(recipes, spiceSelected, ratingSelected);
				break;
			case 5:
				DisplayRecipe(recipes);
				break;
			case 6:
				EnterNewRecipe(recipes);
				isFileChanged = true;
				break;
			case 7:
				Save(recipes, fileName, xmlStartTag, xmlEndTag);
				break;
			case 8:
				if(isFileChanged)
					SaveAndExit(recipes, fileName, xmlStartTag, xmlEndTag);
			default:
				break;
		}
	}
	cout << "\n\n";
}
//end of Main.cpp