extends Node2D

onready var activatorArea = $"%ActivatorArea"
onready var indicatorPlayer = $"%IndicatorPlayer"
onready var signal_manager := get_tree().root.get_child(4).get_node("%SignalManager")
onready var unactivatable_timer := $Timer

var activatable = false

func _input(event: InputEvent) -> void:
	if activatable && Input.is_action_just_released("interact"):
		selfActivate()
		

func selfActivate():
	indicatorPlayer.play("onning")
	#TODO dis importante
	activatorArea.set_deferred("monitoring", false)
	#TODO Close gate again?
	signal_manager.emit_signal("unlocked", "gateblock")
	activatable = false


func _on_ActivatorArea_area_entered(area:Area2D) -> void:
		$Label.visible = true
		$Highlight.visible = true
		activatable = true
		if(area.get_parent().name == "WhatAreFrog"):
			selfActivate()

func _on_ActivatorArea_area_exited(area:Area2D) -> void:
		unactivatable_timer.start()

func _on_Timer_timeout():
	for body in activatorArea.get_overlapping_bodies():
		if body.is_in_group("player"):
			return
	$Label.visible = false
	$Highlight.visible = false
	activatable = false
