package main

import (
	"fmt"

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

type levelSelect struct {
	alui.Menu

	ctx *Context

	packID string
	pack   levelPack
}

func (s *levelSelect) Enter(ctx *Context) error {
	s.ctx = ctx
	s.pack = s.ctx.Levels[s.packID]
	s.Init()
	name := func(i int, steps int) string {
		if steps == 0 {
			return fmt.Sprintf("Level %d", i)
		}
		return fmt.Sprintf("Level %d (%d)", i, steps)
	}
	for i, id := range s.pack.order {
		levelID := id
		s.Add(name(i+1, s.ctx.Progress.Level(s.packID, levelID).Steps), func() {
			s.ctx.Navigation.PlayLevel(s.packID, levelID)
		})
	}
	s.Add("Back to main menu", func() { s.ctx.Navigation.ShowMainMenu() })
	return nil
}

func (s *levelSelect) Leave() {}
