// **********************************
// * pipewire buffersize and sample *
// * rate setup                     *
// * ------------------------------ *
// * (c) by THS 2026                *
// **********************************

package main

import (
	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

type PWSetup struct {
	samplerate string
	buffersize string
}

var pwsetup PWSetup

func main() {
	app := tview.NewApplication()
	pages := tview.NewPages()

	text := tview.NewTextView().
		SetTextColor(tcell.ColorGreen).
		SetText("Samplerate: " + pwsetup.samplerate)

	form := tview.NewForm().
		AddDropDown("SampleRate: ", []string{"44100", "48000", "96000"}, 0, func(option string, index int) {
			pwsetup.samplerate = option
		}).
		AddDropDown("Buffer    : ", []string{"64", "128", "256", "512", "1024", "2048"}, 0, func(option string, index int) {
			pwsetup.buffersize = option
		}).
		AddTextView("Notes", "Set sample rate and buffersize for Pipewire", 40, 2, true, false).
		AddButton("Set", func() {
			text.SetText("SampleRate: " + pwsetup.samplerate)
			pages.SwitchToPage("result")
		}).
		AddButton("Quit", func() {
			app.Stop()
		})

	form.SetBorder(true).SetTitle(" Pipewire setup ").SetTitleAlign(tview.AlignLeft)

	pages.AddPage("pwsetup", form, true, true)
	pages.AddPage("result", text, true, false)

	if err := app.SetRoot(pages, true).EnableMouse(true).EnablePaste(true).Run(); err != nil {
		panic(err)
	}
}
