# Hurry Curry! - a game about cooking
# Copyright (C) 2026 Hurry Curry! Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
extends Menu
class_name MapSelector

const MAP_LIST_ITEM = preload("res://gui/menus/map_selector/map_list_item.tscn")

@onready var map_container: VBoxContainer = $OuterMargin/Panel/InnerMargin/VBoxContainer/ScrollContainer/VBoxContainer

func _ready() -> void:
	var maps: Array = data[0]
	for m in maps:
		var item: MapListItem = MAP_LIST_ITEM.instantiate()
		item.name = m["name"]
		map_container.add_child(item)
		item.setup(m["display_name"], int(m["difficulty"]), int(m["players"]))
		item.button.pressed.connect(select_map.bind(m))
	super()

func select_map(map):
	var algos: Array = data[1]
	var success = await submenu("res://gui/menus/map_selector/map_details_selector.tscn", [map, algos])
	if success: exit()

func _menu_cover(state: bool):
	# TODO: Find a better way to hide this menu without hiding submenu, this feels hacky
	$OuterMargin.visible = not state

func _on_back_pressed() -> void:
	exit()
