package geom

import (
	"image/color"

	"github.com/hajimehoshi/ebiten/v2"
)

var GrayFill = color.RGBA{R: 128, G: 128, B: 128, A: 255}
var RedFill = color.RGBA{R: 200, G: 0, B: 0, A: 255}
var GreenFill = color.RGBA{R: 0, G: 200, B: 0, A: 255}
var BlueFill = color.RGBA{R: 0, G: 0, B: 200, A: 255}
var LightRedFill = color.RGBA{R: 255, G: 104, B: 103, A: 255}
var LightGreenFill = color.RGBA{R: 144, G: 255, B: 143, A: 255}
var LightBlueFill = color.RGBA{R: 150, G: 150, B: 255, A: 255}

var RGBColourMap = map[int]color.Color{
	0: RedFill,
	1: GreenFill,
	2: BlueFill,
}

var AllColourMap = map[int]color.Color{
	0: GrayFill,
	1: RedFill,
	2: GreenFill,
	3: BlueFill,
	4: LightRedFill,
	5: LightBlueFill,
	6: LightGreenFill,
}

var LightRGBMap = map[int]color.Color{
	0: LightRedFill,
	1: LightGreenFill,
	2: LightBlueFill,
}

type Square struct {
	x              int
	y              int
	clr            color.Color
	width          int
	height         int
	Img            *ebiten.Image
	RGBColourIndex int
}

func MakeSquare(size int) Square {
	image := ebiten.NewImage(size, size)
	defaultColor := color.RGBA{R: 128, G: 128, B: 128, A: 255}
	image.Fill(defaultColor)
	sq := Square{clr: defaultColor, Img: image, width: size, height: size, x: 0, y: 0, RGBColourIndex: -1}
	return sq
}

func (sq *Square) ChangeColour(newColor color.Color) {
	sq.clr = newColor
	sq.Img.Fill(newColor)
}

func (sq *Square) SetPosition(x int, y int) {
	sq.x = x
	sq.y = y
}

func (sq *Square) X() int {
	return sq.x
}

func (sq *Square) Y() int {
	return sq.y
}

func (sq *Square) moveRightOnGrid() {
	newX := sq.x + GameGrid.squareSize + GameGrid.squareSpacing
	sq.x = newX
}

func (sq *Square) moveLeftOnGrid() {
	newX := sq.x - GameGrid.squareSize - GameGrid.squareSpacing
	sq.x = newX
}

func (sq *Square) moveDownOnGrid() {
	newY := sq.y + GameGrid.squareSize + GameGrid.squareSpacing
	sq.y = newY
}

func (sq *Square) moveUpOnGrid() {
	newY := sq.y - GameGrid.squareSize - GameGrid.squareSpacing
	sq.y = newY
}
