package main

import (
	"opslag.de/schobers/allg5"

	"opslag.de/schobers/krampus19/alui"
)

type levelPackSelect struct {
	alui.Menu

	ctx *Context
}

func (s *levelPackSelect) Enter(ctx *Context) error {
	s.ctx = ctx
	s.Init()
	s.AddChild(newHeader("Select a level pack"))
	for _, id := range s.ctx.Levels.order {
		var copy = id
		s.Add(s.ctx.Levels.ByID(id).name, func() {
			s.ctx.Navigation.SelectLevel(copy)
		})
	}
	s.Add("Back to main menu", func() { s.ctx.Navigation.ShowMainMenu() })
	return nil
}

func (s *levelPackSelect) Handle(e allg5.Event) {
	switch e := e.(type) {
	case *allg5.KeyDownEvent:
		switch e.KeyCode {
		case allg5.KeyEscape:
			s.ctx.Navigation.ShowMainMenu()
		}
	}
	s.Menu.Handle(e)
}

func (s *levelPackSelect) Leave() {}
