extends Control

@onready var v_box_container: VBoxContainer = $MarginContainer/PanelContainer/VBoxContainer

var timeline_rsc
var timelines : Array[RemnantTimeline]

func _ready() -> void:
	timeline_rsc = load("res://scenes/gui/in_game_gui/remnant_timelines/single_timeline.tscn")
	for i in range(PlayerVariables.max_number_of_remnants):
		var timeline = timeline_rsc.instantiate() as RemnantTimeline
		timelines.append(timeline)
		v_box_container.add_child(timeline)
		v_box_container.move_child(timeline, 0)
		if i > 0:
			timelines[i].timeline_marker.hide()
	hide()
	SignalBus.set_anchor.connect(show)
	SignalBus.anchor_ran_out.connect(hide)
	SignalBus.changed_remnant_timeline.connect(switch_timeline)

func _exit_tree() -> void:
	SignalBus.changed_remnant_timeline.disconnect(switch_timeline)

func switch_timeline(timeline_index : int):
	for i in range(PlayerVariables.max_number_of_remnants):
		if i == timeline_index:
			timelines[i].timeline_marker.show()
		else:
			timelines[i].timeline_marker.hide()
	AudioManager.create_audio(SoundEffect.SOUND_EFFECT_TYPE.SWITCH_TIME_LINE_UI)
