package maps

import (
	"image/color"

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

func CreateDesert(screenWidth, screenHeight float64) *Map {
	m := NewMap("desert", 2, "Desert", screenWidth, screenHeight)
	m.BackgroundColor = color.NRGBA{R: 15, G: 20, B: 40, A: 255}
	m.Lighting = LightConfig{
		AmbientBrightness: 0.1,
		Sources: []LightSource{
			{
				X:              screenWidth - 80,
				Y:              80,
				Radius:         450,
				Color:          color.RGBA{R: 200, G: 220, B: 255, A: 255},
				Intensity:      0.5,
				ShadowDarkness: 0.7,
			},
		},
	}

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

	// Platforms - sandy brown color
	platformColor := color.NRGBA{R: 194, G: 134, B: 64, A: 255}

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

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

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

	// Platform 4: Mid right
	m.World.AddSurface(&world.Surface{
		X:      720,
		Y:      screenHeight - 140,
		Width:  140,
		Height: 20,
		Tag:    world.TagPlatform,
		Color:  platformColor,
	})

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

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

	return m
}
