extends Node

class_name InventoryMenu


@onready var inventory : Inventory
@onready var item_list : VBoxContainer =  $CanvasLayer/PanelContainer/VBoxContainer/MarginContainer/ScrollContainer/VBoxContainer
var item_scene : PackedScene = preload("res://Scenes/Menu/InventoryUiItem.tscn")

func _ready() -> void:
	$CanvasLayer.hide()
	pass


func toggle_inventory() -> bool:
	var canvas = $CanvasLayer
	if canvas.visible == true:
		$CanvasLayer.hide()
		return false
	else:
		update_inventory()
		$CanvasLayer.show()
		return true

func update_inventory():
	for i in inventory.items:
		var match_found : bool = false
		var new_item = item_scene.instantiate()
		for j in item_list.get_children():
			if j.id.text != str(i.item.id):
				match_found = true
		if !match_found || item_list.get_children().size() == 1:
			item_list.add_child(new_item)
			new_item.set_values(i.item.id, i.item.name, 10, 10)
