
package gui

// buildProfileGui_Lifestyle.go implements the pages to build the lifestyle portion of a mate profile

import "fyne.io/fyne/v2"
import "fyne.io/fyne/v2/container"
import "fyne.io/fyne/v2/widget"
import "fyne.io/fyne/v2/dialog"
import "fyne.io/fyne/v2/theme"
import "fyne.io/fyne/v2/layout"

import "seekia/internal/allowedText"
import "seekia/internal/currencies"
import "seekia/internal/globalSettings"
import "seekia/internal/helpers"
import "seekia/internal/profiles/myLocalProfiles"

import "errors"

func setBuildMateProfileCategoryPage_Lifestyle(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfileCategoryPage_Lifestyle(window, previousPage)}

	title := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	hobbiesButton := widget.NewButton(translate("Hobbies"), func(){
			setBuildMateProfilePage_Hobbies(window, currentPage)
		})

	wealthButton := widget.NewButton(translate("Wealth"), func(){
			setBuildMateProfilePage_Wealth(window, currentPage)
		})

	jobButton := widget.NewButton(translate("Job"), func(){
			setBuildMateProfilePage_Job(window, currentPage)
		})

	dietButton := widget.NewButton(translate("Diet"), func(){
			setBuildMateProfilePage_Diet(window, currentPage)
		})

	fameButton := widget.NewButton(translate("Fame"), func(){
			setBuildMateProfilePage_Fame(window, currentPage)
		})

	drugsButton := widget.NewButton(translate("Drugs"), func(){
			setBuildMateProfilePage_Drugs(window, currentPage)
		})
	
	buttonsGrid := container.NewGridWithColumns(1, hobbiesButton, wealthButton, jobButton, dietButton, fameButton, drugsButton)

	buttonsGridCentered := getContainerCentered(buttonsGrid)

	buttonsGridPadded := container.NewPadded(buttonsGridCentered)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), buttonsGridPadded)
	
	setPageContent(page, window)
}


func setBuildMateProfilePage_Hobbies(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Hobbies(window, previousPage)}

	pageTitle := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate("Hobbies"))

	description1 := getLabelCentered(translate("Enter your hobbies."))
	description2 := getLabelCentered(translate("Hobbies are activities you enjoy."))

	currentHobbiesExist, currentHobbies, err := myLocalProfiles.GetProfileData("Mate", "Hobbies")
	if (err != nil) {
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	getMyCurrentHobbiesRow := func()(*fyne.Container, error){

		myHobbiesLabel := widget.NewLabel("My Hobbies:")

		if (currentHobbiesExist == false){

			noResponseLabel := getBoldItalicLabel("No Response")
			currentHobbiesRow := container.NewHBox(layout.NewSpacer(), myHobbiesLabel, noResponseLabel, layout.NewSpacer())

			return currentHobbiesRow, nil
		}

		isAllowed := allowedText.VerifyStringIsAllowed(currentHobbies)
		if (isAllowed == false){
			return nil, errors.New("My current mate hobbies is not allowed: " + currentHobbies)
		}

		if( len(currentHobbies) > 1000 ){
			return nil, errors.New("My current mate hobbies is too long: " + currentHobbies)
		}

		currentHobbiesTrimmed, _, err := helpers.TrimAndFlattenString(currentHobbies, 15)
		if (err != nil) { return nil, err }

		currentHobbiesLabel := getBoldLabel(currentHobbiesTrimmed)

		viewMyHobbiesButton := widget.NewButtonWithIcon("", theme.VisibilityIcon(), func(){
				setViewTextPage(window, "Viewing Hobbies", currentHobbies, false, currentPage)
			})

		currentHobbiesRow := container.NewHBox(layout.NewSpacer(), myHobbiesLabel, currentHobbiesLabel, viewMyHobbiesButton, layout.NewSpacer())

		return currentHobbiesRow, nil
	}

	currentHobbiesRow, err := getMyCurrentHobbiesRow()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	
	editButton := widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func(){
			setBuildMateProfilePage_EditHobbies(window, currentPage, currentPage)
		})

	noResponseButton := widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){
			if (currentHobbiesExist == false){
				return
			}
			setBuildMateProfilePage_DeleteHobbies(window, currentPage, currentPage)
		})

	buttonsGrid := getContainerCentered(container.NewGridWithColumns(1, editButton, noResponseButton))

	page := container.NewVBox(pageTitle, backButton, widget.NewSeparator(), pageSubtitle, widget.NewSeparator(), description1, description2, widget.NewSeparator(), currentHobbiesRow, widget.NewSeparator(), buttonsGrid)

	setPageContent(page, window)
}


