package main

import 	(
	"go.wit.com/log"
	"go.wit.com/gui/gui"
)


func globalResetOptions(box *gui.Node) {
	group2 := box.NewGroup("Global Destructive Options")
	buildOptions := group2.NewGrid("buildOptions",2, 1)

	buildOptions.NewLabel("global path reset")
	// to globally reset paths:
	// gofmt -w -r "go.wit.com/gui -> go.wit.com/gui/gui" .
	buildOptions.NewButton("Find", func () {
		log.Warn("delete every repo marked PERFECT")
		var newCmds [][]string
		for _, repo := range allrepos {
			status := repo.getStatus()
			if status == "PERFECT" {
				var line []string
				line = append(line, "rm", "-rf",  "go/src/" + repo.path)
				newCmds = append(newCmds, line)
			}
		}
		me.script = newCmds
		doit.Enable()
		setGitCommands()
	})

	buildOptions.NewLabel("delete PERFECT")
	buildOptions.NewButton("Find", func () {
		log.Warn("delete every repo marked PERFECT")
		var newCmds [][]string
		for _, repo := range allrepos {
			status := repo.getStatus()
			if status == "PERFECT" {
				var line []string
				line = append(line, "rm", "-rf",  "go/src/" + repo.path)
				newCmds = append(newCmds, line)
			}
		}
		me.script = newCmds
		doit.Enable()
		setGitCommands()
	})

	buildOptions.NewLabel("start over")
	buildOptions.NewButton("rm ~/go/src & ~/go/pkg", func () {
		var newCmds [][]string
		var dirty bool = false
		for _, repo := range allrepos {
			status := repo.getStatus()
			if status == "dirty" {
				dirty = true
				break
			}
		}
		newCmds = append(newCmds, []string{"cd", "."})
		newCmds = append(newCmds, []string{"rm", "-rf", "go/src/"})
		newCmds = append(newCmds, []string{"chmod", "700", "-R", "go/pkg/"})
		newCmds = append(newCmds, []string{"rm", "-rf", "go/pkg/"})
		if dirty {
			newCmds = append(newCmds, []string{"can't do this with dirty repos"})
			doit.Disable()
		} else {
			doit.Enable()
		}
		me.script = newCmds
		setGitCommands()
	})

	buildOptions.NewLabel("rebuild autotypist")
	buildOptions.NewButton("go get", func () {
		var newCmds [][]string
		newCmds = append(newCmds, []string{"cd", "."})
		newCmds = append(newCmds, []string{"mkdir", "-p", "go/src/go.wit.com/apps/"})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/"})
		newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "go.wit.com/apps/myrepos"})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
		newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
		newCmds = append(newCmds, []string{"go", "get", "-v", "go.wit.com/gui/toolkits"})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits/andlabs"})
		newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits/gocui"})
		newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits"})
		newCmds = append(newCmds, []string{"make"})
		newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
		newCmds = append(newCmds, []string{"make"})
		me.script = newCmds
		setGitCommands()
		doit.Enable()
	})

	buildOptions.NewSeparator("endStatusScans")
	buildOptions.NewSeparator("endStatusScans")

	buildOptions.NewLabel("cmd")
	cmds = buildOptions.NewLabel("ls")

	buildOptions.NewLabel("--dry-run")
	dryrun = buildOptions.NewButton("show commands", func () {
		if goMake("--dry-run") {
			log.Warn("EVERYTHING MIGHT HAVE WORKED")
		} else {
			log.Warn("EVERYTHING WILL NOT WORK")
			dryrun.Disable()
		}
	})

	buildOptions.NewLabel("Doit")
	doit = buildOptions.NewButton("run commands", func () {
		doit.Disable()
		log.Warn("should run the commands here")
		// true here means dryrun == true. it's confusingly named
		if goMake("--doit") {
			log.Warn("EVERYTHING WORKED")
		} else {
			log.Warn("EVERYTHING DID NOT WORK")
		}
	})
}
