package maps

import (
	"image/color"

	"github.com/atridad/LilGuy/internal/config"
	"github.com/atridad/LilGuy/internal/portal"
	"github.com/atridad/LilGuy/internal/world"
)

func CreatePlains(screenWidth, screenHeight float64) *Map {
	m := NewMap("plains", 1, "Plains", screenWidth, screenHeight)
	m.BackgroundColor = color.NRGBA{R: 135, G: 206, B: 235, A: 255}
	m.Lighting = LightConfig{
		AmbientBrightness: 0.3,
		Sources: []LightSource{
			{
				X:              screenWidth - 80,
				Y:              80,
				Radius:         600,
				Color:          color.RGBA{R: 255, G: 250, B: 220, A: 255},
				Intensity:      0.7,
				ShadowDarkness: 0.5,
			},
		},
	}

	// ground surface
	groundColor := color.NRGBA{R: 34, G: 139, B: 34, A: 255}
	m.World.AddSurface(&world.Surface{
		X:      0,
		Y:      screenHeight - config.GroundHeight,
		Width:  screenWidth,
		Height: config.GroundHeight,
		Tag:    world.TagGround,
		Color:  groundColor,
	})

	// Platforms
	// Use ground color by default as requested
	platformColor := groundColor

	// Platform 1: Low left
	m.World.AddSurface(&world.Surface{
		X:      100,
		Y:      screenHeight - 120,
		Width:  150,
		Height: 20,
		Tag:    world.TagPlatform,
		Color:  platformColor,
	})

	// Platform 2: Mid center
	m.World.AddSurface(&world.Surface{
		X:      350,
		Y:      screenHeight - 200,
		Width:  200,
		Height: 20,
		Tag:    world.TagPlatform,
		Color:  platformColor,
	})

	// Platform 3: High right
	m.World.AddSurface(&world.Surface{
		X:      650,
		Y:      screenHeight - 280,
		Width:  150,
		Height: 20,
		Tag:    world.TagPlatform,
		Color:  platformColor,
	})

	// left portal to desert
	leftPortal := portal.CreateSidePortal("plains_left", portal.SideLeft, screenWidth, screenHeight)
	leftPortal.DestinationMap = "desert"
	leftPortal.DestinationPortal = "desert_right"
	leftPortal.Color = color.NRGBA{R: 255, G: 100, B: 100, A: 180}
	leftPortal.GlowColor = color.NRGBA{R: 255, G: 150, B: 150, A: 100}
	m.AddPortal(leftPortal)

	// right portal to desert
	rightPortal := portal.CreateSidePortal("plains_right", portal.SideRight, screenWidth, screenHeight)
	rightPortal.DestinationMap = "desert"
	rightPortal.DestinationPortal = "desert_left"
	rightPortal.Color = color.NRGBA{R: 100, G: 255, B: 100, A: 180}
	rightPortal.GlowColor = color.NRGBA{R: 150, G: 255, B: 150, A: 100}
	m.AddPortal(rightPortal)

	return m
}
