//go:build pybadge
// +build pybadge

package main

import (
	"image/color"
	"time"

	"tinygo.org/x/tinyfont"
	"tinygo.org/x/tinyfont/freesans"

	qrcode "github.com/skip2/go-qrcode"
)

func Info() {
	qr, err := qrcode.New("https://tinygo.org", qrcode.Medium)
	if err != nil {
		println(err, 123)
	}

	qrbytes := qr.Bitmap()
	size := int16(len(qrbytes))

	factor := int16(displayHeight / len(qrbytes))

	bx := (displayWidth - size*factor) / 2
	by := (displayHeight - size*factor) / 2
	display.FillScreen(color.RGBA{109, 0, 140, 255})
	for y := int16(0); y < size; y++ {
		for x := int16(0); x < size; x++ {
			if qrbytes[y][x] {
				display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorBlack)
			} else {
				display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorWhite)
			}
		}
	}

	tinyfont.WriteLine(&display, &freesans.Bold9pt7b, 5, 12, "SCAN ME", colorWhite)

	for {
		time.Sleep(100 * time.Millisecond)
		getInput()
		if goBack() {
			quit = true
			return
		}
	}
}
