package main

import (
	"log"

	"git.dvdt.dev/david/bitcoin-ticker-pi/display"
	"git.dvdt.dev/david/bitcoin-ticker-pi/fonts"
	rgbmatrix "git.dvdt.dev/david/bitcoin-ticker-pi/go-rpi-rgb-led-matrix"
)

func main() {
	cfg := rgbmatrix.DefaultConfig
	cfg.Rows = 32
	cfg.Cols = 64

	m, _ := rgbmatrix.NewRGBLedMatrix(&cfg)
	c := rgbmatrix.NewCanvas(m)

	d := display.New(c,
		display.NewSlot(9, 5, 4, 0, 0),
		display.NewSlot(5, 5, 4, 44, 0),
		display.NewSlot(7, 13, 8, 7, 7),
		display.NewSlot(12, 5, 4, 7, 27),
		display.NewSlot(8, 5, 4, 28, 27),
	)
	err := d.UpdateTopLeft([]display.Segment{
		{Text: "dollar", Color: fonts.Green},
		{Text: "4", Color: fonts.White},
		{Text: "2", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
	})
	if err != nil {
		log.Println(err)
	}

	err = d.UpdateTopRight([]display.Segment{
		{Text: "satoshi", Color: fonts.Orange},
		{Text: "2", Color: fonts.White},
		{Text: ".", Color: fonts.White},
		{Text: "5", Color: fonts.White},
		{Text: "K", Color: fonts.White},
	})
	if err != nil {
		log.Println(err)
	}

	err = d.UpdateCenter([]display.Segment{
		{Text: "height", Color: fonts.Blue},
		{Text: "8", Color: fonts.White},
		{Text: "2", Color: fonts.White},
		{Text: "1", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
	})
	if err != nil {
		log.Println(err)
	}

	err = d.UpdateBottomLeft([]display.Segment{
		{Text: "low", Color: fonts.Green},
		{Text: "1", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "medium", Color: fonts.Orange},
		{Text: "2", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "high", Color: fonts.Red},
		{Text: "3", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
	})
	if err != nil {
		log.Println(err)
	}

	err = d.UpdateBottomRight([]display.Segment{
		{Text: "1", Color: fonts.White},
		{Text: "2", Color: fonts.White},
		{Text: ":", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: ":", Color: fonts.White},
		{Text: "0", Color: fonts.White},
		{Text: "0", Color: fonts.White},
	})
	if err != nil {
		log.Println(err)
	}

	err = d.Render()
	if err != nil {
		log.Println(err)
	}

	select {}
}
