package gui

// desiresGui_Lifestyle.go implements pages to manage a user's lifestyle desires

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

import "seekia/internal/currencies"
import "seekia/internal/desires/myLocalDesires"


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

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

	title := getPageTitleCentered(translate("My Mate Desires - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

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

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

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

	drugsButton := widget.NewButton(translate("Drugs"), func(){
			setChooseDesiresPage_Drugs(window, currentPage)
		})

	buttonsGrid := getContainerCentered(container.NewGridWithColumns(1, wealthButton, dietButton, fameButton, drugsButton))

	buttonsGridPadded := container.NewPadded(buttonsGrid)

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

	setPageContent(page, window)
}


func setChooseDesiresPage_Wealth(window fyne.Window, previousPage func()){
	
	currentPage := func(){setChooseDesiresPage_Wealth(window, previousPage)}

	title := getPageTitleCentered("My Mate Desires - Lifestyle")

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered("Wealth")

	description1 := getLabelCentered("Choose your wealth desires.")

	currentCurrencyLabel := getItalicLabel("Current Currency:")

	//Outputs:
	//	-string: Current currency code (Example: "USD")
	//	-error
	getCurrentCurrencyCodeFunction := func()(string, error){

		currentCurrencyExists, currencyCode, err := myLocalDesires.GetDesire("WealthCurrency")
		if (err != nil){ return "", err }

		if (currentCurrencyExists == false){
			return "USD", nil
		}
		
		return currencyCode, nil
	}

	currencyCode, err := getCurrentCurrencyCodeFunction()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

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

	changeCurrencyButtonText := currencySymbol + currencyCode
	changeCurrencyButton := widget.NewButton(changeCurrencyButtonText, func(){

			onSelectFunction := func(newCurrencyCode string)error{

				err := myLocalDesires.SetDesire("WealthCurrency", newCurrencyCode)
				if (err != nil) { return err }

				return nil			
			}

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

	currentCurrencyRow := container.NewHBox(layout.NewSpacer(), currentCurrencyLabel, changeCurrencyButton, layout.NewSpacer())

	desireEditor, err := getDesireEditor_Numeric(window, currentPage, "Wealth", 0, 9223372036854775807, currencyCode, 0, false, nil, nil, false, "", "", nil)
	if (err != nil) {
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	viewStatisticsButton := getWidgetCentered(widget.NewButtonWithIcon("View Statistics", theme.InfoIcon(), func(){
			setViewMyMateDesireStatisticsPage(window, "Wealth", "Wealth", true, "Bar", "WealthInGold", currentPage)
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description1, widget.NewSeparator(), currentCurrencyRow, widget.NewSeparator(), desireEditor, widget.NewSeparator(), viewStatisticsButton)

	setPageContent(page, window)
}



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

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

	title := getPageTitleCentered("My Mate Desires - Lifestyle")

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered("Diet")

	description := getLabelCentered("Choose your diet desires.")

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

	buttonsGrid := container.NewGridWithColumns(2)

	for _, foodName := range foodNamesList{

		foodButton := widget.NewButton(foodName, func(){
				setChooseDesiresPage_FoodRating(window, foodName, currentPage)
			})
		buttonsGrid.Add(foodButton)
	}

	buttonsGridCentered := getContainerCentered(buttonsGrid)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description, widget.NewSeparator(), buttonsGridCentered)

	setPageContent(page, window)
}

func setChooseDesiresPage_FoodRating(window fyne.Window, foodName string, previousPage func()){

	currentPage := func(){setChooseDesiresPage_FoodRating(window, foodName, previousPage)}
	
	pageTitle := getPageTitleCentered(translate("My Mate Desires - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate(foodName))

	description1 := getLabelCentered("Choose your " + foodName + " rating desires.")
	description2 := getLabelCentered("Users provide a food rating between 1 and 10.")
	description3 := getLabelCentered("Choose the responses that you desire.")
	description4 := getLabelCentered("1/10 = Strongly dislike, 10/10 = Strongly like")

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

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

	desireName := foodName + "Rating"

	desireEditor, err := getDesireEditor_Choice(window, currentPage, desireName, optionTitlesList, optionNamesMap, false, true, 5)
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	desireTitle := foodName + " Rating"

	viewStatisticsButton := getWidgetCentered(widget.NewButtonWithIcon("View Statistics", theme.InfoIcon(), func(){
			setViewMyMateDesireStatisticsPage(window, desireTitle, desireName, true, "Bar", desireName, currentPage)
		}))

	page := container.NewVBox(pageTitle, backButton, widget.NewSeparator(), pageSubtitle, widget.NewSeparator(), description1, description2, description3, description4, widget.NewSeparator(), desireEditor, widget.NewSeparator(), viewStatisticsButton)

	setPageContent(page, window)
}



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

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

	title := getPageTitleCentered(translate("My Mate Desires - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered(translate("Fame"))

	description1 := getLabelCentered("Choose your fame desires.")
	description2 := getLabelCentered("Users describe their fame from 1 to 10.")
	description3 := getLabelCentered("Choose the fame responses that you desire.")
	description4 := getLabelCentered("1/10 = No fame, 10/10 = Most fame.")

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

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

	desireEditor, err := getDesireEditor_Choice(window, currentPage, "Fame", optionTitlesList, optionNamesMap, false, true, 5)
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	viewStatisticsButton := getWidgetCentered(widget.NewButtonWithIcon("View Statistics", theme.InfoIcon(), func(){
			setViewMyMateDesireStatisticsPage(window, "Fame", "Fame", true, "Bar", "Fame", currentPage)
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description1, description2, description3, description4, widget.NewSeparator(), desireEditor, widget.NewSeparator(), viewStatisticsButton)
	
	setPageContent(page, window)
}


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

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

	title := getPageTitleCentered("My Mate Desires - Lifestyle")

	backButton := getBackButtonCentered(previousPage)

	subtitle := getPageSubtitleCentered("Drugs")

	description := getLabelCentered("Choose your drug desires.")

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

	buttonsGrid := container.NewGridWithColumns(1)

	for _, drugName := range drugNamesList{

		drugButton := widget.NewButton(drugName, func(){
				setChooseDesiresPage_DrugFrequency(window, drugName, currentPage)
			})
		buttonsGrid.Add(drugButton)
	}

	buttonsGridCentered := getContainerCentered(buttonsGrid)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), subtitle, widget.NewSeparator(), description, widget.NewSeparator(), buttonsGridCentered)

	setPageContent(page, window)
}

func setChooseDesiresPage_DrugFrequency(window fyne.Window, drugName string, previousPage func()){

	currentPage := func(){setChooseDesiresPage_DrugFrequency(window, drugName, previousPage)}

	pageTitle := getPageTitleCentered(translate("My Mate Desires - Lifestyle"))

	backButton := getBackButtonCentered(previousPage)

	pageSubtitle := getPageSubtitleCentered(translate(drugName))

	description1 := getLabelCentered("Choose your " + drugName + " frequency desires.")
	description2 := getLabelCentered("Users describe their drug use frequency from 1 to 10.")
	description3 := getLabelCentered("Choose the user responses that you desire.")
	description4 := getLabelCentered("1/10 = Never, 10/10 = Constantly")

	desireName := drugName + "Frequency"

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

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

	desireEditor, err := getDesireEditor_Choice(window, currentPage, desireName, optionTitlesList, optionNamesMap, false, true, 5)
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	desireTitle := drugName + " Frequency"

	viewStatisticsButton := getWidgetCentered(widget.NewButtonWithIcon("View Statistics", theme.InfoIcon(), func(){
			setViewMyMateDesireStatisticsPage(window, desireTitle, desireName, true, "Bar", desireName, currentPage)
		}))

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



