extends Node2D

@onready var animations = $"animations"

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

@onready var replay_button = $"widgets/replay_button"
@onready var level_select_button = $"widgets/level_select_button"

@onready var main_menu_button = $"widgets/main_menu_button"


var game = null




func _ready():
	self.connect_buttons()
	
	self.set_process_input(false)


func execute_restart():
	game.restart()
	
	hide_level_done_screen()
	
func execute_main_menu():
	get_tree().paused = false
	self.get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")

func execute_level_menu():
	get_tree().paused = false
	self.get_tree().change_scene_to_file("res://scenes/ui/level_select_menu.tscn")
	


func show_level_done_screen():
	self.animations.play("show")
	get_tree().paused = true
	self.set_process_input(true)

	await self.get_tree().create_timer(0.1).timeout


	self.main_menu_button.grab_focus()



func hide_level_done_screen():
	self.animations.play("hide")
	get_tree().paused = false
	if game != null:
		game.on_pause_menu_closed()
	self.set_process_input(false)


	
func initialize(_game):
	game = _game
	

	

func connect_buttons():
	self.replay_button.connect("pressed", Callable(self, "execute_restart"))

	self.main_menu_button.connect("pressed", Callable(self, "execute_main_menu"))
	self.level_select_button.connect("pressed", Callable(self, "execute_level_menu"))







