extends Control

var label: Array[RichTextLabel]
var q_and_a_id: Array[int]
var qty: Array[int]

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	label = [$qty1, $qty2, $qty3, $qty4, $qty5, $qty6]
	reset_qty()
	set_id()


func set_id() -> void:
	q_and_a_id.resize(6)
	for i in range(q_and_a_id.size()):
		q_and_a_id[i] = randi_range(1, data.q_and_a["q"].size() - 1)


func reset_qty() -> void:
	qty.resize(6)
	qty.fill(0);


func set_qty(type: int, isAdd: bool) -> void:
	if isAdd:
		qty[type] += 1
	else:
		qty[type] -= 1
	if qty[type] < 0:
		qty[type] = 0


func set_correct(index: int) -> void:
	label[index].text = "[center]" + data.q_and_a["q"][q_and_a_id[index]] + "[color=green][b]%d[/b][/color]" % qty[index] + "[/center]"


func set_wrong(index: int) -> void:
	label[index].text = "[center]" + data.q_and_a["q"][q_and_a_id[index]] + "[color=red][b]%d[/b][/color]" % qty[index] + "\n[color=green][b]" + data.q_and_a["a"][q_and_a_id[index]] + "[/b][/color][/center]"


func set_label() -> void:
	for i in range(label.size()):
		label[i].text = "[center]" + data.q_and_a["q"][q_and_a_id[i]] + "[b]%d[/b]" % qty[i] + "[/center]"
