extends Interactable

@onready var tmp_sprite: Sprite2D = $TmpSprite
@onready var timer_visualisation: Control = $TimerVisualisation

@export var timer_duration = 3.0
var remaining_time = 3.0

var saved_state_remaining_time = 0.0

func _ready() -> void:
	super()
	remaining_time = timer_duration

func _process(delta: float) -> void:
	if Globals.paused or SceneChanger.mid_change or SceneChanger.mid_animation:
		return
	#super() # isnt overwriten
	if remaining_time > 0.0:
		remaining_time -= delta
		timer_visualisation.set_absolute((remaining_time / timer_duration) * 100)  # 100 is max value
	elif active:  # switch back off
		switch_state()  

func switch_state():
	super()
	remaining_time = timer_duration  # reset timer
	# notify system
	get_parent().notify_system(active)
	

func _save_state():
	super()
	saved_state_remaining_time = remaining_time

func _load_saved_state():
	super()
	get_parent().notify_system(active)
	remaining_time = saved_state_remaining_time
	
func _update_sprite():  # tmp for now
	if active:
		tmp_sprite.rotation = 45
		timer_visualisation.visible = true
	else:
		tmp_sprite.rotation = -0.3
		timer_visualisation.visible = false
