package gui

// hostGui.go implements pages for hosts to manage their server, view logs, view other hosts, and more.

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/network/myIdentityBalance"
import "seekia/internal/myIdentity"
import "seekia/internal/mySettings"
import "seekia/internal/network/appNetworkType/getAppNetworkType"
import "seekia/internal/appMemory"

import "errors"

func setHostPage(window fyne.Window, previousPageExists bool, previousPage func()){

	appMemory.SetMemoryEntry("CurrentViewedPage", "Host")

	currentPage := func(){setHostPage(window, previousPageExists, previousPage)}

	title := getPageTitleCentered("Host")

	page := container.NewVBox(title)

	if (previousPageExists == true){
		backButton := getBackButtonCentered(previousPage)
		page.Add(backButton)
	}

	page.Add(widget.NewSeparator())
	
	description := getLabelCentered("Support the Seekia network by seeding content.")
	page.Add(description)
	page.Add(widget.NewSeparator())

	settingsIcon, err := getFyneImageIcon("Settings")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}

	profileIcon, err := getFyneImageIcon("Profile")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}
	
	statsIcon, err := getFyneImageIcon("Stats")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}

	logsIcon, err := getFyneImageIcon("Choice")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}

	helpIcon, err := getFyneImageIcon("Info")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}

	hostsIcon, err := getFyneImageIcon("Host")
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}

	helpButton := widget.NewButton("Help", func(){
			setHostingHelpPage(window, currentPage)
		})
	helpButtonWithIcon := container.NewGridWithColumns(1, helpIcon, helpButton)

	settingsButton := widget.NewButton("Settings", func(){
			setHostSettingsPage(window, currentPage)
		})
	settingsButtonWithIcon := container.NewGridWithColumns(1, settingsIcon, settingsButton)

	statsButton := widget.NewButton("Stats", func(){
			setHostStatsPage(window, currentPage)
		})
	statsButtonWithIcon := container.NewGridWithColumns(1, statsIcon, statsButton)

	logsButton := widget.NewButton("Logs", func(){
			//TODO: Logs about hosting
			showUnderConstructionDialog(window)
		})
	logsButtonWithIcon := container.NewGridWithColumns(1, logsIcon, logsButton)

	profileButton := widget.NewButton("Profile", func(){
			setProfilePage(window, true, "Host", true, currentPage)
		})
	profileButtonWithIcon := container.NewGridWithColumns(1, profileIcon, profileButton)

	hostsButton := widget.NewButton("Hosts", func(){
			setViewHostsPage(window, currentPage)
		})
	hostsButtonWithIcon := container.NewGridWithColumns(1, hostsIcon, hostsButton)

	buttonsRow := getContainerCentered(container.NewGridWithRows(1, helpButtonWithIcon, profileButtonWithIcon, settingsButtonWithIcon, hostsButtonWithIcon, statsButtonWithIcon, logsButtonWithIcon))

	page.Add(buttonsRow)
	page.Add(widget.NewSeparator())

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

		exists, hostModeStatus, err := mySettings.GetSetting("HostModeOnOffStatus")
		if (err != nil){ return nil, err }
		if (exists == false || hostModeStatus == "Off"){

			description1 := getBoldLabelCentered("You must enable host mode.")
			description2 := getLabelCentered("Enable it on the Settings page.")

			content := container.NewVBox(description1, description2)

			return content, nil
		}

		identityExists, myIdentityHash, err := myIdentity.GetMyIdentityHash("Host")
		if (err != nil) { return nil, err }
		if (identityExists == false){

			description1 := getBoldLabelCentered("Your Host identity does not exist.")
			description2 := getLabelCentered("You must create it to be a host.")
		
			createIdentityButton := getWidgetCentered(widget.NewButtonWithIcon("Create Identity", theme.NavigateNextIcon(), func(){
					setChooseNewIdentityHashPage(window, "Host", currentPage, currentPage)			
				}))
			content := container.NewVBox(description1, description2, createIdentityButton)
			
			return content, nil
		}

		appNetworkType, err := getAppNetworkType.GetAppNetworkType()
		if (err != nil) { return nil, err }

		identityExists, identityIsFunded, _, err := myIdentityBalance.GetMyIdentityBalanceStatus(myIdentityHash, appNetworkType)
		if (err != nil){ return nil, err }
		
		if (identityExists == false){
			return nil, errors.New("My host identity not found after being found.")
		}

		if (identityIsFunded == false){

			description1 := getBoldLabelCentered("Your host identity is not funded.")
			description2 := getLabelCentered("Fund your Host identity below.")

			fundIdentityButton := getWidgetCentered(widget.NewButton("Fund Identity", func(){
					setIncreaseMyIdentityBalancePage(window, "Host", 30, currentPage)
				}))
			content := container.NewVBox(description1, description2, fundIdentityButton)

			return content, nil
		}

		description1 := getBoldLabelCentered("Under Construction")
		description2 := getLabelCentered("Seekia is not able to host content yet.")

		/*
		hostServerStatus := peerServer.GetPeerServerOnOffStatus()
		hostServerStatusLabel := widget.NewLabel("Host Server Status:")
		hostServerStatusText := getBoldLabel(hostServerStatus)

		hostServerStatusRow := getContainerCentered(container.NewHBox(hostServerStatusLabel, hostServerStatusText))

		getServerStartStopButton := func() fyne.Widget{
			if (hostServerStatus == "Off"){
				startButton := widget.NewButtonWithIcon(translate("Start Server"), theme.MediaPlayIcon(), func(){
					err := peerServer.StartPeerServer()
					if (err != nil){
						setErrorEncounteredPage(window, err, func(){setHomePage(window)})
						return
					}
					currentPage()
				})
				return startButton
			}

			stopButton := widget.NewButtonWithIcon(translate("Stop Server"), theme.MediaStopIcon(), func(){
				peerServer.StopPeerServer()
				currentPage()
			})

			return stopButton		
		}
		
		startStopButton := getServerStartStopButton()
		*/

		result := container.NewVBox(description1, description2)
		return result, nil
	}

	hostStatusContainer, err := getHostStatusContainer()
	if (err != nil){
		setErrorEncounteredPage(window, err, func(){setHomePage(window)})
		return
	}
	
	page.Add(hostStatusContainer)

	setPageContent(page, window)
}

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

	setLoadingScreen(window, "Host Stats", "Loading Host Stats...")

	title := getPageTitleCentered("Host Server Stats")

	backButton := getBackButtonCentered(previousPage)

	//TODO: Retrieve all variables below from new package to keep track of hosting history

	totalSeededAmountTitle := widget.NewLabel("Total Seeded Amount:")
	totalSeededAmountLabel := getBoldLabel("0 Gigabytes")
	totalSeededAmountRow := container.NewHBox(layout.NewSpacer(), totalSeededAmountTitle, totalSeededAmountLabel, layout.NewSpacer())

	numberOfSeededProfilesTitle := widget.NewLabel("Seeded Profiles:")
	numberOfSeededProfilesLabel := getBoldLabel("0")
	numberOfSeededProfilesRow := container.NewHBox(layout.NewSpacer(), numberOfSeededProfilesTitle, numberOfSeededProfilesLabel, layout.NewSpacer())	

	numberOfSeededMessagesTitle := widget.NewLabel("Seeded Messages:")
	numberOfSeededMessagesLabel := getBoldLabel("0")
	numberOfSeededMessagesRow := container.NewHBox(layout.NewSpacer(), numberOfSeededMessagesTitle, numberOfSeededMessagesLabel, layout.NewSpacer())

	numberOfSeededReviewsTitle := widget.NewLabel("Seeded Reviews:")
	numberOfSeededReviewsLabel := getBoldLabel("0")
	numberOfSeededReviewsRow := container.NewHBox(layout.NewSpacer(), numberOfSeededReviewsTitle, numberOfSeededReviewsLabel, layout.NewSpacer())

	numberOfSeededReportsTitle := widget.NewLabel("Seeded Reports:")
	numberOfSeededReportsLabel := getBoldLabel("0")
	numberOfSeededReportsRow := container.NewHBox(layout.NewSpacer(), numberOfSeededReportsTitle, numberOfSeededReportsLabel, layout.NewSpacer())

	page := container.NewVBox(title, backButton, widget.NewSeparator(), totalSeededAmountRow, widget.NewSeparator(), numberOfSeededProfilesRow, numberOfSeededMessagesRow, numberOfSeededReviewsRow, numberOfSeededReportsRow)

	setPageContent(page, window)
}

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

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

	title := getPageTitleCentered("Host Settings")

	backButton := getBackButtonCentered(previousPage)

	description := getLabelCentered("Manage your host settings.")

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

		settingTitleColumn := container.NewVBox()
		settingStatusColumn := container.NewVBox()
		manageSettingButtonsColumn := container.NewVBox()

		addSettingRow := func(addSeparator bool, settingTitle string, settingName string, manageSettingPage func())error{

			settingTitleLabel := getBoldLabelCentered(settingTitle)

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

				exists, hostModeStatus, err := mySettings.GetSetting(settingName)
				if (err != nil){ return "", err }
				if (exists == false){
					return "Off", nil
				}
				return hostModeStatus, nil
			}

			settingStatus, err := getSettingOnOffStatus()
			if (err != nil) { return err }

			settingStatusLabel := getBoldLabelCentered(settingStatus)

			manageSettingButton := widget.NewButtonWithIcon("Manage", theme.SettingsIcon(), manageSettingPage)

			settingTitleColumn.Add(settingTitleLabel)
			settingStatusColumn.Add(settingStatusLabel)
			manageSettingButtonsColumn.Add(manageSettingButton)

			if (addSeparator == true){

				settingTitleColumn.Add(widget.NewSeparator())
				settingStatusColumn.Add(widget.NewSeparator())
				manageSettingButtonsColumn.Add(widget.NewSeparator())
			}

			return nil
		}
		
		err := addSettingRow(true, "Host Mode", "HostModeOnOffStatus", func(){
				setHostSettingsPage_HostMode(window, currentPage)
			})
		if (err != nil) { return nil, err }

		err = addSettingRow(true, "Host Unviewable Profiles", "HostUnviewableProfilesOnOffStatus", func(){
				setHostSettingsPage_HostUnviewableProfiles(window, currentPage)
			})
		if (err != nil) { return nil, err }

		err = addSettingRow(true, "Host Messages", "HostMessagesOnOffStatus", func(){
				setHostSettingsPage_HostMessages(window, currentPage)
			})
		if (err != nil) { return nil, err }

		err = addSettingRow(false, "Host Over Clearnet", "HostOverClearnetOnOffStatus", func(){
				setHostSettingsPage_HostOverClearnet(window, currentPage)
			})
		if (err != nil) { return nil, err }

		settingsGrid := container.NewHBox(layout.NewSpacer(), settingTitleColumn, settingStatusColumn, manageSettingButtonsColumn, layout.NewSpacer())

		return settingsGrid, nil
	}

	settingsGrid, err := getSettingsGrid()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	manageStorageButton := getWidgetCentered(widget.NewButtonWithIcon("Manage Storage", theme.DocumentSaveIcon(), func(){
			setManageStoragePage(window, currentPage)
		}))

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


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

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

	title := getPageTitleCentered("Settings - Host Mode")

	backButton := getBackButtonCentered(previousPage)

	description1 := getLabelCentered("Enable this mode to start hosting Seekia content.")
	description2 := getLabelCentered("You can choose what type of content you want to host on the Host Settings page")
	description3 := getLabelCentered("You will only host over the Tor anonymity network unless you enable clearnet hosting.")
	description4 := getLabelCentered("Your host identity will be tied to everything you host.")
	description5 := getLabelCentered("Create and fund a new host identity if you want to start fresh.")

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

		exists, hostModeStatus, err := mySettings.GetSetting("HostModeOnOffStatus")
		if (err != nil){ return "", err }
		if (exists == false){
			return "Off", nil
		}
		if (hostModeStatus != "On" && hostModeStatus != "Off"){
			return "", errors.New("Invalid host mode status:" + hostModeStatus)
		}
		return hostModeStatus, nil
	}

	hostModeStatus, err := getCurrentHostModeStatus()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	
	currentStatusLabel := widget.NewLabel("Current Status:")
	currentStatusText := getBoldLabel(hostModeStatus)
	currentStatusRow := container.NewHBox(layout.NewSpacer(), currentStatusLabel, currentStatusText, layout.NewSpacer())

	getEnableDisableButton := func()fyne.Widget{
		
		if (hostModeStatus == "On"){
			disableButton := widget.NewButton("Disable", func(){
				err := mySettings.SetSetting("HostModeOnOffStatus", "Off")
				if (err != nil){
					setErrorEncounteredPage(window, err, previousPage)
					return
				}
				currentPage()
				})
			return disableButton
		}
		
		enableButton := widget.NewButton("Enable", func(){
				setConfirmEnableHostModePage(window, currentPage, currentPage)
			})
		return enableButton
	}

	enableDisableButton := getEnableDisableButton()
	enableDisableButtonCentered := getWidgetCentered(enableDisableButton)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, widget.NewSeparator(), currentStatusRow, enableDisableButtonCentered)

	setPageContent(page, window)
}

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

	title := getPageTitleCentered("Confirm Enable Host Mode")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Enable host mode?")

	description2 := getLabelCentered("In this mode, you will become a host on the Seekia network.")
	description3 := getLabelCentered("You may host content that is unruleful.")
	description4 := getLabelCentered("The Seekia moderation system will try to remove unruleful content from the network.")
	description5 := getLabelCentered("You must accept all legal risks associated with hosting this content.")

	enableHostModeButton := getWidgetCentered(widget.NewButtonWithIcon("Enable", theme.ConfirmIcon(), func(){
			err := mySettings.SetSetting("HostModeOnOffStatus", "On")
			if (err != nil){
				setErrorEncounteredPage(window, err, previousPage)
				return
			}
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, enableHostModeButton)

	setPageContent(page, window)
}

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

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

	title := getPageTitleCentered("Settings - Host Unviewable Profiles")

	backButton := getBackButtonCentered(previousPage)

	description1 := getLabelCentered("Enable this mode if you are willing to host unviewable profiles.")
	description2 := getLabelCentered("These profiles may contain rulebreaking content.")
	description3 := getLabelCentered("Unruleful profiles should eventually be banned by the moderators and deleted from the network.")
	description4 := getLabelCentered("You will only serve these profiles to other hosts and moderators who opt-in.")
	description5 := getLabelCentered("Only enable this mode if you accept the legal liability of hosting these profiles.")

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

		exists, hostUnviewableStatus, err := mySettings.GetSetting("HostUnviewableProfilesOnOffStatus")
		if (err != nil){ return "", err }
		if (exists == false){
			return "Off", nil
		}
		if (hostUnviewableStatus != "On" && hostUnviewableStatus != "Off"){
			return "", errors.New("Invalid HostUnviewableProfilesOnOffStatus: " + hostUnviewableStatus)
		}

		return hostUnviewableStatus, nil
	}

	hostUnviewableStatus, err := getCurrentHostUnviewableProfilesStatus()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}

	currentStatusLabel := widget.NewLabel("Current Status:")
	currentStatusText := getBoldLabel(hostUnviewableStatus)
	currentStatusRow := container.NewHBox(layout.NewSpacer(), currentStatusLabel, currentStatusText, layout.NewSpacer())

	getEnableDisableButton := func()fyne.Widget{
		
		if (hostUnviewableStatus == "On"){
			disableButton := widget.NewButton("Disable", func(){
					err := mySettings.SetSetting("HostUnviewableProfilesOnOffStatus", "Off")
					if (err != nil){
						setErrorEncounteredPage(window, err, previousPage)
						return
					}
					currentPage()
				})
			return disableButton
		}
		
		enableButton := widget.NewButton("Enable", func(){
				setConfirmEnableHostUnviewableProfilesPage(window, currentPage, currentPage)
			})
		return enableButton
	}

	enableDisableButton := getEnableDisableButton()
	enableDisableButtonCentered := getWidgetCentered(enableDisableButton)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, widget.NewSeparator(), currentStatusRow, enableDisableButtonCentered)

	setPageContent(page, window)
}


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

	title := getPageTitleCentered("Confirm Host Unviewable Profiles")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Host Unviewable Profiles?")

	description2 := getLabelCentered("In this mode, you will download and serve unviewable profiles.")
	description3 := getLabelCentered("These profiles may contain illegal and rulebreaking content.")
	description4 := getLabelCentered("Unruleful profiles should be banned by the moderators and deleted.")
	description5 := getLabelCentered("You must accept the legal risks of hosting these profiles.")

	enableButton := getWidgetCentered(widget.NewButtonWithIcon("Enable", theme.ConfirmIcon(), func(){
			err := mySettings.SetSetting("HostUnviewableProfilesOnOffStatus", "On")
			if (err != nil){
				setErrorEncounteredPage(window, err, previousPage)
				return
			}
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, enableButton)

	setPageContent(page, window)
}

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

	title := getPageTitleCentered("Settings - Host Messages")

	backButton := getBackButtonCentered(previousPage)

	description1 := getLabelCentered("Enable this mode if you are willing to host messages.")
	description2 := getLabelCentered("Messsages are encrypted and their contents are unknown until they are reported.")
	description3 := getLabelCentered("Messages may contain unlawful and unruleful content.")
	description4 := getLabelCentered("Only enable this mode if you accept the legal liability of hosting messages.")
	description5 := getLabelCentered("Moderators can ban messages after they are publicly reported.")

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

		exists, hostMessagesStatus, err := mySettings.GetSetting("HostMessagesOnOffStatus")
		if (err != nil){ return "", err }
		if (exists == false){
			 return "Off", nil
		}
		if (hostMessagesStatus != "On" && hostMessagesStatus != "Off"){
			return "", errors.New("Invalid host messages status: " + hostMessagesStatus)
		}
		return hostMessagesStatus, nil
	}

	hostMessagesStatus, err := getCurrentHostMessagesStatus()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return	
	}

	currentStatusLabel := widget.NewLabel("Current Status:")
	currentStatusText := getBoldLabel(hostMessagesStatus)
	currentStatusRow := container.NewHBox(layout.NewSpacer(), currentStatusLabel, currentStatusText, layout.NewSpacer())

	getEnableDisableButton := func()fyne.Widget{
		
		if (hostMessagesStatus == "On"){
			disableButton := widget.NewButton("Disable", func(){
					err := mySettings.SetSetting("HostMessagesOnOffStatus", "Off")
					if (err != nil){
						setErrorEncounteredPage(window, err, currentPage)
						return
					}
					currentPage()
				})
			return disableButton
		}
	
		enableButton := widget.NewButton("Enable", func(){
				setConfirmEnableHostMessagesPage(window, currentPage, currentPage)
			})
		return enableButton
	}

	enableDisableButton := getEnableDisableButton()
	enableDisableButtonCentered := getWidgetCentered(enableDisableButton)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, widget.NewSeparator(), currentStatusRow, enableDisableButtonCentered)

	setPageContent(page, window)
}

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

	title := getPageTitleCentered("Confirm Enable Host Messages Mode")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Enable Host Messages Mode?")

	description2 := getLabelCentered("In this mode, you will download and serve Seekia messages.")
	description3 := getLabelCentered("Messages are encrypted and may contain illegal and rulebreaking content.")
	description4 := getLabelCentered("Unruleful messages should be banned upon being reported and reviewed by moderators.")
	description5 := getLabelCentered("You must accept all legal risks associated with the hosting of these messages.")

	enableButton := getWidgetCentered(widget.NewButtonWithIcon("Enable", theme.ConfirmIcon(), func(){
			err := mySettings.SetSetting("HostMessagesOnOffStatus", "On")
			if (err != nil){
				setErrorEncounteredPage(window, err, previousPage)
				return
			}
			nextPage()
		}))
	
	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, enableButton)

	setPageContent(page, window)
}

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

	title := getPageTitleCentered("Settings - Host Over Clearnet")

	backButton := getBackButtonCentered(previousPage)

	description1 := getLabelCentered("Enable this mode if you are willing to host over clearnet.")
	description2 := getLabelCentered("This will expose your IP address to Seekia peers.")
	description3 := getLabelCentered("Clearnet is faster than Tor and is recommended for most hosts.")
	description4 := getLabelCentered("In this mode, use a VPN to hide your true IP address from Seekia peers.")

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

		exists, hostOverClearnetStatus, err := mySettings.GetSetting("HostOverClearnetOnOffStatus")
		if (err != nil){ return "", err }
		if (exists == false){
			return "Off", nil
		}
		if (hostOverClearnetStatus != "On" && hostOverClearnetStatus != "Off"){
			return "", errors.New("Invalid host over clearnet status: " + hostOverClearnetStatus)
		}
		return hostOverClearnetStatus, nil
	}

	hostOverClearnetStatus, err := getCurrentHostOverClearnetStatus()
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return	
	}

	currentStatusLabel := widget.NewLabel("Current Status:")
	currentStatusText := getBoldLabel(hostOverClearnetStatus)
	currentStatusRow := container.NewHBox(layout.NewSpacer(), currentStatusLabel, currentStatusText, layout.NewSpacer())

	getEnableDisableButton := func()fyne.Widget{

		if (hostOverClearnetStatus == "On"){
			disableButton := widget.NewButton("Disable", func(){
					setConfirmDisableHostOverClearnetPage(window, currentPage, currentPage)
				})
			return disableButton
		}

		enableButton := widget.NewButton("Enable", func(){
				setConfirmEnableHostOverClearnetPage(window, currentPage, currentPage)
			})
		return enableButton
	}

	enableDisableButton := getEnableDisableButton()
	enableDisableButtonCentered := getWidgetCentered(enableDisableButton)

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, widget.NewSeparator(), currentStatusRow, enableDisableButtonCentered)

	setPageContent(page, window)
}


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

	title := getPageTitleCentered("Enable Host Over Clearnet")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Enable Host Over Clearnet?")

	description2 := getLabelCentered("In this mode, you will host content over clearnet.")
	description3 := getLabelCentered("This will expose your IP address.")
	description4 := getLabelCentered("Use a VPN to shield your true IP address.")
	description5 := getLabelCentered("Anything you already hosted could be linked to your IP address.")
	description6 := getLabelCentered("Create a new host identity to cut ties with your hosting history.")

	enableButton := getWidgetCentered(widget.NewButtonWithIcon("Enable", theme.ConfirmIcon(), func(){
			err := mySettings.SetSetting("HostOverClearnetOnOffStatus", "On")
			if (err != nil){
				setErrorEncounteredPage(window, err, previousPage)
				return
			}
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, description6, enableButton)

	setPageContent(page, window)
}

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

	title := getPageTitleCentered("Disable Host Over Clearnet")

	backButton := getBackButtonCentered(previousPage)

	description1 := getBoldLabelCentered("Disable Host Over Clearnet?")

	description2 := getLabelCentered("If you disable this, you will stop hosting over clearnet.")
	description3 := getLabelCentered("Your Host identity will not change.")
	description4 := getLabelCentered("Your clearnet IP address is already associated with your host identity.")
	description5 := getLabelCentered("Your IP address could be linked to anything you hosted or will host in the future.")
	description6 := getLabelCentered("To cut all ties with your old IP address, create a new Host identity.")

	disableButton := getWidgetCentered(widget.NewButtonWithIcon("Disable", theme.ConfirmIcon(), func(){
			err := mySettings.SetSetting("HostOverClearnetOnOffStatus", "Off")
			if (err != nil){
				setErrorEncounteredPage(window, err, previousPage)
				return
			}
			nextPage()
		}))

	page := container.NewVBox(title, backButton, widget.NewSeparator(), description1, description2, description3, description4, description5, description6, disableButton)

	setPageContent(page, window)
}


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

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

	title := getPageTitleCentered("Build Host Profile")

	backButton := getBackButtonCentered(previousPage)

	description1 := getLabelCentered("Build your host profile.")
	description2 := getLabelCentered("All information is optional.")	

	usernameButton := widget.NewButton("Username", func(){
			setBuildProfilePage_Username(window, "Host", currentPage)
		})

	avatarButton := widget.NewButton("Avatar", func(){
			setBuildProfilePage_Avatar(window, "Host", currentPage)
		})

	descriptionButton := widget.NewButton("Description", func(){
			setBuildProfilePage_Description(window, "Host", currentPage)
		})

	profileLanguageButton := widget.NewButton(translate("Profile Language"), func(){
			setBuildProfilePage_ProfileLanguage(window, "Host", currentPage)
		})

	buttonsGrid := getContainerCentered(container.NewGridWithColumns(1, usernameButton, avatarButton, descriptionButton, profileLanguageButton))

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


func setViewHostDetailsPage(window fyne.Window, hostIdentityHash [16]byte, previousPage func()){

	//TODO: A page to view info about a host
	// This will be seperate from the host's profile. We should show a ViewProfile button on this page
	// We should also show a Peer Actions button
	// We need this page because a Host's profile may not exist, or is unviewable

	showUnderConstructionDialog(window)
}


