extends Control
class_name Victory

signal loot_selected(index: int)

@onready var animation: AnimationPlayer = $AnimationPlayer
@onready var loot_button_1: Button = $VBoxContainer/Loot1Button
@onready var loot_button_2: Button = $VBoxContainer/Loot2Button
@onready var loot_button_3: Button = $VBoxContainer/Loot3Button

var selection: int = -1

func _ready() -> void:
	animation.play("open")

func set_loot_options(opt1: String, opt2: String, opt3: String) -> void:
	loot_button_1.text = opt1
	loot_button_2.text = opt2
	loot_button_3.text = opt3

func close(selected_loot: int) -> void:
	selection = selected_loot
	animation.play("close")
	await animation.animation_finished
	loot_selected.emit(selected_loot)
	queue_free()

func _on_loot_1_button_pressed():
	close(0)

func _on_loot_2_button_pressed():
	close(1)

func _on_loot_3_button_pressed():
	close(2)
