
package gui

// syncGui.go implements pages to manage the app connection to the Seekia network

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

import "seekia/internal/appMemory"

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

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

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

	title := getPageTitleCentered("Sync")

	backButton := getBackButtonCentered(previousPage)

	syncDescription := getLabelCentered("Manage your connection to the Seekia network.")

	settingsIcon, err := getFyneImageIcon("Settings")
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	settingsButton := widget.NewButton(translate("Settings"), func(){
			setManageNetworkSettingsPage(window, currentPage)
		})
	settingsButtonWithIcon := container.NewGridWithColumns(1, settingsIcon, settingsButton)

	logsIcon, err := getFyneImageIcon("Choice")
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	logsButton := widget.NewButton(translate("Logs"), func(){
			setViewLogsPage(window, "Network", currentPage)
		})
	logsButtonWithIcon := container.NewGridWithColumns(1, logsIcon, logsButton)

	peersIcon, err := getFyneImageIcon("Host")
	if (err != nil){
		setErrorEncounteredPage(window, err, previousPage)
		return
	}
	peersButton := widget.NewButton(translate("Peers"), func(){
			//TODO
			// This should show a page where we can view all connected peers
			// It should show a display similar to a torrenting client, where we can see information such as
			//		how much data has been uploaded/downloaded from each peer and the IP of each peer
			showUnderConstructionDialog(window)
		})
	peersButtonWithIcon := container.NewGridWithColumns(1, peersIcon, peersButton)

	buttonsRow := getContainerCentered(container.NewGridWithRows(1, settingsButtonWithIcon, logsButtonWithIcon, peersButtonWithIcon))

	/*
	//TODO
 	syncOnOffStatus := "Off"

	syncOnOffStatusTitle := widget.NewLabel("Sync Status:")
	syncOnOffStatusLabel := getBoldLabel(syncOnOffStatus)

	// We show a button to start and stop the client's connection to the network
	// This is useful for users who want to use Seekia in offline-only mode
	// This way, Seekia will not connect to any servers, and the user can use the app for offline activities such as analyzing genomes
	getStartStopSyncButton := func() fyne.Widget{
		if (syncOnOffStatus == "Off"){
			startButton := widget.NewButtonWithIcon(translate("Start"), theme.MediaPlayIcon(), func(){
				//TODO
				currentPage()
			})
			return startButton
		}
		stopButton := widget.NewButtonWithIcon(translate("Stop"), theme.MediaStopIcon(), func(){
			//TODO
			currentPage()
		})
		return stopButton
	}

	startStopSyncButton := getStartStopSyncButton()

	syncStartStopRow := container.NewHBox(layout.NewSpacer(), syncOnOffStatusTitle, syncOnOffStatusLabel, startStopSyncButton, layout.NewSpacer())
	*/

	description1 := getLabelCentered("Seekia is under construction.")
	description2 := getLabelCentered("The app is unable to connect to other peers.")

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

	setPageContent(page, window)
}


func setManageNetworkConnectionPage(window fyne.Window, previousPage func()){
	
	title := getPageTitleCentered("Manage Network Connection")

	backButton := getBackButtonCentered(previousPage)

	description := getBoldLabelCentered("Under Construction")

	//TODO: This page should show information about the network connection
	// The user should be able to see if the app is currently able to connect to other peers over Tor and clearnet
	// They should also see a realtime description of how much data is being uploaded and downloaded in megabytes per second

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

	setPageContent(page, window)
}



