from tkinter import ttk

from .. import config
from .. import display
from ..game import level

from . import tk_util



def main_gui():
	window = ttk.Frame( display.tkroot, padding=5 )
	window.grid()

	def on_done( lvl_num_:int ):
		nonlocal lvl_num
		lvl_num = lvl_num_
		display.tkroot.event_generate("<Escape>")

	for k, name in enumerate( level.Level.load_names() ):
		lvl_num = k + 1

		btn = tk_util.Button(
			window, f"{lvl_num}: {name}", lambda lvl_num=lvl_num: on_done(lvl_num), True
		)
		btn.set_grid( 0,k, sticky="wesn" )
		if lvl_num > config.level_max:
			btn.set_enabled(False)

	lvl_num = -1

	display.tk_main(window.destroy)

	return lvl_num
