package hud

import (
	"image/color"

	"github.com/hajimehoshi/ebiten/v2"

	"github.com/atridad/LilGuy/internal/status"
)

type Overlay struct {
	X     int
	Y     int
	Color color.Color
}

func (o Overlay) Draw(screen *ebiten.Image, meters []status.Meter) {
	if o.Color == nil {
		o.Color = color.White
	}

	instructions := Column{
		Elements: []Element{
			Label{Text: "Lil Guy", Color: o.Color},
			Label{Text: "Move with Arrow Keys / WASD", Color: o.Color},
			Label{Text: "Hold Shift to Sprint", Color: o.Color}},
		Spacing: 7,
	}
	instructions.Draw(screen, 16, 16)

	meterElements := make([]Element, 0, len(meters))
	for _, meter := range meters {
		if meter.Base < 0 {
			meterElements = append(meterElements,
				MeterLabel{Meter: meter, Color: o.Color},
			)
		} else {
			meterElements = append(meterElements, Column{
				Elements: []Element{
					MeterLabel{Meter: meter, Color: o.Color},
					Bar{Meter: meter, MaxWidth: 180, Height: 8, ShowBorder: false},
				},
				Spacing: 2,
			})
		}
	}

	meterPanel := Column{
		Elements: meterElements,
		Spacing:  16,
	}
	meterPanel.Draw(screen, o.X, o.Y)
}