func setBuildMateProfilePage_DeleteHobbies(window fyne.Window, previousPage func(), nextPage func()){

	title := getPageTitleCentered("Delete Hobbies")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Delete Hobbies?")
	
	description2 := getLabelCentered("Confirm to delete your hobbies?")

	confirmButton := getWidgetCentered(widget.NewButtonWithIcon("Delete", theme.DeleteIcon(), func(){
			myLocalProfiles.DeleteProfileData("Mate", "Hobbies")
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, confirmButton)

	setPageContent(page, window)
}


func setBuildMateProfilePage_EditHobbies(window fyne.Window, previousPage func(), nextPage func()){

	title := getPageTitleCentered("Edit Mate Hobbies")

	backButton := getBackButtonCentered(previousPage)

	hobbiesEntry := widget.NewMultiLineEntry()
	hobbiesEntry.Wrapping = 3

	//Outputs:
	//	-bool: Current hobbies exist
	//	-string: Current hobbies
	//	-error
	getCurrentHobbies := func()(bool, string, error){	

		exists, currentHobbies, err := myLocalProfiles.GetProfileData("Mate", "Hobbies")
		if (err != nil) { return false, "", err }
		if (exists == false){
			return false, "", nil
		}

		isAllowed := allowedText.VerifyStringIsAllowed(currentHobbies)
		if (isAllowed == false){
			return false, "", errors.New("My current mate hobbies is not allowed: " + currentHobbies)
		}

		if(len(currentHobbies) > 1000){
			return false, "", errors.New("My current mate hobbies is too long: " + currentHobbies)
		}

		return true, currentHobbies, nil
	}

	currentHobbiesExist, currentHobbies, err := getCurrentHobbies()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	if (currentHobbiesExist == false){
		hobbiesEntry.SetPlaceHolder("Enter your hobbies...")
	} else {
		hobbiesEntry.SetText(currentHobbies)
	}

	submitButton := getWidgetCentered(widget.NewButtonWithIcon(translate("Save"), theme.ConfirmIcon(), func(){

		newHobbies := hobbiesEntry.Text

		isAllowed := allowedText.VerifyStringIsAllowed(newHobbies)
		if (isAllowed == false){
			title := translate("Invalid Hobbies")
			dialogMessageA := getLabelCentered(translate("Your hobbies contain an invalid character."))
			dialogMessageB := getLabelCentered(translate("It must be encoded in UTF-8."))
			dialogContent := container.NewVBox(dialogMessageA, dialogMessageB)
			dialog.ShowCustom(title, translate("Close"), dialogContent, window)
			return
		}

		currentBytesLength := len(newHobbies)
		if (currentBytesLength > 1000){

			currentLengthString := helpers.ConvertIntToString(currentBytesLength)

			title := translate("Invalid Hobbies")
			dialogMessageA := getLabelCentered(translate("Your Hobbies are too long."))
			dialogMessageB := getLabelCentered(translate("Hobbies cannot be longer than 1000 bytes."))
			dialogMessageC := getLabelCentered(translate("Current Length: ") + currentLengthString)
			dialogContent := container.NewVBox(dialogMessageA, dialogMessageB, dialogMessageC)
			dialog.ShowCustom(title, translate("Close"), dialogContent, window)
			return
		}

		if (newHobbies == ""){
			myLocalProfiles.DeleteProfileData("Mate", "Hobbies")
		} else {
			myLocalProfiles.SetProfileData("Mate", "Hobbies", newHobbies)
		}

		nextPage()
	}))

	emptyLabel := widget.NewLabel("")

	submitButtonWithSpacer := container.NewVBox(submitButton, emptyLabel)

	hobbiesEntryBoxed := getWidgetBoxed(hobbiesEntry)
	
	hobbiesEntryWithSubmitButton := container.NewBorder(nil, submitButtonWithSpacer, nil, nil, hobbiesEntryBoxed)

	header := container.NewVBox(title, backButton, widget.NewSeparator())

	page := container.NewBorder(header, nil, nil, nil, hobbiesEntryWithSubmitButton)

	setPageContent(page, window)
}



func setBuildMateProfilePage_Wealth(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Wealth(window, previousPage)}

	title := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered("Wealth")

	description1 := getLabelCentered("Enter your total wealth.")
	description2 := getLabelCentered("Be careful about sharing any secret wealth.")
	description3 := getLabelCentered("For the most safety, only share an amount that is already public and obvious.")

	// Outputs:
	//	-bool: Current wealth exists
	//	-string: Current wealth
	//	-bool: Current wealth is a lower bound
	//	-error
	getCurrentWealthInfo := func()(bool, string, bool, error){	

		wealthExists, currentWealth, err := myLocalProfiles.GetProfileData("Mate", "Wealth")
		if (err != nil){ return false, "", false, err }
		if (wealthExists == false){
			return false, "", false, nil
		}
		isValid, err := helpers.VerifyStringIsIntWithinRange(currentWealth, 0, 9223372036854775807)
		if (err != nil){ return false, "", false, err }
		if (isValid == false){
			return false, "", false, errors.New("MyLocalProfiles contains invalid Wealth: " + currentWealth)
		}

		currentWealthIsLowerBoundExists, currentWealthIsLowerBound, err := myLocalProfiles.GetProfileData("Mate", "WealthIsLowerBound")
		if (err != nil){ return false, "", false, err }
		if (currentWealthIsLowerBoundExists == false){
			return false, "", false, errors.New("MyLocalProfiles contains Wealth without WealthIsLowerBound attribute.")
		}

		currentWealthIsLowerBoundBool, err := helpers.ConvertYesOrNoStringToBool(currentWealthIsLowerBound)
		if (err != nil){
			return false, "", false, errors.New("MyLocalProfiles contains Invalid WealthIsLowerBound: " + currentWealthIsLowerBound)
		}

		return true, currentWealth, currentWealthIsLowerBoundBool, nil
	}

	currentWealthExists, currentWealth, currentWealthIsLowerBound, err := getCurrentWealthInfo()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	wealthEntry := widget.NewEntry()

	if (currentWealthExists == false){
		wealthEntry.SetPlaceHolder(translate("Enter wealth..."))
	} else {
		wealthEntry.SetText(currentWealth)
	}

	getCurrentWealthCurrencyCodeFunction := func()(string, error){
		currentWealthCurrencyExists, currentWealthCurrencyCode, err := myLocalProfiles.GetProfileData("Mate", "WealthCurrency")
		if (err != nil){ return "", err }
		if (currentWealthCurrencyExists == true){
			return currentWealthCurrencyCode, nil
		}

		// We will default to the user's already chosen currency
		exists, currentAppCurrency, err := globalSettings.GetSetting("Currency")
		if (err != nil) { return "", err }
		if (exists == false){
			return "USD", nil
		}

		return currentAppCurrency, nil
	}

	currentWealthCurrencyCode, err := getCurrentWealthCurrencyCodeFunction()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	_, currentWealthCurrencySymbol, err := currencies.GetCurrencyInfoFromCurrencyCode(currentWealthCurrencyCode)
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	getCurrentWealthLabel := func()fyne.Widget{

		if (currentWealthExists == false){
			result := translate("No Response")

			wealthLabel := getBoldItalicLabel(result)
			return wealthLabel
		}

		getCurrentWealthFormatted := func()string{

			if (currentWealthIsLowerBound == true){

				currentWealthFormatted := currentWealthCurrencySymbol + " " + currentWealth + "+ " + currentWealthCurrencyCode
				return currentWealthFormatted
			}
			currentWealthFormatted := currentWealthCurrencySymbol + " " + currentWealth + " " + currentWealthCurrencyCode
			return currentWealthFormatted
		}
		currentWealthFormatted := getCurrentWealthFormatted()

		wealthLabel := getBoldLabel(currentWealthFormatted)
		return wealthLabel
	}

	currentWealthLabel := getCurrentWealthLabel()

	myWealthLabel := widget.NewLabel("My Wealth:")

	currentWealthRow := container.NewHBox(layout.NewSpacer(), myWealthLabel, currentWealthLabel, layout.NewSpacer())

	chooseCurrencyButton := widget.NewButton(currentWealthCurrencySymbol, func(){

			onSelectFunction := func(newCurrencyCode string)error{

					err := myLocalProfiles.SetProfileData("Mate", "WealthCurrency", newCurrencyCode)
					if (err != nil){ return err }

					return nil			
				}

			setChooseCurrencyPage(window, getCurrentWealthCurrencyCodeFunction, onSelectFunction, currentPage)
		})

	chooseCurrencyButtonWithSpacer := container.NewHBox(layout.NewSpacer(), chooseCurrencyButton)

	currentCurrencyCodeLabel := getBoldLabel(currentWealthCurrencyCode)

	currentCurrencyCodeLabelWidened := container.NewHBox(currentCurrencyCodeLabel, widget.NewLabel(""), widget.NewLabel(""))

	wealthEntryRow := getContainerCentered(container.NewGridWithRows(1, chooseCurrencyButtonWithSpacer, wealthEntry, currentCurrencyCodeLabelWidened))

	isLowerBoundCheck := widget.NewCheck("Is A Lower Bound?", func(newIsLowerBoundStatus bool){

			if (currentWealthExists == false){
				return
			}
			newWealth := wealthEntry.Text
			if (newWealth != currentWealth){
				return
			}

			newIsLowerBoundString := helpers.ConvertBoolToYesOrNoString(newIsLowerBoundStatus)

			myLocalProfiles.SetProfileData("Mate", "WealthIsLowerBound", newIsLowerBoundString)

			currentPage()
		})

	if (currentWealthExists == true && currentWealthIsLowerBound == true){
		isLowerBoundCheck.Checked = true
	}

	isLowerBoundHelpButton := widget.NewButtonWithIcon("", theme.QuestionIcon(), func(){
			setWealthIsLowerBoundExplainerPage(window, currentPage)
		})
	isLowerBoundCheckRow := container.NewHBox(layout.NewSpacer(), isLowerBoundCheck, isLowerBoundHelpButton, layout.NewSpacer())

	submitButton := getWidgetCentered(widget.NewButtonWithIcon("Submit", theme.ConfirmIcon(), func(){

		newWealth := wealthEntry.Text

		isValid, err := helpers.VerifyStringIsIntWithinRange(newWealth, 0, 9223372036854775807)
		if (err != nil){
			setErrorEncounteredPage(window, err, currentPage)
			return
		}
		if (isValid == false){

			if (currentWealthExists == false){
				wealthEntry.SetText("")
				wealthEntry.SetPlaceHolder(translate("Enter wealth..."))
			} else {
				wealthEntry.SetText(currentWealth)
			}

			title := translate("Invalid Wealth")
			dialogMessageA := getLabelCentered(translate("Invalid wealth entered."))
			dialogMessageB := getLabelCentered(translate("The value must be a number between 0 and 9223372036854775807."))
			dialogContent := container.NewVBox(dialogMessageA, dialogMessageB)
			dialog.ShowCustom(title, translate("Close"), dialogContent, window)
			return
		}

		myLocalProfiles.SetProfileData("Mate", "Wealth", newWealth)

		newIsLowerBoundStatus := isLowerBoundCheck.Checked

		newIsLowerBoundString := helpers.ConvertBoolToYesOrNoString(newIsLowerBoundStatus)

		myLocalProfiles.SetProfileData("Mate", "WealthIsLowerBound", newIsLowerBoundString)

		myLocalProfiles.SetProfileData("Mate", "WealthCurrency", currentWealthCurrencyCode)

		currentPage()
	}))

	noResponseButton := getWidgetCentered(widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){ 
			_ = myLocalProfiles.DeleteProfileData("Mate", "Wealth")
			_ = myLocalProfiles.DeleteProfileData("Mate", "WealthIsLowerBound")
			currentPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description1, description2, description3, widget.NewSeparator(), currentWealthRow, widget.NewSeparator(), wealthEntryRow, isLowerBoundCheckRow, submitButton, widget.NewSeparator(), noResponseButton)
	
	setPageContent(page, window)
}

func setBuildMateProfilePage_Job(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Job(window, previousPage)}

	pageTitle := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate("Job"))

	description1 := getLabelCentered(translate("Enter your job."))
	description2 := getLabelCentered(translate("This is how you make money."))

	currentJobExists, currentJob, err := myLocalProfiles.GetProfileData("Mate", "Job")
	if (err != nil) {
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	getMyCurrentJobRow := func()(*fyne.Container, error){

		myJobLabel := widget.NewLabel("My Job:")

		if (currentJobExists == false){

			noResponseLabel := getBoldItalicLabel("No Response")
			currentJobRow := container.NewHBox(layout.NewSpacer(), myJobLabel, noResponseLabel, layout.NewSpacer())

			return currentJobRow, nil
		}

		isAllowed := allowedText.VerifyStringIsAllowed(currentJob)
		if (isAllowed == false){
			return nil, errors.New("My current mate job is not allowed.")
		}

		if(len(currentJob) > 100){
			return nil, errors.New("My current mate job is too long.")
		}

		currentJobTrimmed, _, err := helpers.TrimAndFlattenString(currentJob, 15)
		if (err != nil) { return nil, err }

		currentJobLabel := getBoldLabel(currentJobTrimmed)

		viewMyJobButton := widget.NewButtonWithIcon("", theme.VisibilityIcon(), func(){
				setViewTextPage(window, "Viewing Job", currentJob, false, currentPage)
			})

		currentJobRow := container.NewHBox(layout.NewSpacer(), myJobLabel, currentJobLabel, viewMyJobButton, layout.NewSpacer())

		return currentJobRow, nil
	}

	currentJobRow, err := getMyCurrentJobRow()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	
	editButton := widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func(){
			setBuildMateProfilePage_EditJob(window, currentPage, currentPage)
		})

	noResponseButton := widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){

			if (currentJobExists == false){
				return
			}	

			setBuildMateProfilePage_DeleteJob(window, currentPage, currentPage)
		})

	buttonsGrid := getContainerCentered(container.NewGridWithColumns(1, editButton, noResponseButton))
	
	page := container.NewVBox(pageTitle, backButton, widget.NewSeparator(), pageSubtitle, widget.NewSeparator(), description1, description2, widget.NewSeparator(), currentJobRow, widget.NewSeparator(), buttonsGrid)

	setPageContent(page, window)
}


