package fonts

import (
	"errors"
	"fmt"
	"image/color"
)

type Font map[string][][]byte

var (
	ErrCharNotFound = errors.New("unrecognized character")
)

func (f Font) ToColor(char string, c color.RGBA) ([][]color.RGBA, error) {
	bitmap, found := f[char]
	if !found {
		return nil, fmt.Errorf("%w: %s", ErrCharNotFound, char)
	}

	colorMappedChar := make([][]color.RGBA, 0, len(bitmap))
	for _, row := range bitmap {
		crow := make([]color.RGBA, 0, len(row))
		for _, pixel := range row {
			crowColor := c
			crowColor.R = crowColor.R * pixel
			crowColor.G = crowColor.G * pixel
			crowColor.B = crowColor.B * pixel
			crowColor.A = 0xff * pixel
			crow = append(crow, crowColor)
		}

		colorMappedChar = append(colorMappedChar, crow)
	}

	return colorMappedChar, nil
}

var (
	White = color.RGBA{
		R: 255, G: 255, B: 255, A: 255,
	}
	Black = color.RGBA{
		R: 0, G: 0, B: 0, A: 255,
	}
	DarkGrey = color.RGBA{
		R: 70, G: 70, B: 70, A: 255,
	}
	Green = color.RGBA{
		R: 34, G: 177, B: 76, A: 255,
	}
	Orange = color.RGBA{
		R: 255, G: 126, B: 0, A: 255,
	}
	Red = color.RGBA{
		R: 153, G: 0, B: 48, A: 255,
	}
	Blue = color.RGBA{
		R: 0, G: 183, B: 239, A: 255,
	}
)
