package main

import (
	"fmt"
	"math/rand"
	"strings"
	"time"

	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

var items []string

func main() {
	app := app.New()
	win := app.NewWindow("Wheel of Fortune")

	inputEntry := widget.NewEntry()
	inputEntry.SetPlaceHolder("Enter items separated by commas")

	spinButton := widget.NewButton("Spin", spinWheel)
	resultLabel := widget.NewLabel("")

	content := container.NewVBox(
		inputEntry,
		spinButton,
		resultLabel,
	)

	win.SetContent(content)
	win.Resize(fyne.NewSize(300, 150))
	win.ShowAndRun()
}

func spinWheel() {
	inputText := strings.TrimSpace(items[0])
	if inputText == "" {
		return
	}

	items = strings.Split(inputText, ",")

	rand.Seed(time.Now().UnixNano())
	randomIndex := rand.Intn(len(items))
	selectedItem := items[randomIndex]

	fmt.Println(selectedItem)
}