func setBuildMateProfilePage_DeleteJob(window fyne.Window, previousPage func(), nextPage func()){

	title := getPageTitleCentered("Delete Job")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Delete Job?")
	
	description2 := getLabelCentered("Confirm to delete your job?")

	confirmButton := getWidgetCentered(widget.NewButtonWithIcon("Delete", theme.DeleteIcon(), func(){
			myLocalProfiles.DeleteProfileData("Mate", "Job")
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, confirmButton)

	setPageContent(page, window)
}


func setBuildMateProfilePage_EditJob(window fyne.Window, previousPage func(), nextPage func()){

	title := getPageTitleCentered("Edit Job")

	backButton := getBackButtonCentered(previousPage)

	jobEntry := widget.NewMultiLineEntry()
	jobEntry.Wrapping = 3

	getCurrentJob := func()(string, error){	

		exists, currentJob, err := myLocalProfiles.GetProfileData("Mate", "Job")
		if (err != nil) { return "", err }
		if (exists == false){
			return "", nil
		}

		isAllowed := allowedText.VerifyStringIsAllowed(currentJob)
		if (isAllowed == false){
			return "", errors.New("My current mate job is not allowed: " + currentJob)
		}

		if( len(currentJob) > 100 ){
			return "", errors.New("My current mate job is too long: " + currentJob)
		}

		return currentJob, nil
	}

	currentJob, err := getCurrentJob()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	if (currentJob == ""){
		jobEntry.SetPlaceHolder("Enter your job...")
	} else {
		jobEntry.SetText(currentJob)
	}

	submitButton := getWidgetCentered(widget.NewButtonWithIcon(translate("Save"), theme.ConfirmIcon(), func(){

		newJob := jobEntry.Text

		isAllowed := allowedText.VerifyStringIsAllowed(newJob)
		if (isAllowed == false){
			title := translate("Invalid Job")
			dialogMessageA := getLabelCentered(translate("Your job contain an invalid character."))
			dialogMessageB := getLabelCentered(translate("It must be encoded in UTF-8."))
			dialogContent := container.NewVBox(dialogMessageA, dialogMessageB)
			dialog.ShowCustom(title, translate("Close"), dialogContent, window)
			return
		}

		currentBytesLength := len(newJob)
		if (currentBytesLength > 100){

			currentLengthString := helpers.ConvertIntToString(currentBytesLength)

			title := translate("Invalid Job")

			dialogMessageA := getLabelCentered(translate("Your Job is too long."))
			dialogMessageB := getLabelCentered(translate("Job cannot be longer than 100 bytes."))
			dialogMessageC := getLabelCentered(translate("Current Length: ") + currentLengthString)
			dialogContent := container.NewVBox(dialogMessageA, dialogMessageB, dialogMessageC)
			dialog.ShowCustom(title, translate("Close"), dialogContent, window)
			return
		}

		if (newJob == ""){
			_ = myLocalProfiles.DeleteProfileData("Mate", "Job")
		} else {
			_ = myLocalProfiles.SetProfileData("Mate", "Job", newJob)
		}

		nextPage()
	}))

	emptyLabel := widget.NewLabel("")

	submitButtonWithSpacer := container.NewVBox(submitButton, emptyLabel)

	jobEntryBoxed := getWidgetBoxed(jobEntry)
	
	jobEntryWithSubmitButton := container.NewBorder(nil, submitButtonWithSpacer, nil, nil, jobEntryBoxed)

	header := container.NewVBox(title, backButton, widget.NewSeparator())

	page := container.NewBorder(header, nil, nil, nil, jobEntryWithSubmitButton)

	setPageContent(page, window)
}


func setBuildMateProfilePage_Diet(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Diet(window, previousPage)}

	pageTitle := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))
	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate("Diet"))

	description1 := getLabelCentered(translate("Rate each food."))
	description2 := getLabelCentered(translate("1 = Strongly Dislike, 10 = Strongly Like"))

	//TODO: Shrink the columns of this grid so they are only as wide as the widest element within them
	// Also add grid lines
	foodSelectorsGrid := container.NewGridWithColumns(3)

	foodsList := []string{"Fruit", "Vegetables", "Nuts", "Grains", "Dairy", "Seafood", "Beef", "Pork", "Poultry", "Eggs", "Beans"}

	for _, foodName := range foodsList{

		foodAttributeName := foodName + "Rating"

		foodNameLabel := getBoldLabelCentered(foodName)

		optionsList := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}

		foodRatingSelector := widget.NewSelect(optionsList, func(response string){
	
				err := myLocalProfiles.SetProfileData("Mate", foodAttributeName, response)
				if (err != nil){
					setErrorEncounteredPage(window, err, currentPage)
					return
				}
			})

		currentRatingExists, currentFoodRating, err := myLocalProfiles.GetProfileData("Mate", foodAttributeName)
		if (err != nil){
			setErrorEncounteredPage(window, err, previousPage)
			return
		}

		if (currentRatingExists == true){
			foodRatingSelector.Selected = currentFoodRating
		} else {
			foodRatingSelector.PlaceHolder = translate("Choose rating...")
		}

		noResponseButton := getWidgetCentered(widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){

				err := myLocalProfiles.DeleteProfileData("Mate", foodAttributeName)
				if (err != nil){
					setErrorEncounteredPage(window, err, currentPage)
					return
				}

				currentPage()
			}))

		foodSelectorsGrid.Add(foodNameLabel)
		foodSelectorsGrid.Add(foodRatingSelector)
		foodSelectorsGrid.Add(noResponseButton)
	}

	foodsGrid := getContainerCentered(foodSelectorsGrid)

	page := container.NewVBox(pageTitle, backButton, widget.NewSeparator(), pageSubtitle, widget.NewSeparator(), description1, description2, widget.NewSeparator(), foodsGrid)
	
	setPageContent(page, window)
}


