extends Control

@onready var level_manager = $"/root/LevelManager"

@onready var picker = $"picker"

func _ready():
	open_picker()


func open_picker():
	
	self.picker.set_level_name(level_manager.selected_level)
	self.picker.save_button.hide()
	self.picker.load_button_label.text = "play"
	self.show_picker()

	self.picker.bind_success(self, "handle_picker_output")
	self.picker.bind_cancel(self, "back_to_menu")


	#self.level.camera_rig.navigation_enabled = false

func back_to_menu():
	self.get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")

	
func handle_picker_output(args):
	var level_name = args[0]
	var context = args[1]

	if context == "save":
		print ("there should be no save button in this menu xD")
		
	elif context == "load":
		LevelManager.selected_level = level_name
		self.get_tree().change_scene_to_file("res://scenes/game/game.tscn")

	
func show_picker():
	self.picker.show_picker()

