extends Node


@export_group("Settings")
@export var always_active: bool = false
@export var detector_node: Control
@export var visual_node: Control
@export var scale_amount: Vector2 = Vector2(1.1, 1.1)
@export var duration: float = 0.5

var hover_tween: Tween

func _ready():
	if not detector_node or not visual_node:
		return
	
	if always_active:
		_start_tween()
		return
	
	detector_node.mouse_entered.connect(_on_mouse_entered)
	detector_node.mouse_exited.connect(_on_mouse_exited)


func _on_mouse_entered():
	if hover_tween: hover_tween.kill()
	
	_start_tween()

func _on_mouse_exited():
	if hover_tween: hover_tween.kill()
	
	_stop_tween()

	
func _start_tween() -> void:
		hover_tween = create_tween().set_loops()
		hover_tween.tween_property(visual_node, "scale", scale_amount, duration).set_trans(Tween.TRANS_SINE)
		hover_tween.tween_property(visual_node, "scale", Vector2.ONE, duration).set_trans(Tween.TRANS_SINE)

func _stop_tween() -> void:
	var exit_tween = create_tween()
	exit_tween.tween_property(visual_node, "scale", Vector2.ONE, 0.2).set_trans(Tween.TRANS_QUAD)
	