func setBuildMateProfilePage_Fame(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Fame(window, previousPage)}

	title := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered("Fame")

	description1 := getLabelCentered("Describe how famous you are on a scale of 1-10.")
	description2 := getLabelCentered("1 = Least famous, 10 = Most famous.")

	currentSelectionExists, currentFameSelection, err := myLocalProfiles.GetProfileData("Mate", "Fame")
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	myFameTitle := widget.NewLabel("My Fame:")

	getMyFameLabel := func()fyne.Widget{

		if (currentSelectionExists == false){

			myFameLabel := getBoldItalicLabel(translate("No Response"))
	
			return myFameLabel
		}

		labelText := currentFameSelection + "/10"

		myFameLabel := getBoldLabel(labelText)
		return myFameLabel
	}

	myFameLabel := getMyFameLabel()

	myFameRow := container.NewHBox(layout.NewSpacer(), myFameTitle, myFameLabel, layout.NewSpacer())

	selectFameLabel := getItalicLabelCentered("Select your fame:")

	optionsList := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
	fameSelector := widget.NewSelect(optionsList, func(newSelection string){

			err := myLocalProfiles.SetProfileData("Mate", "Fame", newSelection)
			if (err != nil){
				setErrorEncounteredPage(window, err, currentPage)
				return
			}

			currentPage()
		})

	if (currentSelectionExists == true){
		fameSelector.Selected = currentFameSelection
	} else {
		fameSelector.PlaceHolder = translate("Select one...")
	}

	fameSelectorCentered := getWidgetCentered(fameSelector)

	noResponseButton := getWidgetCentered(widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){

			err := myLocalProfiles.DeleteProfileData("Mate", "Fame")
			if (err != nil){
				setErrorEncounteredPage(window, err, currentPage)
				return
			}
			currentPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description1, description2, widget.NewSeparator(), myFameRow, widget.NewSeparator(), selectFameLabel, fameSelectorCentered, noResponseButton)

	setPageContent(page, window)
}

