class_name TopMenu extends Control

const member_panel_entry_template = preload("res://templates/member_panel_entry.tscn")
const quest_panel_entry_template = preload("res://templates/quest_panel_entry.tscn")
const guild_info_window_template = preload("res://templates/guild_info_window.tscn")

@onready var members_list = %MembersList
@onready var members = %Members
@onready var quest_list = %QuestList
@onready var quests = %Quests
func _ready() -> void:
	Game.top_menu = self

func hide_submenus() -> void:
	members.visible = false
	quests.visible = false
	
func _on_members_button_pressed() -> void:
	if !members.visible:
		hide_submenus()
	members.visible = !members.visible
	for child in members_list.get_children():
		child.enabled = members.visible
			
func _on_quests_button_pressed() -> void:
	if !quests.visible:
		hide_submenus()
	quests.visible = !quests.visible
	for child in quest_list.get_children():
		child.enabled = quests.visible

func add_member(member : Adventurer) -> void:
	var entry = member_panel_entry_template.instantiate()
	entry.setup(member)
	members_list.add_child(entry)

func add_quest(quest : Quest) -> void:
	var entry = quest_panel_entry_template.instantiate()
	entry.setup(quest)
	quest_list.add_child(entry)


func _on_quest_generate_button_pressed() -> void:
	%GenerateQuestDialog.show()


func _on_guild_button_pressed() -> void:
	var wnd = guild_info_window_template.instantiate()
	add_child(wnd)
	wnd.popup_centered()
	wnd.grab_focus()
