// For fun.. Plot to the screen

package main

import (
	"fmt"
	"github.com/gizak/termui/v3/drawille"
	ui "github.com/gizak/termui/v3"
	"github.com/gizak/termui/v3/widgets"
	"image"
)

func breaker(x interface{}) {}
func scrnPlt(pi, stdErr []float32) error {
	ui.Theme.Plot.Axes = ui.ColorBlack
	thm := ui.Theme
	thm.Default = ui.NewStyle(ui.ColorBlack, ui.ColorWhite, ui.ModifierReverse)
	thm.Default.Fg = ui.ColorBlack
	thm.Default.Bg = ui.ColorWhite
	thm.Plot.Lines = []ui.Color{ui.ColorBlack}
	thm.Paragraph.Text = ui.NewStyle(ui.ColorBlack, ui.ColorWhite)
	ui.Theme = thm
	ptxt := widgets.NewParagraph()

	ptxt.Text = "Hello World!"
	ptxt.SetRect(0, 0, 25, 5)

	p1 := widgets.NewPlot()

	p1.Title = "π"
	{
		data := make([][]float64, 2)
		data[0] = make([]float64, len(pi))
		data[1] = make([]float64, len(pi))
		for i := range pi {
			data[0][i] = float64(i + 1)
			data[1][i] = float64(pi[i])
		}
		p1.Data = data
	}
	breaker(thm)
	p1.SetRect(5, 5, 80, 80)
	p1.AxesColor = ui.ColorBlack
	p1.LineColors = []ui.Color{ui.ColorRed}

	p1.Marker = widgets.MarkerBraille
	p1.PlotType = widgets.ScatterPlot
	//  next: syntax OK, just doesn't work
	r := image.Rectangle(image.Rect(0, 0, 100, 100))
	buf := ui.NewBuffer(r)

	cell := drawille.Cell{Color:7}
	fmt.Println (cell)
//	buf.Fill(cell, r)
	p1.Block.Draw(buf)

	if err := ui.Init(); err != nil {
		return fmt.Errorf("failed to initialize termui: %w", err)
	}
	defer ui.Close()

	ui.Render(p1, ptxt)
	for e := range ui.PollEvents() {
		if e.Type == ui.KeyboardEvent {
			break
		}
	}
	return nil
}