extends MarginContainer


@export var highlight_panel: PanelContainer
@export var icon: TextureRect
@export var name_label: RichTextLabel
@export var amount_label: Label


func update_from_item(item: Item, show_amount: bool) -> void:
	icon.texture = item.icon
	name_label.text = "[center]%s[/center]" % item.name
	
	if item.stackable and show_amount:
		amount_label.text = "x%d" % item.amount
	else:
		amount_label.text = ""


func _on_focus_entered() -> void:
	const PANEL = preload("res://src/lib/item_box_highlight_panel.tres")
	highlight_panel.add_theme_stylebox_override("panel", PANEL)


func _on_focus_exited() -> void:
	highlight_panel.add_theme_stylebox_override("panel", StyleBoxEmpty.new())


func _on_gui_input(event: InputEvent) -> void:
	# ignore mouse clicks for focus, it's only for mouseless gameplay
	if event is InputEventMouseButton:
		release_focus()
