class_name MenuBase
extends Control

signal menu_opened
signal menu_closed

@export var focus_node: Control

var previous_menu: MenuBase


func open_menu(last_menu: MenuBase = previous_menu) -> void:
	show()

	if is_instance_valid(last_menu):
		previous_menu = last_menu
		last_menu.hide()
		menu_opened.emit()

	if is_instance_valid(focus_node):
		focus_node.grab_focus()


func close_menu() -> void:
	hide()

	if is_instance_valid(previous_menu):
		previous_menu.open_menu()
		previous_menu = null
		menu_closed.emit()