func setBuildMateProfilePage_Drugs(window fyne.Window, previousPage func()){

	currentPage := func(){setBuildMateProfilePage_Drugs(window, previousPage)}

	pageTitle := getPageTitleCentered(translate("Build Mate Profile - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate("Drugs"))

	description1 := getLabelCentered(translate("Describe how often you take each drug."))
	description2 := getLabelCentered(translate("1 = Never, 10 = Most Often"))
	description3 := getBoldLabelCentered(translate("If the drug is illegal where you live, do not respond with a non-1 response."))

	getDrugsGrid := func()(*fyne.Container, error){

		drugsGrid := container.NewGridWithColumns(3)

		drugsList := []string{"Alcohol", "Tobacco", "Cannabis"}

		for _, drugName := range drugsList{

			drugAttributeName := drugName + "Frequency"

			drugNameLabel := getBoldLabelCentered(translate(drugName))
			
			optionsList := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}

			handleSelectionFunction := func(response string){
					err := myLocalProfiles.SetProfileData("Mate", drugAttributeName, response)
					if (err != nil){
						setErrorEncounteredPage(window, err, currentPage)
					}				
				}

			drugRatingSelector := widget.NewSelect(optionsList, handleSelectionFunction)

			currentRatingExists, currentDrugRating, err := myLocalProfiles.GetProfileData("Mate", drugAttributeName)
			if (err != nil){ return nil, err }

			if (currentRatingExists == true){
				drugRatingSelector.Selected = currentDrugRating
			} else {
				drugRatingSelector.PlaceHolder = translate("Choose rating...")
			}

			noResponseButton := getWidgetCentered(widget.NewButtonWithIcon(translate("No Response"), theme.CancelIcon(), func(){ 
					err := myLocalProfiles.DeleteProfileData("Mate", drugAttributeName)
					if (err != nil){
						setErrorEncounteredPage(window, err, currentPage)
						return
					}
					currentPage()
				}))

			drugsGrid.Add(drugNameLabel)
			drugsGrid.Add(drugRatingSelector)
			drugsGrid.Add(noResponseButton)
		}

		drugsGridCentered := getContainerCentered(drugsGrid)

		return drugsGridCentered, nil
	}

	drugsGrid, err := getDrugsGrid()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	page := container.NewVBox(pageTitle, backButton, widget.NewSeparator(), pageSubtitle, widget.NewSeparator(), description1, description2, widget.NewSeparator(), description3, widget.NewSeparator(), drugsGrid)
	
	setPageContent(page, window)
}


