// A simple TUI application that charts latency times to specified hosts.
//
// TODO(main): determine chart heights dynamically by number of addresses
//
// TODO(performance): implement ping message channel buffering
//
//	i.e, change the address title to red so long as there is a single -1 in
//	the display buffer, and a toast notification (???) if a display buffer is
//	entirely composed of -1
package main

import (
	"flag"
	"fmt"
	"os"
	"pingo/internal/tui"
	"time"

	tea "github.com/charmbracelet/bubbletea"
)

func main() {
	speed := flag.Int("s", 80, "the speed with which the UI runs")
	chartHeight := flag.Int("h", 0,
		"the height of the latency chart. set to 0 to render charts full screen.")
	flag.Parse()
	hosts := flag.Args()

	if len(hosts) == 0 {
		fmt.Println("Must specify hosts!")
		return
	}
	var model = tui.InitialModel(
		hosts, time.Duration(*speed), *chartHeight,
	)

	p := tea.NewProgram(model,
		tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"
		// tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
	)

	if _, err := p.Run(); err != nil {
		fmt.Printf("Alas, there's been an error: %v", err)
		os.Exit(1)
	}
}
