extends Window

var quest : Quest
signal quest_accepted()

func setup(qst : Quest, board : bool) -> void:
	quest = qst
	quest.status_changed.connect(_on_quest_status_changed)
	%NameField.text = quest.name
	%DifficultyField.text = quest.difficulty_name()
	%LocationField.text = quest.location
	if !board:
		%AcceptButton.hide()

	if quest.is_taken():
		%StatusField.text = "Taken"
		%AcceptButton.disabled = true
	else:
		%StatusField.text = "OPEN"
		%AcceptButton.disabled = false


func _on_quest_status_changed(status : Quest.Status) -> void:
	if status == Quest.Status.COMPLETED:
		queue_free()
	if quest.is_taken():
		%StatusField.text = "Taken"
		%AcceptButton.disabled = true
	else:
		%StatusField.text = "OPEN"
		%AcceptButton.disabled = false

func _on_accept_pressed() -> void:
	Guild.assign_quest(Game.player.data, quest)
	quest_accepted.emit()
	queue_free()

func _on_close_button_pressed() -> void:
	queue_free()
