class_name QuestLogEntry extends Panel

var quest : Quest = null
@onready var icon : TextureRect = %Icon
@onready var name_label : Label = %NameLabel
@onready var status_label : Label = %StatusLabel

func setup(quest : Quest) -> void:
	self.quest = quest
	name_label.text = quest.name
	status_label.text = "Available" if !quest.taken else "Unavailable"
	quest.status_changed.connect(_on_quest_status_changed)

func update() -> void:
	status_label.text = "Available" if !quest.taken else "Unavailable"

func _on_quest_status_changed(status : Quest.Status) -> void:
	match(status):
		Quest.Status.OPEN: status_label.text = "Available"
		Quest.Status.COMPLETED: queue_free()
		_: status_label.text = "Unavailable"
