extends Control
class_name PlaceableUI

@onready var texture_rect_icon: TextureRect = $Button/TextureRectIcon
@onready var label_quantity: Label = $LabelQuantity
@onready var button: Button = $Button

@export var placeable_item: PlaceableData
@export var quantity: int = 1:
	set(value):
		quantity = value
		update_ui()

func _ready():
	if quantity == 0:
		# Quantity in the beginning is 0 -> Item should not be available in the level
		self.hide()
		return
	
	update_ui()

func update_ui():
	if placeable_item == null or texture_rect_icon == null:
		return
	
	
	texture_rect_icon.texture = placeable_item.icon
	label_quantity.text = str(quantity) + "x"
	if quantity <= 0:
		button.disabled = true

func _on_button_pressed():
	if quantity <= 0:
		return
	(GameConstants.get_placeable_manager() as PlaceableManager).activate_place_mode(self)


