
#include "book.h"

// Prototypes

int showMenu(book myBook);

enum addressOptions
{
	READ,
	WRITE,
	DISPLAY,
	ADD,
	SORT,
	FIND,
	EDIT,
	DELETE,
	QUIT
};

int main ()
{
	book myBook;
	int opt;

	while ( ( opt = showMenu(myBook) ) != QUIT )
	{
		switch (opt)
		{
			case READ:
				myBook.readBook();
				break;

			case WRITE:
				myBook.writeBook();
				break;

			case ADD:
				myBook.addContact();
				break;

			case DISPLAY:
				myBook.displayBook();
				break;

			case SORT:
				myBook.sortBook();
				break;

			case FIND:
				myBook.findContact();
				break;

			case EDIT:
				myBook.editContact( myBook.findContact() );
				break;

			case DELETE:
				myBook.deleteContact( myBook.findContact() );
		}


	}
	return (0);

}

int showMenu(book myBook)
{
	int option;
	char junk[256];

	cout << "Welcome to the Address book" << endl
		<< endl
		<< "There are currently " << myBook.getListingCount() << " entries." << endl
		<< "The book is currently sorted by: " << fieldNames[myBook.getSortType()] << endl 
		<< endl
		<< "0. Read address book from a file." << endl
		<< "1. Write address book to a file." << endl
		<< "2. Display current address book." << endl
		<< "3. Add a contact to the address book." << endl
		<< "4. Sort the records in the book." << endl
		<< "5. Find person in address book." << endl
		<< "6. Edit person in address book." << endl
		<< "7. Delete person in address book." << endl
		<< "7. " << endl
		<< endl
		<< ". Quit" << endl
		<< endl
		<< "Please choose and option: ";

	cin >> option;
	cin.getline(junk, 256);

	cout << endl;

	return (option);

}

